diff --git a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs index 857754ba1a..754b65c0c4 100644 --- a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs +++ b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs @@ -19,7 +19,7 @@ public static class GitToolsTestingExtensions static GitToolsTestingExtensions() => sp = ConfigureService(); - public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null) + public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null) { if (configuration == null) { @@ -31,7 +31,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co var variableProvider = sp.GetService(); var versionFinder = sp.GetService(); - var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, isForTrackedBranchOnly, commitId); + var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, onlyTrackedBranches, commitId); var executeGitVersion = versionFinder.FindVersion(gitVersionContext); var variables = variableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged); @@ -47,19 +47,19 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co } } - public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null) + public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null) { - fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, isForTrackedBranchOnly, targetBranch); + fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, onlyTrackedBranches, targetBranch); } - public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null) + public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null) { configuration.Reset(); Console.WriteLine("---------"); try { - var variables = fixture.GetVersion(configuration, repository, commitId, isForTrackedBranchOnly, targetBranch); + var variables = fixture.GetVersion(configuration, repository, commitId, onlyTrackedBranches, targetBranch); variables.FullSemVer.ShouldBe(fullSemver); } catch (Exception) diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index 76abbf6215..74c4b293ca 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -143,7 +143,7 @@ public void WhenDevelopBranchedFromMasterDetachedHeadMinorIsIncreased() var commit = fixture.Repository.Head.Tip; fixture.Repository.MakeACommit(); Commands.Checkout(fixture.Repository, commit); - fixture.AssertFullSemver("1.1.0-alpha.1"); + fixture.AssertFullSemver("1.1.0-alpha.1", onlyTrackedBranches: false); } [Test] diff --git a/src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs index a5daa8e42c..54bd232b50 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs @@ -1,4 +1,4 @@ -using GitTools.Testing; +using GitTools.Testing; using LibGit2Sharp; using NUnit.Framework; using GitVersion.Configuration; @@ -93,7 +93,7 @@ public void GivenARepositoryWithCommitsButNoTagsWithDetachedHeadVersionShouldBe0 Commands.Checkout(fixture.Repository, commit); // When - fixture.AssertFullSemver("0.1.0+2"); + fixture.AssertFullSemver("0.1.0+2", onlyTrackedBranches: false); } [Test] @@ -207,4 +207,4 @@ public void AreTagsNotAdheringToTagPrefixIgnored() fixture.AssertFullSemver(config, "0.1.0+6"); //Fallback version + 6 commits since tag } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs index 9f4087b022..087f10a433 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs @@ -68,7 +68,7 @@ public void GivenARemoteGitRepositoryWhenCheckingOutDetachedheadUsingExistingImp fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Head.Tip); - Should.Throw(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, isForTrackedBranchOnly: false), + Should.Throw(() => fixture.AssertFullSemver("0.1.0+4", fixture.LocalRepositoryFixture.Repository, onlyTrackedBranches: false), $"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."); } diff --git a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs index c4b02de1b6..4073622fa3 100644 --- a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs @@ -26,7 +26,7 @@ public BranchConfigurationCalculator(ILog log, GitVersionContext context) public BranchConfig GetBranchConfiguration(Branch targetBranch, IList excludedInheritBranches = null) { var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote()); - + if (matchingBranches == null) { 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 List possibleParents; if (branchPoint == BranchCommit.Empty) { - possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, true) + possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(targetBranch.Tip, branchesToEvaluate, false) // It fails to inherit Increment branch configuration if more than 1 parent; // therefore no point to get more than 2 parents .Take(2) @@ -93,11 +93,11 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi else { var branches = context.RepositoryMetadataProvider - .GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, true).ToList(); + .GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, false).ToList(); if (branches.Count > 1) { var currentTipBranches = context.RepositoryMetadataProvider - .GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true).ToList(); + .GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, false).ToList(); possibleParents = branches.Except(currentTipBranches).ToList(); } else diff --git a/src/GitVersionCore/GitRepoMetadataProvider.cs b/src/GitVersionCore/GitRepoMetadataProvider.cs index 1d82939508..ddc80558da 100644 --- a/src/GitVersionCore/GitRepoMetadataProvider.cs +++ b/src/GitVersionCore/GitRepoMetadataProvider.cs @@ -81,7 +81,7 @@ public IEnumerable GetBranchesContainingCommit(Commit commit, IList GetBranchesContainingCommit(Commit commit, IList onlyTrackedBranches && !b.IsTracking)) + foreach (var branch in branches.Where(b => (onlyTrackedBranches && b.IsTracking) || !onlyTrackedBranches)) { log.Info($"Searching for commits reachable from '{branch.FriendlyName}'."); diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 896a513d82..a97d4b93fc 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -14,18 +14,18 @@ public class GitVersionContext { private readonly ILog log; - public GitVersionContext(IRepository repository, ILog log, string targetBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null) - : this(repository, log, GetTargetBranch(repository, targetBranch), configuration, onlyEvaluateTrackedBranches, commitId) + public GitVersionContext(IRepository repository, ILog log, string targetBranch, Config configuration, bool onlyTrackedBranches = false, string commitId = null) + : this(repository, log, GetTargetBranch(repository, targetBranch), configuration, onlyTrackedBranches, commitId) { } - public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null) + public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, Config configuration, bool onlyTrackedBranches = false, string commitId = null) { this.log = log; Repository = repository; RepositoryMetadataProvider = new GitRepoMetadataProvider(repository, log, configuration); FullConfiguration = configuration; - OnlyEvaluateTrackedBranches = onlyEvaluateTrackedBranches; + OnlyTrackedBranches = onlyTrackedBranches; if (currentBranch == null) throw new InvalidOperationException("Need a branch to operate on"); @@ -53,7 +53,7 @@ public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, if (currentBranch.IsDetachedHead()) { - CurrentBranch = RepositoryMetadataProvider.GetBranchesContainingCommit(CurrentCommit, repository.Branches.ToList(), OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch; + CurrentBranch = RepositoryMetadataProvider.GetBranchesContainingCommit(CurrentCommit, repository.Branches.ToList(), OnlyTrackedBranches).OnlyOrDefault() ?? currentBranch; } else { @@ -78,7 +78,7 @@ public GitVersionContext(IRepository repository, ILog log, Branch currentBranch, /// public Config FullConfiguration { get; } public SemanticVersion CurrentCommitTaggedVersion { get; } - public bool OnlyEvaluateTrackedBranches { get; } + public bool OnlyTrackedBranches { get; } public EffectiveConfiguration Configuration { get; private set; } public IRepository Repository { get; } public Branch CurrentBranch { get; }