/// <summary>
/// Find the commit where the given branch was branched from another branch.
/// If there are multiple such commits and branches, tries to guess based on commit histories.
/// </summary>
public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch[] excludedBranches)
{
if (branch == null)
{
throw new ArgumentNullException("branch");
}
using (Logger.IndentLog(string.Format("Finding branch source of '{0}'", branch.FriendlyName)))
{
if (branch.Tip == null)
{
Logger.WriteWarning(string.Format(missingTipFormat, branch.FriendlyName));
return(BranchCommit.Empty);
}
var possibleBranches = GetMergeCommitsForBranch(branch, excludedBranches)
.Where(b => !branch.IsSameBranch(b.Branch))
.ToList();
if (possibleBranches.Count > 1)
{
var first = possibleBranches.First();
Logger.WriteInfo($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).\n" +
"This may result in incorrect commit counting.\nOptions were:\n " +
string.Join(", ", possibleBranches.Select(b => b.Branch.FriendlyName)));
return(first);
}
return(possibleBranches.SingleOrDefault());
}
}