Skip to content

Commit dd368aa

Browse files
committed
Fixed rebase issues, todo about regex and made dynamic repository test run against temporary local git repo
1 parent a4b955d commit dd368aa

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

GitVersionCore/BuildServers/GitHelper.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GitVersion
77

88
public static class GitHelper
99
{
10-
const string MergeMessageRegexPattern = "refs/heads/pull(-requests)?/(?<issuenumber>[0-9]*)/merge";
10+
const string MergeMessageRegexPattern = "refs/heads/(pr|pull(-requests)?/(?<issuenumber>[0-9]*)/merge)";
1111

1212
public static void NormalizeGitDirectory(string gitDirectory, Authentication authentication)
1313
{
@@ -32,14 +32,14 @@ public static void NormalizeGitDirectory(string gitDirectory, Authentication aut
3232
Logger.WriteInfo(string.Format("HEAD points at branch '{0}'.", headSha));
3333
return;
3434
}
35-
35+
3636
Logger.WriteInfo(string.Format("HEAD is detached and points at commit '{0}'.", headSha));
37-
37+
3838
// In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA.
3939
// If they do, go ahead and checkout that branch
4040
// If no, go ahead and check out a new branch, using the known commit SHA as the pointer
4141
var localBranchesWhereCommitShaIsHead = repo.Branches.Where(b => !b.IsRemote && b.Tip.Sha == headSha).ToList();
42-
42+
4343
if (localBranchesWhereCommitShaIsHead.Count > 1)
4444
{
4545
var names = string.Join(", ", localBranchesWhereCommitShaIsHead.Select(r => r.CanonicalName));
@@ -55,7 +55,7 @@ public static void NormalizeGitDirectory(string gitDirectory, Authentication aut
5555
else
5656
{
5757
Logger.WriteInfo(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].Name));
58-
repo.Branches[localBranchesWhereCommitShaIsHead[0].Name].Checkout();
58+
repo.Branches[localBranchesWhereCommitShaIsHead[0].Name].Checkout();
5959
}
6060
}
6161
}
@@ -76,22 +76,12 @@ public static string ExtractIssueNumber(string mergeMessage)
7676
// Dynamic: refs/heads/pr/5
7777
// Github Message: refs/heads/pull/5/merge
7878
// Stash Message: refs/heads/pull-requests/5/merge
79+
var regex = new Regex(MergeMessageRegexPattern);
80+
var match = regex.Match(mergeMessage);
7981

80-
// Note by @GeertvanHorrik: sorry, I suck at regex so did a quick hack, feel free to replace by regex
81-
if (mergeMessage.Contains("refs/heads/pr/"))
82-
{
83-
var issueNumber = mergeMessage.Replace("refs/heads/pr/", string.Empty);
84-
return issueNumber;
85-
}
86-
else
87-
{
88-
var regex = new Regex(MergeMessageRegexPattern);
89-
var match = regex.Match(mergeMessage);
90-
91-
var issueNumber = match.Groups["issuenumber"].Value;
82+
var issueNumber = match.Groups["issuenumber"].Value;
9283

93-
return issueNumber;
94-
}
84+
return issueNumber;
9585
}
9686

9787
static void AddMissingRefSpecs(Repository repo, Remote remote)
@@ -113,7 +103,7 @@ static FetchOptions BuildFetchOptions(string username, string password)
113103

114104
if (!string.IsNullOrEmpty(username))
115105
{
116-
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
106+
fetchOptions.CredentialsProvider = (url, user, types) => new UsernamePasswordCredentials
117107
{
118108
Username = username,
119109
Password = password

GitVersionCore/Extensions/ExtensionMethods.git.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static bool IsPullRequest(this string branchName)
8080

8181
public static bool IsSupport(this string branchName)
8282
{
83-
return branchName.ToLower().StartsWith("support-");
83+
return branchName.ToLower().StartsWith("support-") || branchName.ToLower().StartsWith("support/");
8484
}
8585
}
8686
}

GitVersionCore/GitVersionCore.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,12 @@
7373
<Compile Include="Configuration\Config.cs" />
7474
<Compile Include="Configuration\ConfigReader.cs" />
7575
<Compile Include="Configuration\ConfigurationProvider.cs" />
76-
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
7776
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
7877
<Compile Include="Helpers\FileSystem.cs" />
7978
<Compile Include="Helpers\IFileSystem.cs" />
8079
<Compile Include="LastMinorVersionFinder.cs" />
8180
<Compile Include="Extensions\ExtensionMethods.git.cs" />
8281
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
83-
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
84-
<Compile Include="GitFlow\BranchFinders\VersionOnMasterFinder.cs" />
85-
<Compile Include="LastVersionOnMasterFinder.cs" />
86-
<Compile Include="ShortVersion.cs" />
8782
<Compile Include="SemanticVersionExtensions.cs" />
8883
<Compile Include="WarningException.cs" />
8984
<Compile Include="Extensions\ExtensionMethods.cs" />
@@ -127,7 +122,6 @@
127122
<Compile Include="SemanticVersionBuildMetaData.cs" />
128123
<Compile Include="SemanticVersionPreReleaseTag.cs" />
129124
<Compile Include="GitFlow\BranchFinders\VersionOnMasterFinder.cs" />
130-
<Compile Include="ShortVersionParser.cs" />
131125
<Compile Include="VersionPoint.cs" />
132126
</ItemGroup>
133127
<ItemGroup>

GitVersionExe.Tests/GitPreparerTests.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,43 @@ public GitPreparerTests()
1515
Logger.WriteError = s => { };
1616
}
1717

18-
const string RemoteRepositoryUrl = "https://github.com/ParticularLabs/GitVersion.git";
1918
const string DefaultBranchName = "master";
20-
const string SpecificBranchName = "gh-pages";
19+
const string SpecificBranchName = "feature/foo";
2120

22-
[Explicit]
21+
[Test]
2322
[TestCase(null, DefaultBranchName)]
2423
[TestCase(SpecificBranchName, SpecificBranchName)]
2524
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
2625
{
2726
var tempDir = Path.GetTempPath();
2827

29-
var arguments = new Arguments
28+
using (var fixture = new EmptyRepositoryFixture(new Config()))
3029
{
31-
TargetPath = tempDir,
32-
TargetUrl = RemoteRepositoryUrl
33-
};
30+
fixture.Repository.MakeCommits(5);
31+
fixture.Repository.CreateBranch("feature/foo");
32+
var arguments = new Arguments
33+
{
34+
TargetPath = tempDir,
35+
TargetUrl = fixture.RepositoryPath
36+
};
3437

35-
if (!string.IsNullOrWhiteSpace(branchName))
36-
{
37-
arguments.TargetBranch = branchName;
38-
}
38+
if (!string.IsNullOrWhiteSpace(branchName))
39+
{
40+
arguments.TargetBranch = branchName;
41+
}
3942

40-
var gitPreparer = new GitPreparer(arguments);
41-
var dynamicRepositoryPath = gitPreparer.Prepare();
43+
var gitPreparer = new GitPreparer(arguments);
44+
var dynamicRepositoryPath = gitPreparer.Prepare();
4245

43-
Assert.AreEqual(Path.Combine(tempDir, "_dynamicrepository", ".git"), dynamicRepositoryPath);
44-
Assert.IsTrue(gitPreparer.IsDynamicGitRepository);
46+
Assert.AreEqual(Path.Combine(tempDir, "_dynamicrepository", ".git"), dynamicRepositoryPath);
47+
Assert.IsTrue(gitPreparer.IsDynamicGitRepository);
4548

46-
using (var repository = new Repository(dynamicRepositoryPath))
47-
{
48-
var currentBranch = repository.Head.CanonicalName;
49+
using (var repository = new Repository(dynamicRepositoryPath))
50+
{
51+
var currentBranch = repository.Head.CanonicalName;
4952

50-
Assert.IsTrue(currentBranch.EndsWith(expectedBranchName));
53+
Assert.IsTrue(currentBranch.EndsWith(expectedBranchName));
54+
}
5155
}
5256
}
5357

GitVersionTask.Tests/GitVersionTask.Tests.v2.ncrunchproject

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
2323
<MSTestThreadApartmentState>STA</MSTestThreadApartmentState>
2424
<BuildProcessArchitecture>x86</BuildProcessArchitecture>
25+
<IgnoredTests>
26+
<FixtureTestSelector>
27+
<FixtureName>IntegrationTests</FixtureName>
28+
</FixtureTestSelector>
29+
</IgnoredTests>
2530
<AdditionalFilesToInclude>..\Packages\LibGit2Sharp.0.19.0.0\lib\net40\NativeBinaries\**.*</AdditionalFilesToInclude>
2631
<HiddenWarnings>PostBuildEventDisabled</HiddenWarnings>
2732
</ProjectConfiguration>

0 commit comments

Comments
 (0)