diff --git a/.gitignore b/.gitignore index cae0bc79c6..f32c94de93 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ NuGetExeBuild/ NuGetRefBuild/ Packages/ NuGetTaskBuild/ +GitVersionTfsTaskBuild/ \ No newline at end of file diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index 10a98ee588..e06af72eee 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -65,29 +65,33 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv { excludedBranches = CalculateWhenMultipleParents(repository, currentCommit, ref currentBranch, excludedBranches); } + if (excludedInheritBranches == null) { excludedInheritBranches = repository.Branches.Where(b => { var branchConfig = LookupBranchConfiguration(config, b); - return branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit; + + // NOTE: if length is 0 we couldn't find the configuration for the branch e.g. "origin/master" + // NOTE: if the length is greater than 1 we cannot decide which merge strategy to pick + return (branchConfig.Length != 1) || (branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit); }).ToList(); } excludedBranches.ToList().ForEach(excludedInheritBranches.Add); + var branchesToEvaluate = repository.Branches.Except(excludedInheritBranches).ToList(); var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(repository, excludedInheritBranches.ToArray()); - List possibleParents; if (branchPoint == null) { - possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList(); + possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList(); } else { - var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList(); + var branches = branchPoint.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList(); if (branches.Count > 1) { - var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList(); + var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList(); possibleParents = branches.Except(currentTipBranches).ToList(); } else diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index ccdb3d2f88..c7ee591eea 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -48,7 +48,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co if (currentBranch.IsDetachedHead()) { - CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch; + CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, repository.Branches.ToList(), OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch; } else { diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs index 2bc9f6a4f6..f8290a7149 100644 --- a/src/GitVersionCore/LibGitExtensions.cs +++ b/src/GitVersionCore/LibGitExtensions.cs @@ -92,7 +92,7 @@ static bool IsSameBranch(Branch branch, Branch b) return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name; } - public static IEnumerable GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, bool onlyTrackedBranches) + public static IEnumerable GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, IList branches, bool onlyTrackedBranches) { if (commit == null) { @@ -100,7 +100,7 @@ public static IEnumerable GetBranchesContainingCommit([NotNull] this Com } var directBranchHasBeenFound = false; - foreach (var branch in repository.Branches) + foreach (var branch in branches) { if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking)) { @@ -116,7 +116,7 @@ public static IEnumerable GetBranchesContainingCommit([NotNull] this Com yield break; } - foreach (var branch in repository.Branches.Where(b => (onlyTrackedBranches && !b.IsTracking))) + foreach (var branch in branches.Where(b => (onlyTrackedBranches && !b.IsTracking))) { var commits = repository.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commit.Sha);