/// <summary> /// Gets the <see cref="BranchConfig"/> for the current commit. /// </summary> public static BranchConfig GetBranchConfiguration(GitVersionContext context, Branch targetBranch, IList <Branch> excludedInheritBranches = null) { var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote()); if (matchingBranches == null) { Logger.WriteInfo($"No branch configuration found for branch {targetBranch.FriendlyName}, falling back to default configuration"); matchingBranches = new BranchConfig { Name = FallbackConfigName }; ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List <string>()); } if (matchingBranches.Increment == IncrementStrategy.Inherit) { matchingBranches = InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches); if (matchingBranches.Name == FallbackConfigName && matchingBranches.Increment == IncrementStrategy.Inherit) { // We tried, and failed to inherit, just fall back to patch matchingBranches.Increment = IncrementStrategy.Patch; } } return(matchingBranches); }
/// <summary> /// Checks if the two branch objects refer to the same branch (have the same friendly name). /// </summary> public static bool IsSameBranch(this Branch branch, Branch otherBranch) { // For each branch, fixup the friendly name if the branch is remote. var otherBranchFriendlyName = otherBranch.NameWithoutRemote(); var branchFriendlyName = branch.NameWithoutRemote(); return(otherBranchFriendlyName == branchFriendlyName); }
List <BranchCommit> GetMergeCommitsForBranch(Branch branch, Branch[] excludedBranches) { if (mergeBaseCommitsCache.ContainsKey(branch)) { Logger.WriteDebug(string.Format( "Cache hit for getting merge commits for branch {0}.", branch.CanonicalName)); return(mergeBaseCommitsCache[branch]); } var currentBranchConfig = configuration.GetConfigForBranch(branch.NameWithoutRemote()); var regexesToCheck = currentBranchConfig == null ? new [] { ".*" } // Match anything if we can't find a branch config : currentBranchConfig.SourceBranches.Select(sb => configuration.Branches[sb].Regex); var branchMergeBases = Repository.Branches .ExcludingBranches(excludedBranches) .Where(b => { if (b == branch) { return(false); } var branchCanBeMergeBase = regexesToCheck.Any(regex => Regex.IsMatch(b.FriendlyName, regex)); return(branchCanBeMergeBase); }) .Select(otherBranch => { if (otherBranch.Tip == null) { Logger.WriteWarning(string.Format(missingTipFormat, otherBranch.FriendlyName)); return(BranchCommit.Empty); } var findMergeBase = FindMergeBase(branch, otherBranch); return(new BranchCommit(findMergeBase, otherBranch)); }) .Where(b => b.Commit != null) .OrderByDescending(b => b.Commit.Committer.When) .ToList(); mergeBaseCommitsCache.Add(branch, branchMergeBases); return(branchMergeBases); }