Skip to content

Commit 6a5d0e1

Browse files
committed
Fixed broken test
1 parent d68122f commit 6a5d0e1

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

GitVersionCore.Tests/Fixtures/EmptyRepositoryFixture.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public EmptyRepositoryFixture(Config configuration) :
99
{
1010
}
1111

12-
public void DumpGraph()
13-
{
14-
Repository.DumpGraph();
15-
}
16-
1712
static IRepository CreateNewRepository(string path)
1813
{
1914
LibGit2Sharp.Repository.Init(path);

GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using GitVersion;
34
using LibGit2Sharp;
45
using Shouldly;
@@ -30,7 +31,16 @@ public void AssertFullSemver(string fullSemver, IRepository repository = null, s
3031
gitVersionContext.Configuration.VersioningMode,
3132
gitVersionContext.Configuration.ContinuousDeploymentFallbackTag,
3233
gitVersionContext.IsCurrentCommitTagged);
33-
variables.FullSemVer.ShouldBe(fullSemver);
34+
try
35+
{
36+
variables.FullSemVer.ShouldBe(fullSemver);
37+
}
38+
catch (Exception)
39+
{
40+
Trace.WriteLine("Test failing, dumping repository graph");
41+
repository.DumpGraph();
42+
throw;
43+
}
3444
}
3545

3646
private SemanticVersion ExecuteGitVersion(GitVersionContext context)

GitVersionCore.Tests/Helpers/GitTestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void DumpGraph(this IRepository repository)
2020
e => output.AppendLineFormat("ERROR: {0}", e),
2121
null,
2222
"git",
23-
@"log --graph --abbrev-commit --decorate --date=relative --all",
23+
@"log --graph --abbrev-commit --decorate --date=relative --all --remotes=*",
2424
repository.Info.Path);
2525

2626
Trace.Write(output.ToString());

GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void CanCalculatePullRequestChanges()
1616

1717
fixture.Repository.CreatePullRequest("feature/Foo", "master");
1818

19-
fixture.DumpGraph();
19+
fixture.Repository.DumpGraph();
2020
fixture.AssertFullSemver("0.1.1-PullRequest.2+2");
2121
}
2222
}
@@ -34,7 +34,7 @@ public void CanCalculatePullRequestChangesInheritingConfig()
3434

3535
fixture.Repository.CreatePullRequest("feature/Foo", "develop", 44);
3636

37-
fixture.DumpGraph();
37+
fixture.Repository.DumpGraph();
3838
fixture.AssertFullSemver("0.2.0-PullRequest.44+3");
3939
}
4040
}
@@ -51,7 +51,7 @@ public void CanCalculatePullRequestChangesFromRemoteRepo()
5151

5252
fixture.Repository.CreatePullRequest("feature/Foo", "master");
5353

54-
fixture.DumpGraph();
54+
fixture.Repository.DumpGraph();
5555
fixture.AssertFullSemver("0.1.1-PullRequest.2+2");
5656
}
5757
}

GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
105105

106106
Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.Name)));
107107

108-
// If it comes down to master and something, master is always first so we pick other branch
109-
if (possibleParents.Count == 2 && possibleParents.Any(p => p.Name == "master"))
110-
{
111-
possibleParents.Remove(possibleParents.Single(p => p.Name == "master"));
112-
}
113-
114108
if (possibleParents.Count == 1)
115109
{
116110
var branchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, possibleParents[0], excludedInheritBranches).Value;

GitVersionCore/LibGitExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static Branch FindBranch(this IRepository repository, string branchName)
2626

2727
public static Commit FindCommitBranchWasBranchedFrom(this Branch branch, IRepository repository, params Branch[] excludedBranches)
2828
{
29-
var otherBranches = repository.Branches.Where(b => !b.IsRemote).Except(excludedBranches).Except(new [] { branch }).ToList();
29+
var otherBranches = repository.Branches.Except(excludedBranches).Where(b => IsSameBranch(branch, b)).ToList();
3030
var mergeBases = otherBranches.Select(b =>
3131
{
3232
var otherCommit = b.Tip;
@@ -36,10 +36,15 @@ public static Commit FindCommitBranchWasBranchedFrom(this Branch branch, IReposi
3636
}
3737
var mergeBase = repository.Commits.FindMergeBase(otherCommit, branch.Tip);
3838
return mergeBase;
39-
}).Where(b => b != null);
39+
}).Where(b => b != null).ToList();
4040
return mergeBases.OrderByDescending(b => b.Committer.When).FirstOrDefault();
4141
}
4242

43+
static bool IsSameBranch(Branch branch, Branch b)
44+
{
45+
return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name;
46+
}
47+
4348
public static IEnumerable<Branch> GetBranchesContainingCommit(this Commit commit, IRepository repository, bool onlyTrackedBranches)
4449
{
4550
var directBranchHasBeenFound = false;

GitVersionCore/VersionCalculation/MetaDataCalculator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public SemanticVersionBuildMetaData Create(Commit baseVersionSource, GitVersionC
1616

1717
var commitLog = context.Repository.Commits.QueryBy(qf);
1818
var commitsSinceTag = commitLog.Count();
19+
Logger.WriteInfo(string.Format("{0} commits found between {1} and {2}", commitsSinceTag, baseVersionSource.Sha, context.CurrentCommit.Sha));
1920

2021
return new SemanticVersionBuildMetaData(
2122
commitsSinceTag,

GitVersionExe.Tests/GitPreparerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void UpdatesExistingDynamicRepository()
109109

110110
using (var repository = new Repository(dynamicRepositoryPath))
111111
{
112-
mainRepositoryFixture.DumpGraph();
112+
mainRepositoryFixture.Repository.DumpGraph();
113113
repository.DumpGraph();
114114
repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha);
115115
}

0 commit comments

Comments
 (0)