本文整理汇总了C#中Branch.IsSameBranch方法的典型用法代码示例。如果您正苦于以下问题:C# Branch.IsSameBranch方法的具体用法?C# Branch.IsSameBranch怎么用?C# Branch.IsSameBranch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch.IsSameBranch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InheritBranchConfiguration
static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch targetBranch, BranchConfig branchConfiguration, IList<Branch> excludedInheritBranches)
{
var repository = context.Repository;
var config = context.FullConfiguration;
using (Logger.IndentLog("Attempting to inherit branch configuration from parent branch"))
{
var excludedBranches = new[] { targetBranch };
// Check if we are a merge commit. If so likely we are a pull request
var parentCount = context.CurrentCommit.Parents.Count();
if (parentCount == 2)
{
excludedBranches = CalculateWhenMultipleParents(repository, context.CurrentCommit, ref targetBranch, excludedBranches);
}
if (excludedInheritBranches == null)
{
excludedInheritBranches = repository.Branches.Where(b =>
{
var branchConfig = LookupBranchConfiguration(config, b).ToArray();
// 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].Increment == IncrementStrategy.Inherit);
}).ToList();
}
// Add new excluded branches.
foreach (var excludedBranch in excludedBranches.ExcludingBranches(excludedInheritBranches))
{
excludedInheritBranches.Add(excludedBranch);
}
var branchesToEvaluate = repository.Branches.Except(excludedInheritBranches).ToList();
var branchPoint = context.RepositoryMetadataProvider
.FindCommitBranchWasBranchedFrom(targetBranch, excludedInheritBranches.ToArray());
List<Branch> possibleParents;
if (branchPoint == BranchCommit.Empty)
{
possibleParents = context.RepositoryMetadataProvider.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true)
// It fails to inherit Increment branch configuration if more than 1 parent;
// therefore no point to get more than 2 parents
.Take(2)
.ToList();
}
else
{
var branches = context.RepositoryMetadataProvider
.GetBranchesContainingCommit(branchPoint.Commit, branchesToEvaluate, true).ToList();
if (branches.Count > 1)
{
var currentTipBranches = context.RepositoryMetadataProvider
.GetBranchesContainingCommit(context.CurrentCommit, branchesToEvaluate, true).ToList();
possibleParents = branches.Except(currentTipBranches).ToList();
}
else
{
possibleParents = branches;
}
}
Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName)));
if (possibleParents.Count == 1)
{
var branchConfig = GetBranchConfiguration(context, possibleParents[0], excludedInheritBranches);
return new BranchConfig(branchConfiguration)
{
Increment = branchConfig.Increment,
PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
// If we are inheriting from develop then we should behave like develop
TracksReleaseBranches = branchConfig.TracksReleaseBranches
};
}
// If we fail to inherit it is probably because the branch has been merged and we can't do much. So we will fall back to develop's config
// if develop exists and master if not
string errorMessage;
if (possibleParents.Count == 0)
errorMessage = "Failed to inherit Increment branch configuration, no branches found.";
else
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName));
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, "^develop", RegexOptions.IgnoreCase)
|| Regex.IsMatch(b.FriendlyName, "master$", RegexOptions.IgnoreCase));
if (chosenBranch == null)
{
// TODO We should call the build server to generate this exception, each build server works differently
// for fetch issues and we could give better warnings.
throw new InvalidOperationException("Could not find a 'develop' or 'master' branch, neither locally nor remotely.");
}
var branchName = chosenBranch.FriendlyName;
Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config");
// To prevent infinite loops, make sure that a new branch was chosen.
if (targetBranch.IsSameBranch(chosenBranch))
{
Logger.WriteWarning("Fallback branch wants to inherit Increment branch configuration from itself. Using patch increment instead.");
return new BranchConfig(branchConfiguration)
{
Increment = IncrementStrategy.Patch
//.........这里部分代码省略.........