Skip to content

Commit 0ade4b2

Browse files
authored
Merge branch 'master' into patch-1
2 parents 992d146 + c855918 commit 0ade4b2

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class GitToolsTestingExtensions
1919

2020
static GitToolsTestingExtensions() => sp = ConfigureService();
2121

22-
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
22+
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
2323
{
2424
if (configuration == null)
2525
{
@@ -31,7 +31,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
3131
var variableProvider = sp.GetService<IVariableProvider>();
3232
var versionFinder = sp.GetService<IGitVersionFinder>();
3333

34-
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, isForTrackedBranchOnly, commitId);
34+
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, onlyTrackedBranches, commitId);
3535
var executeGitVersion = versionFinder.FindVersion(gitVersionContext);
3636
var variables = variableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
3737

@@ -47,19 +47,19 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
4747
}
4848
}
4949

50-
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
50+
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
5151
{
52-
fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, isForTrackedBranchOnly, targetBranch);
52+
fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, onlyTrackedBranches, targetBranch);
5353
}
5454

55-
public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
55+
public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
5656
{
5757
configuration.Reset();
5858
Console.WriteLine("---------");
5959

6060
try
6161
{
62-
var variables = fixture.GetVersion(configuration, repository, commitId, isForTrackedBranchOnly, targetBranch);
62+
var variables = fixture.GetVersion(configuration, repository, commitId, onlyTrackedBranches, targetBranch);
6363
variables.FullSemVer.ShouldBe(fullSemver);
6464
}
6565
catch (Exception)

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void WhenDevelopBranchedFromMasterDetachedHeadMinorIsIncreased()
143143
var commit = fixture.Repository.Head.Tip;
144144
fixture.Repository.MakeACommit();
145145
Commands.Checkout(fixture.Repository, commit);
146-
fixture.AssertFullSemver("1.1.0-alpha.1");
146+
fixture.AssertFullSemver("1.1.0-alpha.1", onlyTrackedBranches: false);
147147
}
148148

149149
[Test]

src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using LibGit2Sharp;
33
using NUnit.Framework;
44
using GitVersion.Configuration;
@@ -93,7 +93,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0
9393
Commands.Checkout(fixture.Repository, commit);
9494

9595
// When
96-
fixture.AssertFullSemver("0.1.0+2");
96+
fixture.AssertFullSemver("0.1.0+2", onlyTrackedBranches: false);
9797
}
9898

9999
[Test]
@@ -207,4 +207,4 @@ public void AreTagsNotAdheringToTagPrefixIgnored()
207207
fixture.AssertFullSemver(config, "0.1.0+6"); //Fallback version + 6 commits since tag
208208
}
209209
}
210-
}
210+
}

src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void GivenARemoteGitRepositoryWhenCheckingOutDetachedheadUsingExistingImp
6868
fixture.LocalRepositoryFixture.Repository,
6969
fixture.LocalRepositoryFixture.Repository.Head.Tip);
7070

71-
Should.Throw<WarningException>(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, isForTrackedBranchOnly: false),
71+
Should.Throw<WarningException>(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, onlyTrackedBranches: false),
7272
$"It looks like the branch being examined is a detached Head pointing to commit '{fixture.LocalRepositoryFixture.Repository.Head.Tip.Id.ToString(7)}'. Without a proper branch name GitVersion cannot determine the build version.");
7373
}
7474

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BranchConfigurationCalculator(ILog log, GitVersionContext context)
2626
public BranchConfig GetBranchConfiguration(Branch targetBranch, IList<Branch> excludedInheritBranches = null)
2727
{
2828
var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote());
29-
29+
3030
if (matchingBranches == null)
3131
{
3232
log.Info($"No branch configuration found for branch {targetBranch.FriendlyName}, falling back to default configuration");
@@ -84,7 +84,7 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
8484
List<Branch> possibleParents;
8585
if (branchPoint == BranchCommit.Empty)
8686
{
87-
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, true)
87+
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, false)
8888
// It fails to inherit Increment branch configuration if more than 1 parent;
8989
// therefore no point to get more than 2 parents
9090
.Take(2)
@@ -93,11 +93,11 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
9393
else
9494
{
9595
var branches = context.RepositoryMetadataProvider
96-
.GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, true).ToList();
96+
.GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, false).ToList();
9797
if (branches.Count > 1)
9898
{
9999
var currentTipBranches = context.RepositoryMetadataProvider
100-
.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true).ToList();
100+
.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, false).ToList();
101101
possibleParents = branches.Except(currentTipBranches).ToList();
102102
}
103103
else

src/GitVersionCore/GitRepoMetadataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit(Commit commit, IList<Bran
8181
// TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
8282
foreach (var branch in branches)
8383
{
84-
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
84+
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || ((onlyTrackedBranches && branch.IsTracking) || !onlyTrackedBranches))
8585
{
8686
continue;
8787
}
@@ -97,7 +97,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit(Commit commit, IList<Bran
9797
}
9898

9999
log.Info($"No direct branches found, searching through {(onlyTrackedBranches ? "tracked" : "all")} branches.");
100-
foreach (var branch in branches.Where(b => onlyTrackedBranches && !b.IsTracking))
100+
foreach (var branch in branches.Where(b => (onlyTrackedBranches && b.IsTracking) || !onlyTrackedBranches))
101101
{
102102
log.Info($"Searching for commits reachable from '{branch.FriendlyName}'.");
103103

src/GitVersionCore/GitVersionContext.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public class GitVersionContext
1414
{
1515
private readonly ILog log;
1616

17-
public GitVersionContext(IRepository repository, ILog log, string targetBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null)
18-
: this(repository, log, GetTargetBranch(repository, targetBranch), configuration, onlyEvaluateTrackedBranches, commitId)
17+
public GitVersionContext(IRepository repository, ILog log, string targetBranch, Config configuration, bool onlyTrackedBranches = false, string commitId = null)
18+
: this(repository, log, GetTargetBranch(repository, targetBranch), configuration, onlyTrackedBranches, commitId)
1919
{
2020
}
2121

22-
public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null)
22+
public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, Config configuration, bool onlyTrackedBranches = false, string commitId = null)
2323
{
2424
this.log = log;
2525
Repository = repository;
2626
RepositoryMetadataProvider = new GitRepoMetadataProvider(repository, log, configuration);
2727
FullConfiguration = configuration;
28-
OnlyEvaluateTrackedBranches = onlyEvaluateTrackedBranches;
28+
OnlyTrackedBranches = onlyTrackedBranches;
2929

3030
if (currentBranch == null)
3131
throw new InvalidOperationException("Need a branch to operate on");
@@ -53,7 +53,7 @@ public GitVersionContext(IRepository repository, ILog log, Branch currentBranch,
5353

5454
if (currentBranch.IsDetachedHead())
5555
{
56-
CurrentBranch = RepositoryMetadataProvider.GetBranchesContainingCommit(CurrentCommit, repository.Branches.ToList(), OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch;
56+
CurrentBranch = RepositoryMetadataProvider.GetBranchesContainingCommit(CurrentCommit, repository.Branches.ToList(), OnlyTrackedBranches).OnlyOrDefault() ?? currentBranch;
5757
}
5858
else
5959
{
@@ -78,7 +78,7 @@ public GitVersionContext(IRepository repository, ILog log, Branch currentBranch,
7878
/// </summary>
7979
public Config FullConfiguration { get; }
8080
public SemanticVersion CurrentCommitTaggedVersion { get; }
81-
public bool OnlyEvaluateTrackedBranches { get; }
81+
public bool OnlyTrackedBranches { get; }
8282
public EffectiveConfiguration Configuration { get; private set; }
8383
public IRepository Repository { get; }
8484
public Branch CurrentBranch { get; }

0 commit comments

Comments
 (0)