Skip to content

Commit e4cd2ea

Browse files
authored
Merge pull request #1342 from JakeGinnivan/fix/release-issues
Fix/release issues
2 parents e1a373b + b4152e9 commit e4cd2ea

File tree

7 files changed

+60
-26
lines changed

7 files changed

+60
-26
lines changed

build.cake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void Build(string configuration, string nugetVersion, string semVersion, string
4747
}
4848
}
4949

50+
// This build task can be run to just build
5051
Task("DogfoodBuild")
5152
.IsDependentOn("NuGet-Package-Restore")
5253
.Does(() =>
@@ -92,7 +93,7 @@ Task("Build")
9293
});
9394

9495
Task("Run-NUnit-Tests")
95-
.IsDependentOn("Build")
96+
.IsDependentOn("DogfoodBuild")
9697
.Does(() =>
9798
{
9899
var settings = new NUnit3Settings();
@@ -113,6 +114,7 @@ Task("Run-NUnit-Tests")
113114
});
114115

115116
Task("Zip-Files")
117+
.IsDependentOn("Build")
116118
.IsDependentOn("Run-NUnit-Tests")
117119
.Does(() =>
118120
{

src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void ShouldNotAllowIncrementOfVersion()
5858
[TestCase("Finish 0.14.1", true, "0.14.1")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Hotfix' branch
5959
[TestCase("Merge branch 'Release-v0.2.0'", true, "0.2.0")]
6060
[TestCase("Merge branch 'Release-v2.2'", true, "2.2.0")]
61+
[TestCase("Merge remote-tracking branch 'origin/release/0.8.0' into develop/master", true, "0.8.0")]
6162
public void AssertMergeMessage(string message, bool isMergeCommit, string expectedVersion)
6263
{
6364
var parents = GetParents(isMergeCommit);
@@ -121,6 +122,7 @@ static void AssertMergeMessage(string message, string expectedVersion, List<Comm
121122
}
122123
else
123124
{
125+
baseVersion.ShouldNotBeNull();
124126
baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
125127
}
126128
}

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class BranchConfigurationCalculator
1515
/// </summary>
1616
public static BranchConfig GetBranchConfiguration(GitVersionContext context, Branch targetBranch, IList<Branch> excludedInheritBranches = null)
1717
{
18-
var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.FriendlyName);
18+
var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote());
1919

2020
if (matchingBranches == null)
2121
{
@@ -27,11 +27,20 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
2727
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
2828
}
2929

30-
return matchingBranches.Increment == IncrementStrategy.Inherit ?
31-
InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches) :
32-
matchingBranches;
30+
if (matchingBranches.Increment == IncrementStrategy.Inherit)
31+
{
32+
matchingBranches = InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches);
33+
if (matchingBranches.Name == FallbackConfigName && matchingBranches.Increment == IncrementStrategy.Inherit)
34+
{
35+
// We tried, and failed to inherit, just fall back to patch
36+
matchingBranches.Increment = IncrementStrategy.Patch;
37+
}
38+
}
39+
40+
return matchingBranches;
3341
}
3442

43+
// TODO I think we need to take a fresh approach to this.. it's getting really complex with heaps of edge cases
3544
static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch targetBranch, BranchConfig branchConfiguration, IList<Branch> excludedInheritBranches)
3645
{
3746
var repository = context.Repository;
@@ -50,17 +59,17 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
5059
{
5160
excludedInheritBranches = repository.Branches.Where(b =>
5261
{
53-
var branchConfig = config.GetConfigForBranch(b.FriendlyName);
62+
var branchConfig = config.GetConfigForBranch(b.NameWithoutRemote());
5463

55-
return branchConfig != null && branchConfig.Increment == IncrementStrategy.Inherit;
64+
return branchConfig == null || branchConfig.Increment == IncrementStrategy.Inherit;
5665
}).ToList();
5766
}
5867
// Add new excluded branches.
5968
foreach (var excludedBranch in excludedBranches.ExcludingBranches(excludedInheritBranches))
6069
{
6170
excludedInheritBranches.Add(excludedBranch);
6271
}
63-
var branchesToEvaluate = repository.Branches.Except(excludedInheritBranches).ToList();
72+
var branchesToEvaluate = repository.Branches.ExcludingBranches(excludedInheritBranches).ToList();
6473

6574
var branchPoint = context.RepositoryMetadataProvider
6675
.FindCommitBranchWasBranchedFrom(targetBranch, excludedInheritBranches.ToArray());
@@ -94,13 +103,17 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
94103
if (possibleParents.Count == 1)
95104
{
96105
var branchConfig = GetBranchConfiguration(context, possibleParents[0], excludedInheritBranches);
97-
return new BranchConfig(branchConfiguration)
106+
// If we have resolved a fallback config we should not return that we have got config
107+
if (branchConfig.Name != FallbackConfigName)
98108
{
99-
Increment = branchConfig.Increment,
100-
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
101-
// If we are inheriting from develop then we should behave like develop
102-
TracksReleaseBranches = branchConfig.TracksReleaseBranches
103-
};
109+
return new BranchConfig(branchConfiguration)
110+
{
111+
Increment = branchConfig.Increment,
112+
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
113+
// If we are inheriting from develop then we should behave like develop
114+
TracksReleaseBranches = branchConfig.TracksReleaseBranches
115+
};
116+
}
104117
}
105118

106119
// If we fail to inherit it is probably because the branch has been merged and we can't do much. So we will fall back to develop's config

src/GitVersionCore/GitRepoMetadataProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch
198198
return BranchCommit.Empty;
199199
}
200200

201-
var possibleBranches = GetMergeCommitsForBranch(branch)
202-
.ExcludingBranches(excludedBranches)
201+
var possibleBranches = GetMergeCommitsForBranch(branch, excludedBranches)
203202
.Where(b => !branch.IsSameBranch(b.Branch))
204203
.ToList();
205204

@@ -216,7 +215,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch
216215
}
217216
}
218217

219-
List<BranchCommit> GetMergeCommitsForBranch(Branch branch)
218+
List<BranchCommit> GetMergeCommitsForBranch(Branch branch, Branch[] excludedBranches)
220219
{
221220
if (mergeBaseCommitsCache.ContainsKey(branch))
222221
{
@@ -226,11 +225,12 @@ List<BranchCommit> GetMergeCommitsForBranch(Branch branch)
226225
return mergeBaseCommitsCache[branch];
227226
}
228227

229-
var currentBranchConfig = configuration.GetConfigForBranch(branch.FriendlyName);
228+
var currentBranchConfig = configuration.GetConfigForBranch(branch.NameWithoutRemote());
230229
var regexesToCheck = currentBranchConfig == null
231230
? new [] { ".*" } // Match anything if we can't find a branch config
232231
: currentBranchConfig.SourceBranches.Select(sb => configuration.Branches[sb].Regex);
233232
var branchMergeBases = Repository.Branches
233+
.ExcludingBranches(excludedBranches)
234234
.Where(b =>
235235
{
236236
if (b == branch) return false;

src/GitVersionCore/IncrementStrategyFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static Regex CreateRegex(string pattern)
129129

130130
public static VersionField FindDefaultIncrementForBranch( GitVersionContext context, string branch = null )
131131
{
132-
var config = context.FullConfiguration.GetConfigForBranch(branch ?? context.CurrentBranch.FriendlyName);
132+
var config = context.FullConfiguration.GetConfigForBranch(branch ?? context.CurrentBranch.NameWithoutRemote());
133133
if ( config?.Increment != null && config.Increment != IncrementStrategy.Inherit )
134134
{
135135
return config.Increment.Value.ToVersionField();

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ public static DateTimeOffset When(this Commit commit)
1717
/// <summary>
1818
/// Checks if the two branch objects refer to the same branch (have the same friendly name).
1919
/// </summary>
20-
public static bool IsSameBranch(this Branch branch, Branch otherBranch)
20+
public static string NameWithoutRemote(this Branch branch)
2121
{
22-
// For each branch, fixup the friendly name if the branch is remote.
23-
var otherBranchFriendlyName = otherBranch.IsRemote ?
24-
otherBranch.FriendlyName.Substring(otherBranch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) :
25-
otherBranch.FriendlyName;
26-
var branchFriendlyName = branch.IsRemote ?
22+
return branch.IsRemote ?
2723
branch.FriendlyName.Substring(branch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) :
2824
branch.FriendlyName;
25+
}
26+
27+
/// <summary>
28+
/// Checks if the two branch objects refer to the same branch (have the same friendly name).
29+
/// </summary>
30+
public static bool IsSameBranch(this Branch branch, Branch otherBranch)
31+
{
32+
// For each branch, fixup the friendly name if the branch is remote.
33+
var otherBranchFriendlyName = otherBranch.NameWithoutRemote();
34+
var branchFriendlyName = branch.NameWithoutRemote();
2935

3036
return otherBranchFriendlyName == branchFriendlyName;
3137
}

src/GitVersionCore/MergeMessage.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class MergeMessage
1515
static Regex smartGitMergeMessage = new Regex(
1616
@"^Finish (?<Branch>.*)",
1717
RegexOptions.IgnoreCase | RegexOptions.Compiled);
18+
static Regex parseRemoteTrackingMergeMessage = new Regex(
19+
@"^Merge remote-tracking branch '(?<SourceBranch>.*)' into (?<TargetBranch>.*)",
20+
RegexOptions.IgnoreCase | RegexOptions.Compiled);
21+
1822
private string mergeMessage;
1923
private Config config;
2024

@@ -73,7 +77,14 @@ private string ParseBranch()
7377
PullRequestNumber = pullNumber;
7478
}
7579
var from = match.Groups["Source"].Value;
76-
// We could remove/separate the remote name at this point?
80+
// TODO We could remove/separate the remote name at this point?
81+
return from;
82+
}
83+
84+
match = parseRemoteTrackingMergeMessage.Match(mergeMessage);
85+
if (match.Success) {
86+
var from = match.Groups["SourceBranch"].Value;
87+
// TODO We could remove/separate the remote name at this point?
7788
return from;
7889
}
7990

0 commit comments

Comments
 (0)