Skip to content

Commit 6c05548

Browse files
committed
removed *Name from ReferenceName properties, implemented ToString()
1 parent 46ce1d4 commit 6c05548

18 files changed

+130
-112
lines changed

src/GitVersion.LibGit2Sharp/Git/Branch.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace GitVersion
55
{
66
internal sealed class Branch : IBranch
77
{
8-
private static readonly LambdaEqualityHelper<IBranch> equalityHelper = new(x => x.Name.CanonicalName);
9-
private static readonly LambdaKeyComparer<IBranch, string> comparerHelper = new(x => x.Name.CanonicalName);
8+
private static readonly LambdaEqualityHelper<IBranch> equalityHelper = new(x => x.Name.Canonical);
9+
private static readonly LambdaKeyComparer<IBranch, string> comparerHelper = new(x => x.Name.Canonical);
1010

1111
private readonly LibGit2Sharp.Branch innerBranch;
1212

@@ -18,9 +18,10 @@ internal Branch(LibGit2Sharp.Branch branch)
1818
public ReferenceName Name { get; }
1919

2020
public int CompareTo(IBranch other) => comparerHelper.Compare(this, other);
21-
public override bool Equals(object obj) => Equals((obj as IBranch)!);
2221
public bool Equals(IBranch other) => equalityHelper.Equals(this, other);
22+
public override bool Equals(object obj) => Equals((obj as IBranch)!);
2323
public override int GetHashCode() => equalityHelper.GetHashCode(this);
24+
public override string ToString() => Name.ToString();
2425
public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch;
2526

2627
public ICommit? Tip
@@ -41,7 +42,7 @@ public ICommitCollection? Commits
4142
}
4243
}
4344

44-
public bool IsDetachedHead => Name.CanonicalName.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
45+
public bool IsDetachedHead => Name.Canonical.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
4546

4647
public bool IsRemote => innerBranch.IsRemote;
4748
public bool IsTracking => innerBranch.IsTracking;

src/GitVersion.LibGit2Sharp/Git/Commit.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ internal sealed class Commit : ICommit
1515
internal Commit(LibGit2Sharp.Commit innerCommit) => this.innerCommit = innerCommit;
1616

1717
public int CompareTo(ICommit other) => comparerHelper.Compare(this, other);
18-
public override bool Equals(object obj) => Equals((obj as ICommit)!);
1918
public bool Equals(ICommit other) => equalityHelper.Equals(this, other);
19+
public override bool Equals(object obj) => Equals((obj as ICommit)!);
2020
public override int GetHashCode() => equalityHelper.GetHashCode(this);
21-
21+
public override string ToString()
22+
{
23+
return $"{Id.ToString(7)} {innerCommit.MessageShort}";
24+
}
2225
public static implicit operator LibGit2Sharp.Commit(Commit d) => d.innerCommit;
2326

2427
public IEnumerable<ICommit> Parents => innerCommit.Parents.Select(parent => new Commit(parent));

src/GitVersion.LibGit2Sharp/Git/ObjectId.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public ObjectId(string sha) : this(new LibGit2Sharp.ObjectId(sha))
1515
}
1616

1717
public int CompareTo(IObjectId other) => comparerHelper.Compare(this, other);
18-
public override bool Equals(object obj) => Equals((obj as IObjectId)!);
1918
public bool Equals(IObjectId other) => equalityHelper.Equals(this, other);
19+
public override bool Equals(object obj) => Equals((obj as IObjectId)!);
2020
public override int GetHashCode() => equalityHelper.GetHashCode(this);
21+
public override string ToString() => ToString(7);
2122
public static implicit operator LibGit2Sharp.ObjectId(ObjectId d) => d.innerObjectId;
2223
public string Sha => innerObjectId.Sha;
2324

src/GitVersion.LibGit2Sharp/Git/Reference.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace GitVersion
55
{
66
internal sealed class Reference : IReference
77
{
8-
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.CanonicalName);
9-
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.CanonicalName);
8+
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.Canonical);
9+
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.Canonical);
1010

1111
internal readonly LibGit2Sharp.Reference innerReference;
1212
private DirectReference directReference => innerReference.ResolveToDirectReference();
@@ -21,6 +21,7 @@ internal Reference(LibGit2Sharp.Reference reference)
2121
public override bool Equals(object obj) => Equals((obj as IReference)!);
2222
public bool Equals(IReference other) => equalityHelper.Equals(this, other);
2323
public override int GetHashCode() => equalityHelper.GetHashCode(this);
24+
public override string ToString() => Name.ToString();
2425
public string TargetIdentifier => innerReference.TargetIdentifier;
2526
public string DirectReferenceTargetIdentifier => directReference.TargetIdentifier;
2627
public IObjectId DirectReferenceTargetId => new ObjectId(directReference.Target.Id);

src/GitVersion.LibGit2Sharp/Git/Remote.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ internal sealed class Remote : IRemote
1313
internal Remote(LibGit2Sharp.Remote remote) => innerRemote = remote;
1414

1515
public int CompareTo(IRemote other) => comparerHelper.Compare(this, other);
16-
public override bool Equals(object obj) => Equals((obj as IRemote)!);
1716
public bool Equals(IRemote other) => equalityHelper.Equals(this, other);
17+
public override bool Equals(object obj) => Equals((obj as IRemote)!);
1818
public override int GetHashCode() => equalityHelper.GetHashCode(this);
19+
public override string ToString() => Name;
1920
public string Name => innerRemote.Name;
2021
public string RefSpecs => string.Join(", ", innerRemote.FetchRefSpecs.Select(r => r.Specification));
2122
}

src/GitVersion.LibGit2Sharp/Git/Tag.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace GitVersion
55
{
66
internal sealed class Tag : ITag
77
{
8-
private static readonly LambdaEqualityHelper<ITag> equalityHelper = new(x => x.Name.CanonicalName);
9-
private static readonly LambdaKeyComparer<ITag, string> comparerHelper = new(x => x.Name.CanonicalName);
8+
private static readonly LambdaEqualityHelper<ITag> equalityHelper = new(x => x.Name.Canonical);
9+
private static readonly LambdaKeyComparer<ITag, string> comparerHelper = new(x => x.Name.Canonical);
1010

1111
private readonly LibGit2Sharp.Tag innerTag;
1212
internal Tag(LibGit2Sharp.Tag tag)
@@ -17,9 +17,10 @@ internal Tag(LibGit2Sharp.Tag tag)
1717
public ReferenceName Name { get; }
1818

1919
public int CompareTo(ITag other) => comparerHelper.Compare(this, other);
20-
public override bool Equals(object obj) => Equals((obj as ITag)!);
2120
public bool Equals(ITag other) => equalityHelper.Equals(this, other);
21+
public override bool Equals(object obj) => Equals((obj as ITag)!);
2222
public override int GetHashCode() => equalityHelper.GetHashCode(this);
23+
public override string ToString() => Name.ToString();
2324
public string TargetSha => innerTag.Target.Sha;
2425

2526
public ICommit? PeeledTargetCommit()

src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(IGitRepository repo,
4747

4848
var repoTipId = repoTip.Id;
4949

50-
if (repo.Branches.All(b => !b.Name.CanonicalName.IsEquivalentTo(localCanonicalName)))
50+
if (repo.Branches.All(b => !b.Name.Canonical.IsEquivalentTo(localCanonicalName)))
5151
{
5252
log.Info(isBranch ? $"Creating local branch {localCanonicalName}"
5353
: $"Creating local branch {localCanonicalName} pointing at {repoTipId}");
@@ -91,7 +91,7 @@ private static IRemote MockRemote(IGitRepository repository)
9191
branch.Name.Returns(new ReferenceName("refs/heads/feature/feat-test"));
9292

9393
var branches = Substitute.For<IBranchCollection>();
94-
branches[branch.Name.CanonicalName].Returns(branch);
94+
branches[branch.Name.Canonical].Returns(branch);
9595
branches.GetEnumerator().Returns(_ => ((IEnumerable<IBranch>)new[] { branch }).GetEnumerator());
9696

9797
var reference = Substitute.For<IReference>();

src/GitVersionCore.Tests/Extensions/GitToolsTestingExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static IBranch CreateMockBranch(string name, params ICommit[] commits)
5555

5656
public static IBranch FindBranch(this IGitRepository repository, string branchName)
5757
{
58-
return repository.Branches.FirstOrDefault(x => x.Name.NameWithoutRemote == branchName);
58+
return repository.Branches.FirstOrDefault(x => x.Name.WithoutRemote == branchName);
5959
}
6060

6161
public static void DumpGraph(this IGitRepository repository, Action<string> writer = null, int? maxCommits = null)

src/GitVersionCore.Tests/Model/GitVersionContextTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
146146
mockRepository.Head.Returns(releaseLatestBranch);
147147
mockRepository.Commits.Returns(releaseLatestBranch.Commits);
148148

149-
var latestContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseLatestBranch.Name.CanonicalName, config);
149+
var latestContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseLatestBranch.Name.Canonical, config);
150150
latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);
151151

152152
mockRepository.Head.Returns(releaseVersionBranch);
153-
var versionContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseVersionBranch.Name.CanonicalName, config);
153+
var versionContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseVersionBranch.Name.Canonical, config);
154154
versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
155155
}
156156

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public BranchConfigurationCalculator(ILog log, IRepositoryMetadataProvider repos
2727
/// </summary>
2828
public BranchConfig GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList<IBranch> excludedInheritBranches = null)
2929
{
30-
var matchingBranches = configuration.GetConfigForBranch(targetBranch.Name.NameWithoutRemote);
30+
var matchingBranches = configuration.GetConfigForBranch(targetBranch.Name.WithoutRemote);
3131

3232
if (matchingBranches == null)
3333
{
34-
log.Info($"No branch configuration found for branch {targetBranch.Name.FriendlyName}, falling back to default configuration");
34+
log.Info($"No branch configuration found for branch {targetBranch.Name.Friendly}, falling back to default configuration");
3535

3636
matchingBranches = BranchConfig.CreateDefaultBranchConfig(FallbackConfigName)
3737
.Apply(new BranchConfig
@@ -103,7 +103,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf
103103
}
104104
}
105105

106-
log.Info("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.Name.FriendlyName)));
106+
log.Info("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.Name.Friendly)));
107107

108108
if (possibleParents.Count == 1)
109109
{
@@ -125,7 +125,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf
125125
// if develop exists and master if not
126126
var errorMessage = possibleParents.Count == 0
127127
? "Failed to inherit Increment branch configuration, no branches found."
128-
: "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.Name.FriendlyName));
128+
: "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.Name.Friendly));
129129

130130
var chosenBranch = repositoryMetadataProvider.GetChosenBranch(configuration);
131131
if (chosenBranch == null)
@@ -135,7 +135,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf
135135
throw new InvalidOperationException("Could not find a 'develop' or 'master' branch, neither locally nor remotely.");
136136
}
137137

138-
var branchName = chosenBranch.Name.FriendlyName;
138+
var branchName = chosenBranch.Name.Friendly;
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.
@@ -189,22 +189,22 @@ private IBranch[] CalculateWhenMultipleParents(ICommit currentCommit, ref IBranc
189189
}
190190
else if (branches.Count > 1)
191191
{
192-
currentBranch = branches.FirstOrDefault(b => b.Name.NameWithoutRemote == Config.MasterBranchKey) ?? branches.First();
192+
currentBranch = branches.FirstOrDefault(b => b.Name.WithoutRemote == Config.MasterBranchKey) ?? branches.First();
193193
}
194194
else
195195
{
196196
var possibleTargetBranches = repositoryMetadataProvider.GetBranchesForCommit(parents[0]).ToList();
197197
if (possibleTargetBranches.Count > 1)
198198
{
199-
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name.NameWithoutRemote == Config.MasterBranchKey) ?? possibleTargetBranches.First();
199+
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name.WithoutRemote == Config.MasterBranchKey) ?? possibleTargetBranches.First();
200200
}
201201
else
202202
{
203203
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
204204
}
205205
}
206206

207-
log.Info("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name.FriendlyName + " as base");
207+
log.Info("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name.Friendly + " as base");
208208

209209
return excludedBranches;
210210
}
@@ -216,7 +216,7 @@ private static BranchConfig ChooseMasterOrDevelopIncrementStrategyIfTheChosenBra
216216
BranchConfig masterOrDevelopConfig = null;
217217
var developBranchRegex = config.Branches[Config.DevelopBranchKey].Regex;
218218
var masterBranchRegex = config.Branches[Config.MasterBranchKey].Regex;
219-
if (Regex.IsMatch(chosenBranch.Name.FriendlyName, developBranchRegex, RegexOptions.IgnoreCase))
219+
if (Regex.IsMatch(chosenBranch.Name.Friendly, developBranchRegex, RegexOptions.IgnoreCase))
220220
{
221221
// Normally we would not expect this to happen but for safety we add a check
222222
if (config.Branches[Config.DevelopBranchKey].Increment !=
@@ -228,7 +228,7 @@ private static BranchConfig ChooseMasterOrDevelopIncrementStrategyIfTheChosenBra
228228
};
229229
}
230230
}
231-
else if (Regex.IsMatch(chosenBranch.Name.FriendlyName, masterBranchRegex, RegexOptions.IgnoreCase))
231+
else if (Regex.IsMatch(chosenBranch.Name.Friendly, masterBranchRegex, RegexOptions.IgnoreCase))
232232
{
233233
// Normally we would not expect this to happen but for safety we add a check
234234
if (config.Branches[Config.MasterBranchKey].Increment !=

0 commit comments

Comments
 (0)