Skip to content

Commit

Permalink
replace IBranch.IsSameBranch with Equals
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Jan 19, 2021
1 parent 0f027ae commit 1ebd0e5
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 18 deletions.
10 changes: 0 additions & 10 deletions src/GitVersion.LibGit2Sharp/Git/Branch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using GitVersion.Extensions;
using GitVersion.Helpers;

namespace GitVersion
Expand Down Expand Up @@ -50,15 +49,6 @@ internal sealed class Branch : IBranch
}
}

/// <summary>
/// Checks if the two branch objects refer to the same branch (have the same friendly name).
/// </summary>
public bool IsSameBranch(IBranch otherBranch)
{
// For each branch, fixup the friendly name if the branch is remote.
var otherBranchFriendlyName = otherBranch.NameWithoutRemote;
return otherBranchFriendlyName.IsEquivalentTo(NameWithoutRemote);
}
public bool IsDetachedHead => CanonicalName.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);

public bool IsRemote => innerBranch.IsRemote;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IEnumerator<IBranch> GetEnumerator()
}

public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude) =>
this.Where(b => branchesToExclude.All(bte => !b.IsSameBranch(bte)));
this.Where(b => branchesToExclude.All(bte => !b.Equals(bte)));
public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) =>
innerCollection.Update((Branch)branch, b => b.TrackedBranch = remoteTrackingReferenceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf

excludedInheritBranches ??= repositoryMetadataProvider.GetExcludedInheritBranches(configuration).ToList();

excludedBranches = excludedBranches.Where(b => excludedInheritBranches.All(bte => !b.IsSameBranch(bte))).ToArray();
excludedBranches = excludedBranches.Where(b => excludedInheritBranches.All(bte => !b.Equals(bte))).ToArray();
// Add new excluded branches.
foreach (var excludedBranch in excludedBranches)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf
log.Warning(errorMessage + System.Environment.NewLine + "Falling back to " + branchName + " branch config");

// To prevent infinite loops, make sure that a new branch was chosen.
if (targetBranch.IsSameBranch(chosenBranch))
if (targetBranch.Equals(chosenBranch))
{
var developOrMasterConfig =
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(
Expand Down
1 change: 0 additions & 1 deletion src/GitVersionCore/Core/Abstractions/Git/IBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ public interface IBranch : IEquatable<IBranch>, IComparable<IBranch>
bool IsTracking { get; }
bool IsDetachedHead { get; }
ICommitCollection Commits { get; }
bool IsSameBranch(IBranch otherBranch);
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore/Core/RepositoryMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch branch, Config confi
}

var possibleBranches = GetMergeCommitsForBranch(branch, configuration, excludedBranches)
.Where(b => !branch.IsSameBranch(b.Branch))
.Where(b => !branch.Equals(b.Branch))
.ToList();

if (possibleBranches.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion)
var mainlineTip = mainline.Tip;

// when the current branch is not mainline, find the effective mainline tip for versioning the branch
if (!context.CurrentBranch.IsSameBranch(mainline))
if (!context.CurrentBranch.Equals(mainline))
{
mergeBase = FindMergeBaseBeforeForwardMerge(baseVersion.BaseVersionSource, mainline, out mainlineTip);
log.Info($"Current branch ({context.CurrentBranch.FriendlyName}) was branch from {mergeBase}");
Expand Down Expand Up @@ -71,7 +71,7 @@ public SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion)
mainlineVersion.BuildMetaData = CreateVersionBuildMetaData(mergeBase);

// branches other than master always get a bump for the act of branching
if ((!context.CurrentBranch.IsSameBranch(mainline)) && (string.IsNullOrEmpty(context.Configuration.NextVersion)))
if ((!context.CurrentBranch.Equals(mainline)) && (string.IsNullOrEmpty(context.Configuration.NextVersion)))
{
var branchIncrement = FindMessageIncrement(null, context.CurrentCommit, mergeBase, mainlineCommitLog);
log.Info($"Performing {branchIncrement} increment for current branch ");
Expand Down Expand Up @@ -140,7 +140,7 @@ private IBranch GetMainline(ICommit baseVersionSource)
}

// prefer current branch, if it is a mainline branch
if (possibleMainlineBranches.Any(context.CurrentBranch.IsSameBranch))
if (possibleMainlineBranches.Any(context.CurrentBranch.Equals))
{
log.Info($"Choosing {context.CurrentBranch.FriendlyName} as mainline because it is the current branch");
return context.CurrentBranch;
Expand Down

0 comments on commit 1ebd0e5

Please sign in to comment.