Skip to content

Commit 1ebd0e5

Browse files
committed
replace IBranch.IsSameBranch with Equals
1 parent 0f027ae commit 1ebd0e5

File tree

6 files changed

+7
-18
lines changed

6 files changed

+7
-18
lines changed

src/GitVersion.LibGit2Sharp/Git/Branch.cs

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using GitVersion.Extensions;
32
using GitVersion.Helpers;
43

54
namespace GitVersion
@@ -50,15 +49,6 @@ public ICommitCollection? Commits
5049
}
5150
}
5251

53-
/// <summary>
54-
/// Checks if the two branch objects refer to the same branch (have the same friendly name).
55-
/// </summary>
56-
public bool IsSameBranch(IBranch otherBranch)
57-
{
58-
// For each branch, fixup the friendly name if the branch is remote.
59-
var otherBranchFriendlyName = otherBranch.NameWithoutRemote;
60-
return otherBranchFriendlyName.IsEquivalentTo(NameWithoutRemote);
61-
}
6252
public bool IsDetachedHead => CanonicalName.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
6353

6454
public bool IsRemote => innerBranch.IsRemote;

src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public IBranch? this[string friendlyName]
2424
}
2525

2626
public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude) =>
27-
this.Where(b => branchesToExclude.All(bte => !b.IsSameBranch(bte)));
27+
this.Where(b => branchesToExclude.All(bte => !b.Equals(bte)));
2828
public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) =>
2929
innerCollection.Update((Branch)branch, b => b.TrackedBranch = remoteTrackingReferenceName);
3030
}

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf
7070

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

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

141141
// To prevent infinite loops, make sure that a new branch was chosen.
142-
if (targetBranch.IsSameBranch(chosenBranch))
142+
if (targetBranch.Equals(chosenBranch))
143143
{
144144
var developOrMasterConfig =
145145
ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(

src/GitVersionCore/Core/Abstractions/Git/IBranch.cs

-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ public interface IBranch : IEquatable<IBranch>, IComparable<IBranch>
1313
bool IsTracking { get; }
1414
bool IsDetachedHead { get; }
1515
ICommitCollection Commits { get; }
16-
bool IsSameBranch(IBranch otherBranch);
1716
}
1817
}

src/GitVersionCore/Core/RepositoryMetadataProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch branch, Config confi
303303
}
304304

305305
var possibleBranches = GetMergeCommitsForBranch(branch, configuration, excludedBranches)
306-
.Where(b => !branch.IsSameBranch(b.Branch))
306+
.Where(b => !branch.Equals(b.Branch))
307307
.ToList();
308308

309309
if (possibleBranches.Count > 1)

src/GitVersionCore/VersionCalculation/MainlineVersionCalculator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion)
4343
var mainlineTip = mainline.Tip;
4444

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

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

142142
// prefer current branch, if it is a mainline branch
143-
if (possibleMainlineBranches.Any(context.CurrentBranch.IsSameBranch))
143+
if (possibleMainlineBranches.Any(context.CurrentBranch.Equals))
144144
{
145145
log.Info($"Choosing {context.CurrentBranch.FriendlyName} as mainline because it is the current branch");
146146
return context.CurrentBranch;

0 commit comments

Comments
 (0)