Skip to content

Make sure that we're not evaluating excluded branches #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ NuGetExeBuild/
NuGetRefBuild/
Packages/
NuGetTaskBuild/
GitVersionTfsTaskBuild/
14 changes: 9 additions & 5 deletions src/GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,33 @@ static KeyValuePair<string, BranchConfig> 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<Branch> 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
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/GitVersionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersionCore/LibGitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, bool onlyTrackedBranches)
public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, IList<Branch> branches, bool onlyTrackedBranches)
{
if (commit == null)
{
throw new ArgumentNullException("commit");
}

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))
{
Expand All @@ -116,7 +116,7 @@ public static IEnumerable<Branch> 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);

Expand Down