Skip to content

Commit 0c2ce26

Browse files
author
Yannis Guedel
committed
implemented possible fix for #411
1 parent 7af92d5 commit 0c2ce26

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void WhenTwoFeatureBranchPointToTheSameCommit()
6363
fixture.Repository.CreateBranch("feature/feature2");
6464
fixture.Repository.Checkout("feature/feature2");
6565

66-
fixture.AssertFullSemver("1.0.1-test.1+5");
66+
fixture.AssertFullSemver("0.1.0-feature2.1+1");
6767
}
6868
}
6969
}

GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GitVersion
88

99
public class BranchConfigurationCalculator
1010
{
11-
public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit currentCommit, IRepository repository, bool onlyEvaluateTrackedBranches, Config config, Branch currentBranch)
11+
public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit currentCommit, IRepository repository, bool onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList<Branch> excludedInheritBranches = null)
1212
{
1313
var matchingBranches = config.Branches.Where(b => Regex.IsMatch(currentBranch.Name, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray();
1414

@@ -23,7 +23,7 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
2323

2424
if (branchConfiguration.Increment == IncrementStrategy.Inherit)
2525
{
26-
return InheritBranchConfiguration(onlyEvaluateTrackedBranches, repository, currentCommit, currentBranch, keyValuePair, branchConfiguration, config);
26+
return InheritBranchConfiguration(onlyEvaluateTrackedBranches, repository, currentCommit, currentBranch, keyValuePair, branchConfiguration, config, excludedInheritBranches);
2727
}
2828

2929
return keyValuePair;
@@ -33,10 +33,7 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
3333
throw new Exception(string.Format(format, currentBranch.Name, string.Join(", ", matchingBranches.Select(b => b.Key))));
3434
}
3535

36-
static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
37-
bool onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit,
38-
Branch currentBranch, KeyValuePair<string, BranchConfig> keyValuePair,
39-
BranchConfig branchConfiguration, Config config)
36+
static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair<string, BranchConfig> keyValuePair, BranchConfig branchConfiguration, Config config, IList<Branch> excludedInheritBranches)
4037
{
4138
Logger.WriteInfo("Attempting to inherit branch configuration from parent branch");
4239
var excludedBranches = new [] { currentBranch };
@@ -70,18 +67,23 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
7067

7168
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");
7269
}
70+
if (excludedInheritBranches == null)
71+
{
72+
excludedInheritBranches = new List<Branch>();
73+
}
74+
excludedBranches.ToList().ForEach(excludedInheritBranches.Add);
7375

74-
var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(repository, onlyEvaluateTrackedBranches, excludedBranches);
76+
var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(repository, onlyEvaluateTrackedBranches, excludedInheritBranches.ToArray());
7577

7678
List<Branch> possibleParents;
7779
if (branchPoint.Sha == currentCommit.Sha)
7880
{
79-
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
81+
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
8082
}
8183
else
8284
{
83-
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
84-
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedBranches).ToList();
85+
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
86+
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
8587
possibleParents = branches
8688
.Except(currentTipBranches)
8789
.ToList();
@@ -97,7 +99,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(
9799

98100
if (possibleParents.Count == 1)
99101
{
100-
var branchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, possibleParents[0]).Value;
102+
var branchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, possibleParents[0], excludedInheritBranches).Value;
101103
return new KeyValuePair<string, BranchConfig>(
102104
keyValuePair.Key,
103105
new BranchConfig(branchConfiguration)

0 commit comments

Comments
 (0)