Skip to content

Commit ab81191

Browse files
committed
Make develop track tags on master
This removes the need for the TrackMergeTargetBaseVersionStrategy
1 parent 3194f96 commit ab81191

File tree

7 files changed

+99
-87
lines changed

7 files changed

+99
-87
lines changed

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void InheritVersionFromReleaseBranch()
178178
fixture.AssertFullSemver("2.1.0-alpha.4");
179179
fixture.BranchTo("feature/MyFeature");
180180
fixture.MakeACommit();
181-
fixture.AssertFullSemver("2.1.0-MyFeature.1+1");
181+
fixture.AssertFullSemver("2.1.0-MyFeature.1+3");
182182
}
183183
}
184184
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,42 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel
199199
fixture.AssertFullSemver(config, expectedFullSemVer);
200200
}
201201
}
202+
203+
[Test]
204+
public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMasterCommitTag()
205+
{
206+
using (var fixture = new BaseGitFlowRepositoryFixture("0.1.0"))
207+
{
208+
//validate current version
209+
fixture.AssertFullSemver("0.2.0-alpha.1");
210+
fixture.Repository.CreateBranch("release/0.2.0");
211+
fixture.Repository.Checkout("release/0.2.0");
212+
213+
//validate release version
214+
fixture.AssertFullSemver("0.2.0-beta.1+0");
215+
216+
fixture.Checkout("master");
217+
fixture.Repository.MergeNoFF("release/0.2.0");
218+
fixture.Repository.ApplyTag("0.2.0");
219+
220+
//validate master branch version
221+
fixture.AssertFullSemver("0.2.0");
222+
223+
fixture.Checkout("develop");
224+
fixture.Repository.MergeNoFF("release/0.2.0");
225+
fixture.Repository.Branches.Remove("release/2.0.0");
226+
227+
fixture.Repository.MakeACommit();
228+
229+
//validate develop branch version after merging release 0.2.0 to master and develop (finish release)
230+
fixture.AssertFullSemver("0.3.0-alpha.1");
231+
232+
//create a feature branch from develop
233+
fixture.BranchTo("feature/TEST-1");
234+
fixture.Repository.MakeACommit();
235+
236+
//I'm not entirely sure what the + value should be but I know the semvar major/minor/patch should be 0.3.0
237+
fixture.AssertFullSemver("0.3.0-TEST-1.1+2");
238+
}
239+
}
202240
}

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
114114
new BranchConfig(branchConfiguration)
115115
{
116116
Increment = branchConfig.Increment,
117-
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion
117+
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
118+
// If we are inheriting from develop then we should behave like develop
119+
IsDevelop = branchConfig.IsDevelop
118120
});
119121
}
120122

@@ -134,13 +136,15 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
134136
var branchName = chosenBranch.FriendlyName;
135137
Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config");
136138

137-
var value = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value;
139+
var inheritingBranchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value;
138140
return new KeyValuePair<string, BranchConfig>(
139141
keyValuePair.Key,
140142
new BranchConfig(branchConfiguration)
141143
{
142-
Increment = value.Increment,
143-
PreventIncrementOfMergedBranchVersion = value.PreventIncrementOfMergedBranchVersion
144+
Increment = inheritingBranchConfig.Increment,
145+
PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion,
146+
// If we are inheriting from develop then we should behave like develop
147+
IsDevelop = inheritingBranchConfig.IsDevelop
144148
});
145149
}
146150
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
public class TaggedCommitVersionStrategy : BaseVersionStrategy
88
{
99
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
10+
{
11+
return GetTaggedVersions(context, context.CurrentBranch);
12+
}
13+
14+
public IEnumerable<BaseVersion> GetTaggedVersions(GitVersionContext context, Branch currentBranch)
1015
{
1116
var olderThan = context.CurrentCommit.When();
1217
var allTags = context.Repository.Tags
13-
.Where(tag => ((Commit)tag.PeeledTarget()).When() <= olderThan)
18+
.Where(tag => ((Commit) tag.PeeledTarget()).When() <= olderThan)
1419
.ToList();
15-
var tagsOnBranch = context.CurrentBranch
20+
var tagsOnBranch = currentBranch
1621
.Commits
17-
.SelectMany(commit =>
18-
{
19-
return allTags.Where(t => IsValidTag(t, commit));
20-
})
22+
.SelectMany(commit => { return allTags.Where(t => IsValidTag(t, commit)); })
2123
.Select(t =>
2224
{
2325
SemanticVersion version;

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TrackMergeTargetBaseVersionStrategy.cs

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

src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,67 @@ namespace GitVersion.VersionCalculation
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Text.RegularExpressions;
6-
using GitVersion.VersionCalculation.BaseVersionCalculators;
6+
using BaseVersionCalculators;
7+
using GitTools;
78
using LibGit2Sharp;
89

910
/// <summary>
10-
/// Inherit version from release branch
11+
/// Inherit version from release branch and tags on master
1112
/// </summary>
1213
public class DevelopVersionStrategy : BaseVersionStrategy
1314
{
1415
VersionInBranchBaseVersionStrategy releaseVersionStrategy = new VersionInBranchBaseVersionStrategy();
16+
TaggedCommitVersionStrategy taggedCommitVersionStrategy = new TaggedCommitVersionStrategy();
1517

1618
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1719
{
1820
if (context.Configuration.IsCurrentBranchDevelop)
1921
{
20-
var releaseBranchConfig = context.FullConfiguration.Branches
21-
.Where(b => b.Value.IsReleaseBranch == true)
22-
.ToList();
23-
if (releaseBranchConfig.Any())
24-
{
25-
var releaseBranches = context.Repository.Branches
26-
.Where(b => releaseBranchConfig.Any(c => Regex.IsMatch(b.FriendlyName, c.Key)));
27-
28-
var baseVersions = releaseBranches.SelectMany(b => GetReleaseVersion(context, b)).ToList();
29-
return baseVersions;
30-
}
22+
return ReleaseBranchBaseVersions(context).Union(MasterTagsVersions(context));
23+
}
24+
25+
return new BaseVersion[0];
26+
}
27+
28+
private IEnumerable<BaseVersion> MasterTagsVersions(GitVersionContext context)
29+
{
30+
var master = context.Repository.FindBranch("master");
31+
if (master != null)
32+
{
33+
return taggedCommitVersionStrategy.GetTaggedVersions(context, master);
3134
}
3235

3336
return new BaseVersion[0];
3437
}
3538

39+
private IEnumerable<BaseVersion> ReleaseBranchBaseVersions(GitVersionContext context)
40+
{
41+
var releaseBranchConfig = context.FullConfiguration.Branches
42+
.Where(b => b.Value.IsReleaseBranch == true)
43+
.ToList();
44+
if (releaseBranchConfig.Any())
45+
{
46+
var releaseBranches = context.Repository.Branches
47+
.Where(b => releaseBranchConfig.Any(c => Regex.IsMatch(b.FriendlyName, c.Key)));
48+
49+
return releaseBranches
50+
.SelectMany(b => GetReleaseVersion(context, b))
51+
.Select(baseVersion =>
52+
{
53+
// Need to drop branch overrides and give a bit more context about
54+
// where this version came from
55+
var source1 = "Release branch exists -> " + baseVersion.Source;
56+
return new BaseVersion(source1,
57+
baseVersion.ShouldIncrement,
58+
baseVersion.SemanticVersion,
59+
baseVersion.BaseVersionSource,
60+
null);
61+
})
62+
.ToList();
63+
}
64+
return new BaseVersion[0];
65+
}
66+
3667
IEnumerable<BaseVersion> GetReleaseVersion(GitVersionContext context, Branch releaseBranch)
3768
{
3869
var tagPrefixRegex = context.Configuration.GitTagPrefix;

src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public NextVersionCalculator(IBaseVersionCalculator baseVersionCalculator = null
1717
new FallbackBaseVersionStrategy(),
1818
new ConfigNextVersionBaseVersionStrategy(),
1919
new TaggedCommitVersionStrategy(),
20-
new TrackMergeTargetBaseVersionStrategy(),
2120
new MergeMessageBaseVersionStrategy(),
2221
new VersionInBranchBaseVersionStrategy(),
2322
new DevelopVersionStrategy());

0 commit comments

Comments
 (0)