Skip to content

Commit 12359cc

Browse files
committed
Merge pull request #308 from JakeGinnivan/BetterSwitchingToGitFlowStory
Better switching to git flow story
2 parents cba8b2b + 5d55a34 commit 12359cc

30 files changed

+178
-309
lines changed

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="IntegrationTests\GitFlow\MetaDataByCommitScenarios.cs" />
7575
<Compile Include="IntegrationTests\GitFlow\PatchScenarios.cs" />
7676
<Compile Include="IntegrationTests\GitFlow\ReleaseBranchTests.cs" />
77+
<Compile Include="IntegrationTests\GitFlow\SwitchingToGitFlowScenarios.cs" />
7778
<Compile Include="IntegrationTests\GitFlow\UncycloScenarios.cs" />
7879
<Compile Include="IntegrationTests\GitHubFlow\OtherBranchTests.cs" />
7980
<Compile Include="IntegrationTests\GitHubFlow\ReleaseBranchTests.cs" />
@@ -90,7 +91,6 @@
9091
<Compile Include="ApprovalTestsConfig.cs" />
9192
<Compile Include="Fixtures\RepositoryFixtureBase.cs" />
9293
<Compile Include="SemanticVersionTests.cs" />
93-
<Compile Include="ShortVersionParserTests.cs" />
9494
<Compile Include="VariableProviderTests.cs" />
9595
</ItemGroup>
9696
<ItemGroup>

GitVersionCore.Tests/IntegrationTests/GitFlow/MetaDataByCommitScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void EnsureBranchMatch(CommitCountingRepoFixture fixture, string branchNa
157157
var referenceCommitFinder = commitFinder ?? (r => r.FindBranch(branchName).Tip);
158158

159159
var commit = referenceCommitFinder(fixture.Repository);
160-
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, commit);
160+
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, new Config(), commit);
161161
releaseDate.ShouldBe(commit.When());
162162
}
163163

GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ public void CanTakeVersionFromReleaseBranchWithTagOverriden()
3535
}
3636
}
3737

38+
[Test]
39+
public void CanHandleReleaseBranchWithStability()
40+
{
41+
using (var fixture = new EmptyRepositoryFixture(new Config()))
42+
{
43+
fixture.Repository.MakeATaggedCommit("1.0.3");
44+
fixture.Repository.CreateBranch("develop");
45+
fixture.Repository.MakeCommits(5);
46+
fixture.Repository.CreateBranch("release-2.0.0-Final");
47+
fixture.Repository.Checkout("release-2.0.0-Final");
48+
49+
fixture.AssertFullSemver("2.0.0-beta.1+5");
50+
}
51+
}
52+
3853
[Test]
3954
public void WhenReleaseBranchIsMergedIntoMasterVersionIsTakenWithIt()
4055
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using GitVersion;
2+
using LibGit2Sharp;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class SwitchingToGitFlowScenarios
7+
{
8+
[Test]
9+
public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReachableTag()
10+
{
11+
using (var fixture = new EmptyRepositoryFixture(new Config()))
12+
{
13+
fixture.Repository.MakeCommits(5);
14+
fixture.Repository.MakeATaggedCommit("1.0.0.0");
15+
fixture.Repository.MakeCommits(2);
16+
fixture.Repository.CreateBranch("develop").Checkout();
17+
fixture.AssertFullSemver("1.1.0-unstable.0+0");
18+
}
19+
}
20+
}

GitVersionCore.Tests/ShortVersionParserTests.cs

Lines changed: 0 additions & 81 deletions
This file was deleted.

GitVersionCore/GitFlow/BranchFinders/HotfixVersionFinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class HotfixVersionFinder
77
public SemanticVersion FindVersion(GitVersionContext context)
88
{
99
var versionString = GetSuffix(context.CurrentBranch);
10-
var shortVersion = ShortVersionParser.Parse(versionString);
10+
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);
1111

1212
EnsureVersionIsValid(shortVersion, context.CurrentBranch);
1313

@@ -24,7 +24,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
2424
};
2525
}
2626

27-
static string GetSemanticVersionPreReleaseTag(GitVersionContext context, ShortVersion shortVersion, int nbHotfixCommits)
27+
static string GetSemanticVersionPreReleaseTag(GitVersionContext context, SemanticVersion shortVersion, int nbHotfixCommits)
2828
{
2929
var semanticVersionPreReleaseTag = context.Configuration.ReleaseBranchTag + ".1";
3030
var tagVersion = RecentTagVersionExtractor.RetrieveMostRecentOptionalTagVersion(context, shortVersion);
@@ -40,7 +40,7 @@ static string GetSuffix(Branch branch)
4040
return branch.Name.TrimStart("hotfix-").TrimStart("hotfix/");
4141
}
4242

43-
void EnsureVersionIsValid(ShortVersion version, Branch branch)
43+
void EnsureVersionIsValid(SemanticVersion version, Branch branch)
4444
{
4545
if (version.Patch == 0)
4646
{

GitVersionCore/GitFlow/BranchFinders/MasterVersionFinder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ namespace GitVersion
44

55
class MasterVersionFinder
66
{
7-
public SemanticVersion FindVersion(IRepository repository, Commit tip)
7+
public SemanticVersion FindVersion(GitVersionContext context)
88
{
9-
foreach (var tag in repository.TagsByDate(tip))
9+
foreach (var tag in context.Repository.TagsByDate(context.CurrentCommit))
1010
{
11-
ShortVersion shortVersion;
12-
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
11+
SemanticVersion shortVersion;
12+
if (SemanticVersion.TryParse(tag.Name, context.Configuration.TagPrefix, out shortVersion))
1313
{
14-
return BuildVersion(tip, shortVersion);
14+
return BuildVersion(context.CurrentCommit, shortVersion);
1515
}
1616
}
1717

18-
ShortVersion versionFromTip;
19-
if (MergeMessageParser.TryParse(tip, out versionFromTip))
18+
SemanticVersion versionFromTip;
19+
if (MergeMessageParser.TryParse(context.CurrentCommit, context.Configuration, out versionFromTip))
2020
{
21-
return BuildVersion(tip, versionFromTip);
21+
return BuildVersion(context.CurrentCommit, versionFromTip);
2222
}
2323
throw new WarningException("The head of master should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
2424
}
2525

26-
SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)
26+
SemanticVersion BuildVersion(Commit tip, SemanticVersion shortVersion)
2727
{
2828
return new SemanticVersion
2929
{

GitVersionCore/GitFlow/BranchFinders/RecentTagVersionExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitVersion
66

77
class RecentTagVersionExtractor
88
{
9-
internal static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, ShortVersion matchVersion)
9+
internal static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, SemanticVersion matchVersion)
1010
{
1111
var tagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, matchVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix));
1212
return RetrieveMostRecentOptionalTagVersion(context, tagsInDescendingOrder.ToList());

GitVersionCore/GitFlow/BranchFinders/ReleaseVersionFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ReleaseVersionFinder
88
public SemanticVersion FindVersion(GitVersionContext context)
99
{
1010
var versionString = GetSuffix(context.CurrentBranch);
11-
var shortVersion = ShortVersionParser.Parse(versionString);
11+
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);
1212

1313
EnsureVersionIsValid(shortVersion, context.CurrentBranch);
1414

@@ -26,7 +26,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
2626
};
2727
}
2828

29-
static void EnsureVersionIsValid(ShortVersion version, Branch branch)
29+
static void EnsureVersionIsValid(SemanticVersion version, Branch branch)
3030
{
3131
if (version.Patch != 0)
3232
{

GitVersionCore/GitFlow/BranchFinders/SupportVersionFinder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip, Config co
88
{
99
foreach (var tag in repository.TagsByDate(tip))
1010
{
11-
ShortVersion shortVersion;
12-
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
11+
SemanticVersion shortVersion;
12+
if (SemanticVersion.TryParse(tag.Name, configuration.TagPrefix, out shortVersion))
1313
{
1414
return BuildVersion(tip, shortVersion);
1515
}
1616
}
1717

18-
ShortVersion versionFromTip;
19-
if (MergeMessageParser.TryParse(tip, out versionFromTip))
18+
SemanticVersion versionFromTip;
19+
if (MergeMessageParser.TryParse(tip, configuration, out versionFromTip))
2020
{
2121
var semanticVersion = BuildVersion(tip, versionFromTip);
2222
semanticVersion.OverrideVersionManuallyIfNeeded(repository, configuration);
@@ -25,7 +25,7 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip, Config co
2525
throw new WarningException("The head of a support branch should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
2626
}
2727

28-
SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)
28+
SemanticVersion BuildVersion(Commit tip, SemanticVersion shortVersion)
2929
{
3030
return new SemanticVersion
3131
{

GitVersionCore/GitFlow/BranchFinders/VersionOnMasterFinder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ public VersionPoint Execute(GitVersionContext context, DateTimeOffset olderThan)
1111
{
1212
foreach (var tag in context.Repository.TagsByDate(commit))
1313
{
14-
ShortVersion shortVersion;
15-
if (ShortVersionParser.TryParseMajorMinor(tag.Name, out shortVersion))
14+
SemanticVersion semanticVersion;
15+
if (SemanticVersion.TryParse(tag.Name, context.Configuration.TagPrefix, out semanticVersion))
1616
{
1717
return new VersionPoint
1818
{
19-
Major = shortVersion.Major,
20-
Minor = shortVersion.Minor,
19+
Major = semanticVersion.Major,
20+
Minor = semanticVersion.Minor,
2121
};
2222
}
2323
}
2424

25-
ShortVersion shortVersionFromMergeMessage;
26-
if (MergeMessageParser.TryParse(commit, out shortVersionFromMergeMessage))
25+
SemanticVersion semanticVersionFromMergeMessage;
26+
if (MergeMessageParser.TryParse(commit, context.Configuration, out semanticVersionFromMergeMessage))
2727
{
2828
return new VersionPoint
2929
{
30-
Major = shortVersionFromMergeMessage.Major,
31-
Minor = shortVersionFromMergeMessage.Minor,
30+
Major = semanticVersionFromMergeMessage.Major,
31+
Minor = semanticVersionFromMergeMessage.Minor,
3232
};
3333
}
3434
}

GitVersionCore/GitFlow/GitFlowVersionFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
66
{
77
if (context.CurrentBranch.IsMaster())
88
{
9-
return new MasterVersionFinder().FindVersion(context.Repository, context.CurrentCommit);
9+
return new MasterVersionFinder().FindVersion(context);
1010
}
1111

1212
if (context.CurrentBranch.IsHotfix())

GitVersionCore/GitHubFlow/MergedBranchesWithVersionFinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public bool TryGetVersion(out SemanticVersion semanticVersion)
3232
return true;
3333
}
3434

35-
static IEnumerable<ShortVersion> GetAllVersions(GitVersionContext context)
35+
static IEnumerable<SemanticVersion> GetAllVersions(GitVersionContext context)
3636
{
3737
foreach (var commit in context.CurrentBranch.Commits)
3838
{
39-
ShortVersion version;
40-
if (MergeMessageParser.TryParse(commit, out version))
39+
SemanticVersion version;
40+
if (MergeMessageParser.TryParse(commit, context.Configuration, out version))
4141
{
4242
yield return version;
4343
}

GitVersionCore/GitHubFlow/OtherBranchVersionFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public bool FindVersion(GitVersionContext context, out SemanticVersion semanticV
1313
semanticVersion = null;
1414
return false;
1515
}
16-
var shortVersion = ShortVersionParser.Parse(versionString);
16+
var shortVersion = SemanticVersion.Parse(versionString, context.Configuration.TagPrefix);
1717

1818

1919
var applicableTagsInDescendingOrder = context.Repository.SemVerTagsRelatedToVersion(context.Configuration, shortVersion).OrderByDescending(tag => SemanticVersion.Parse(tag.Name, context.Configuration.TagPrefix)).ToList();

GitVersionCore/GitVersionCore.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
7676
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
7777
<Compile Include="LastMinorVersionFinder.cs" />
78-
<Compile Include="ShortVersion.cs" />
7978
<Compile Include="SemanticVersionExtensions.cs" />
8079
<Compile Include="WarningException.cs" />
8180
<Compile Include="ExtensionMethods.cs" />
@@ -118,7 +117,6 @@
118117
<Compile Include="SemanticVersion.cs" />
119118
<Compile Include="SemanticVersionBuildMetaData.cs" />
120119
<Compile Include="SemanticVersionPreReleaseTag.cs" />
121-
<Compile Include="ShortVersionParser.cs" />
122120
<Compile Include="GitFlow\BranchFinders\VersionOnMasterFinder.cs" />
123121
<Compile Include="VersionPoint.cs" />
124122
</ItemGroup>

0 commit comments

Comments
 (0)