Skip to content

Commit 810d309

Browse files
committed
Fixed a few tests and the way inheriting increment strategy works
1 parent 690399e commit 810d309

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.IO;
3-
using System.Text;
43
using GitVersion;
5-
using GitVersion.Helpers;
64
using LibGit2Sharp;
75

86
/// <summary>
@@ -41,19 +39,4 @@ void SetupRepo(Action<IRepository> initialMasterAction)
4139
Repository.CreateBranch("develop").Checkout();
4240
Repository.MakeACommit();
4341
}
44-
45-
public void DumpGraph()
46-
{
47-
var output = new StringBuilder();
48-
49-
ProcessHelper.Run(
50-
o => output.AppendLine(o),
51-
e => output.AppendLineFormat("ERROR: {0}", e),
52-
null,
53-
"git",
54-
@"log --graph --abbrev-commit --decorate --date=relative --all",
55-
RepositoryPath);
56-
57-
Console.Write(output.ToString());
58-
}
5942
}

GitVersionCore.Tests/Fixtures/EmptyRepositoryFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Text;
23
using GitVersion;
4+
using GitVersion.Helpers;
35
using LibGit2Sharp;
46

57
public class EmptyRepositoryFixture : RepositoryFixtureBase
@@ -9,6 +11,21 @@ public EmptyRepositoryFixture(Config configuration) :
911
{
1012
}
1113

14+
public void DumpGraph()
15+
{
16+
var output = new StringBuilder();
17+
18+
ProcessHelper.Run(
19+
o => output.AppendLine(o),
20+
e => output.AppendLineFormat("ERROR: {0}", e),
21+
null,
22+
"git",
23+
@"log --graph --abbrev-commit --decorate --date=relative --all",
24+
RepositoryPath);
25+
26+
Console.Write(output.ToString());
27+
}
28+
1229
static IRepository CreateNewRepository(string path)
1330
{
1431
LibGit2Sharp.Repository.Init(path);

GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void CanFindParentBranchForInheritingIncrementStrategy()
6868
featureBranch.Checkout();
6969
repo.Repository.MakeACommit();
7070

71-
var context = new GitVersionContext(repo.Repository, featureBranch, config);
71+
var context = new GitVersionContext(repo.Repository, config);
7272
context.Configuration.Increment.ShouldBe(IncrementStrategy.Major);
7373
}
7474
}

GitVersionCore/GitVersionContext.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,20 @@ KeyValuePair<string, BranchConfig> GetBranchConfiguration(Branch currentBranch)
107107

108108
if (branchConfiguration.Increment == IncrementStrategy.Inherit)
109109
{
110-
var firstCommitOfBranch = currentBranch.Commits.Last();
111-
var parentCommit = Repository.Commits.QueryBy(new CommitFilter
112-
{
113-
Until = firstCommitOfBranch
114-
}).First().Parents.First();
115-
var branchesContainingFirstCommit = ListBranchesContaininingCommit(Repository, firstCommitOfBranch.Sha);
116-
var branchesContainingParentCommit = ListBranchesContaininingCommit(Repository, parentCommit.Sha);
117-
110+
var tips = Repository.Branches.Select(b => b.Tip).Where(c => c.Sha != CurrentCommit.Sha).ToList();
111+
var branchPoint = Repository.Commits.First(c => tips.Contains(c) || c.Parents.Count() > 1);
112+
var branches = ListBranchesContaininingCommit(Repository, branchPoint.Sha).ToArray();
113+
var currentTipBranches = ListBranchesContaininingCommit(Repository, CurrentCommit.Sha).ToArray();
118114
var branchNameComparer = new BranchNameComparer();
119-
var possibleParents = branchesContainingFirstCommit
120-
.Intersect(branchesContainingParentCommit, branchNameComparer)
121-
.Except(new[] { currentBranch }, branchNameComparer)
122-
.ToArray();
115+
var possibleParents = branches
116+
.Except(currentTipBranches, branchNameComparer)
117+
.ToList();
118+
119+
// If it comes down to master and something, master is always first so we pick other branch
120+
if (possibleParents.Count == 2 && possibleParents.Any(p => p.Name == "master"))
121+
possibleParents.Remove(possibleParents.Single(p => p.Name == "master"));
123122

124-
if (possibleParents.Length == 1)
123+
if (possibleParents.Count == 1)
125124
{
126125
return new KeyValuePair<string, BranchConfig>(
127126
keyValuePair.Key,

0 commit comments

Comments
 (0)