Skip to content

Commit 420bc91

Browse files
committed
Merge pull request #1020 from libgit2/ntk/short
Obsolete ReferenceWrapper.Name in favor of FriendlyName
2 parents 7027de2 + 2b4459b commit 420bc91

12 files changed

+58
-49
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CanCreateBranch(string name)
2626

2727
Branch newBranch = repo.CreateBranch(name, committish);
2828
Assert.NotNull(newBranch);
29-
Assert.Equal(name, newBranch.Name);
29+
Assert.Equal(name, newBranch.FriendlyName);
3030
Assert.Equal("refs/heads/" + name, newBranch.CanonicalName);
3131
Assert.NotNull(newBranch.Tip);
3232
Assert.Equal(committish, newBranch.Tip.Sha);
@@ -36,15 +36,15 @@ public void CanCreateBranch(string name)
3636
// when they're read back:
3737
// - from InlineData: C5-00-6E-00-67-00-73-00-74-00-72-00-F6-00-6D-00
3838
// - from filesystem: 41-00-0A-03-6E-00-67-00-73-00-74-00-72-00-6F-00-08-03-6D-00
39-
Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name.Normalize() == name));
39+
Assert.NotNull(repo.Branches.SingleOrDefault(p => p.FriendlyName.Normalize() == name));
4040

4141
AssertRefLogEntry(repo, newBranch.CanonicalName,
4242
"branch: Created from " + committish,
4343
null,
4444
newBranch.Tip.Id,
4545
Constants.Identity, DateTimeOffset.Now);
4646

47-
repo.Branches.Remove(newBranch.Name);
47+
repo.Branches.Remove(newBranch.FriendlyName);
4848
Assert.Null(repo.Branches[name]);
4949
}
5050
}
@@ -122,12 +122,12 @@ public void CanCreateBranchFromImplicitHead(string headCommitOrBranchSpec)
122122
const string name = "unit_test";
123123
Branch newBranch = repo.CreateBranch(name);
124124
Assert.NotNull(newBranch);
125-
Assert.Equal(name, newBranch.Name);
125+
Assert.Equal(name, newBranch.FriendlyName);
126126
Assert.Equal("refs/heads/" + name, newBranch.CanonicalName);
127127
Assert.False(newBranch.IsCurrentRepositoryHead);
128128
Assert.NotNull(newBranch.Tip);
129129
Assert.Equal("32eab9cb1f450b5fe7ab663462b77d7f4b703344", newBranch.Tip.Sha);
130-
Assert.NotNull(repo.Branches.SingleOrDefault(p => p.Name == name));
130+
Assert.NotNull(repo.Branches.SingleOrDefault(p => p.FriendlyName == name));
131131

132132
AssertRefLogEntry(repo, newBranch.CanonicalName,
133133
"branch: Created from " + headCommitOrBranchSpec,
@@ -303,7 +303,7 @@ public void CanListAllBranches()
303303
string path = SandboxBareTestRepo();
304304
using (var repo = new Repository(path))
305305
{
306-
Assert.Equal(expectedBranches, SortedBranches(repo.Branches, b => b.Name));
306+
Assert.Equal(expectedBranches, SortedBranches(repo.Branches, b => b.FriendlyName));
307307

308308
Assert.Equal(5, repo.Branches.Count());
309309
}
@@ -324,7 +324,7 @@ public void CanListBranchesWithRemoteAndLocalBranchWithSameShortName()
324324
};
325325

326326
Assert.Equal(expectedWdBranches,
327-
SortedBranches(repo.Branches.Where(b => !b.IsRemote), b => b.Name));
327+
SortedBranches(repo.Branches.Where(b => !b.IsRemote), b => b.FriendlyName));
328328
}
329329
}
330330

@@ -341,7 +341,7 @@ public void CanListAllBranchesWhenGivenWorkingDir()
341341
"origin/test"
342342
};
343343

344-
Assert.Equal(expectedWdBranches, SortedBranches(repo.Branches, b => b.Name));
344+
Assert.Equal(expectedWdBranches, SortedBranches(repo.Branches, b => b.FriendlyName));
345345
}
346346
}
347347

@@ -366,7 +366,7 @@ public void CanListAllBranchesIncludingRemoteRefs()
366366
new { Name = "origin/test", Sha = "e90810b8df3e80c413d903f631643c716887138d", IsRemote = true },
367367
};
368368
Assert.Equal(expectedBranchesIncludingRemoteRefs,
369-
SortedBranches(repo.Branches, b => new { b.Name, b.Tip.Sha, b.IsRemote }));
369+
SortedBranches(repo.Branches, b => new { Name = b.FriendlyName, b.Tip.Sha, b.IsRemote }));
370370
}
371371
}
372372

@@ -483,11 +483,11 @@ public void CanLookupABranchByItsCanonicalName()
483483
{
484484
Branch branch = repo.Branches["refs/heads/br2"];
485485
Assert.NotNull(branch);
486-
Assert.Equal("br2", branch.Name);
486+
Assert.Equal("br2", branch.FriendlyName);
487487

488488
Branch branch2 = repo.Branches["refs/heads/br2"];
489489
Assert.NotNull(branch2);
490-
Assert.Equal("br2", branch2.Name);
490+
Assert.Equal("br2", branch2.FriendlyName);
491491

492492
Assert.Equal(branch, branch2);
493493
Assert.True((branch2 == branch));
@@ -503,7 +503,7 @@ public void CanLookupLocalBranch()
503503
Branch master = repo.Branches["master"];
504504
Assert.NotNull(master);
505505
Assert.False(master.IsRemote);
506-
Assert.Equal("master", master.Name);
506+
Assert.Equal("master", master.FriendlyName);
507507
Assert.Equal("refs/heads/master", master.CanonicalName);
508508
Assert.True(master.IsCurrentRepositoryHead);
509509
Assert.Equal("4c062a6361ae6959e06292c1fa5e2822d9c96345", master.Tip.Sha);
@@ -551,7 +551,7 @@ public void CanGetInformationFromUnbornBranch()
551551
Assert.Equal(0, head.Commits.Count());
552552
Assert.True(head.IsCurrentRepositoryHead);
553553
Assert.False(head.IsRemote);
554-
Assert.Equal("master", head.Name);
554+
Assert.Equal("master", head.FriendlyName);
555555
Assert.Null(head.Tip);
556556
Assert.Null(head["huh?"]);
557557

@@ -916,7 +916,7 @@ public void RemovingABranchWhichIsTheCurrentHeadThrows()
916916
string path = SandboxBareTestRepo();
917917
using (var repo = new Repository(path))
918918
{
919-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Remove(repo.Head.Name));
919+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Remove(repo.Head.FriendlyName));
920920
}
921921
}
922922

@@ -988,7 +988,7 @@ public void CanRenameABranch()
988988

989989
Branch newBranch = repo.Branches.Rename("br2", "br3");
990990

991-
Assert.Equal("br3", newBranch.Name);
991+
Assert.Equal("br3", newBranch.FriendlyName);
992992

993993
Assert.Null(repo.Branches["br2"]);
994994
Assert.NotNull(repo.Branches["br3"]);
@@ -1026,7 +1026,7 @@ public void CanRenameABranchWhileOverwritingAnExistingOne()
10261026
Assert.NotNull(br2);
10271027

10281028
Branch newBranch = repo.Branches.Rename("br2", "test", true);
1029-
Assert.Equal("test", newBranch.Name);
1029+
Assert.Equal("test", newBranch.FriendlyName);
10301030

10311031
Assert.Null(repo.Branches["br2"]);
10321032

@@ -1085,7 +1085,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
10851085
using (var repo = new Repository(clonedRepoPath))
10861086
{
10871087
Assert.Empty(Directory.GetFiles(scd2.RootedDirectoryPath));
1088-
Assert.Equal(repo.Head.Name, "master");
1088+
Assert.Equal(repo.Head.FriendlyName, "master");
10891089

10901090
Assert.Null(repo.Head.Tip);
10911091
Assert.NotNull(repo.Head.TrackedBranch);

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer, bool checkoutByCo
128128

129129
Assert.True(detachedHead.IsCurrentRepositoryHead);
130130
Assert.False(detachedHead.IsRemote);
131-
Assert.Equal(detachedHead.Name, detachedHead.CanonicalName);
131+
Assert.Equal(detachedHead.FriendlyName, detachedHead.CanonicalName);
132132

133133
Assert.Equal("(no branch)", detachedHead.CanonicalName);
134134

@@ -793,7 +793,7 @@ public void CheckoutBranchFromDetachedHead()
793793

794794
// Assert reflog entry is created
795795
AssertRefLogEntry(repo, "HEAD",
796-
string.Format("checkout: moving from {0} to {1}", initialHead.Tip.Sha, newHead.Name),
796+
string.Format("checkout: moving from {0} to {1}", initialHead.Tip.Sha, newHead.FriendlyName),
797797
initialHead.Tip.Id, newHead.Tip.Id, Constants.Identity, DateTimeOffset.Now);
798798
}
799799
}

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void CanClone(string url)
3333
Assert.False(repo.Info.IsBare);
3434

3535
Assert.True(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt")));
36-
Assert.Equal(repo.Head.Name, "master");
36+
Assert.Equal(repo.Head.FriendlyName, "master");
3737
Assert.Equal(repo.Head.Tip.Id.ToString(), "49322bb17d3acc9146f98c97d078513228bbf3c0");
3838
}
3939
}
@@ -52,7 +52,7 @@ public void CanCloneWithCheckoutBranchName(string branchName, string headTipId)
5252
{
5353
var head = repo.Head;
5454

55-
Assert.Equal(branchName, head.Name);
55+
Assert.Equal(branchName, head.FriendlyName);
5656
Assert.True(head.IsTracking);
5757
Assert.Equal(headTipId, head.Tip.Sha);
5858
}

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void ResettingWithBadParamsThrows()
8080
public void SoftResetSetsTheHeadToTheSpecifiedCommit()
8181
{
8282
/* Make the Head point to a branch through its name */
83-
AssertSoftReset(b => b.Name, false, b => b.Name);
83+
AssertSoftReset(b => b.FriendlyName, false, b => b.FriendlyName);
8484
}
8585

8686
[Fact]
@@ -107,12 +107,12 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
107107
Assert.Equal(shouldHeadBeDetached, repo.Info.IsHeadDetached);
108108

109109
string expectedHeadName = expectedHeadNameRetriever(branch);
110-
Assert.Equal(expectedHeadName, repo.Head.Name);
110+
Assert.Equal(expectedHeadName, repo.Head.FriendlyName);
111111
Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha);
112112

113113
/* Reset --soft the Head to a tag through its canonical name */
114114
repo.Reset(ResetMode.Soft, tag.CanonicalName);
115-
Assert.Equal(expectedHeadName, repo.Head.Name);
115+
Assert.Equal(expectedHeadName, repo.Head.FriendlyName);
116116
Assert.Equal(tag.Target.Id, repo.Head.Tip.Id);
117117

118118
Assert.Equal(FileStatus.Staged, repo.RetrieveStatus("a.txt"));
@@ -134,7 +134,7 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
134134

135135
/* Reset --soft the Head to a commit through its sha */
136136
repo.Reset(ResetMode.Soft, branch.Tip.Sha);
137-
Assert.Equal(expectedHeadName, repo.Head.Name);
137+
Assert.Equal(expectedHeadName, repo.Head.FriendlyName);
138138
Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha);
139139

140140
Assert.Equal(FileStatus.Unaltered, repo.RetrieveStatus("a.txt"));

LibGit2Sharp.Tests/TagFixture.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public void CanAddATagWithNameContainingASlash()
106106
Assert.NotNull(lwTag);
107107
Assert.False(lwTag.IsAnnotated);
108108
Assert.Equal(commitE90810BSha, lwTag.Target.Sha);
109-
Assert.Equal(lwTagName, lwTag.Name);
109+
Assert.Equal(lwTagName, lwTag.FriendlyName);
110110

111111
const string anTagName = lwTagName + "_as_well";
112112
Tag anTag = repo.Tags.Add(anTagName, commitE90810BSha, signatureNtk, "a nice message");
113113
Assert.NotNull(anTag);
114114
Assert.True(anTag.IsAnnotated);
115115
Assert.Equal(commitE90810BSha, anTag.Target.Sha);
116116
Assert.Equal(anTag.Target, anTag.Annotation.Target);
117-
Assert.Equal(anTagName, anTag.Name);
117+
Assert.Equal(anTagName, anTag.FriendlyName);
118118
}
119119
}
120120

@@ -371,7 +371,7 @@ public void CanAddATagPointingToATree()
371371
Assert.Equal(tree.Id, tag.Target.Id);
372372

373373
Assert.Equal(tree, repo.Lookup(tag.Target.Id));
374-
Assert.Equal(tag, repo.Tags[tag.Name]);
374+
Assert.Equal(tag, repo.Tags[tag.FriendlyName]);
375375
}
376376
}
377377

@@ -409,7 +409,7 @@ public void CanAddATagPointingToABlob()
409409
Assert.Equal(blob.Id, tag.Target.Id);
410410

411411
Assert.Equal(blob, repo.Lookup(tag.Target.Id));
412-
Assert.Equal(tag, repo.Tags[tag.Name]);
412+
Assert.Equal(tag, repo.Tags[tag.FriendlyName]);
413413
}
414414
}
415415

@@ -429,7 +429,7 @@ public void CreatingALightweightTagPointingToATagAnnotationGeneratesAnAnnotatedT
429429
Assert.Equal(annotation, tag.Annotation);
430430

431431
Assert.Equal(annotation, repo.Lookup(tag.Annotation.Id));
432-
Assert.Equal(tag, repo.Tags[tag.Name]);
432+
Assert.Equal(tag, repo.Tags[tag.FriendlyName]);
433433
}
434434
}
435435

@@ -448,7 +448,7 @@ public void CanAddAnAnnotatedTagPointingToATagAnnotation()
448448
Assert.Equal(annotation.Id, tag.Annotation.Target.Id);
449449
Assert.NotEqual(annotation, tag.Annotation);
450450

451-
Assert.Equal(tag, repo.Tags[tag.Name]);
451+
Assert.Equal(tag, repo.Tags[tag.FriendlyName]);
452452
}
453453
}
454454

@@ -605,12 +605,12 @@ public void RemovingATagDecreasesTheTagsCount()
605605
{
606606
const string tagName = "e90810b";
607607

608-
List<string> tags = repo.Tags.Select(r => r.Name).ToList();
608+
List<string> tags = repo.Tags.Select(r => r.FriendlyName).ToList();
609609
Assert.True(tags.Contains(tagName));
610610

611611
repo.Tags.Remove(tagName);
612612

613-
List<string> tags2 = repo.Tags.Select(r => r.Name).ToList();
613+
List<string> tags2 = repo.Tags.Select(r => r.FriendlyName).ToList();
614614
Assert.False(tags2.Contains(tagName));
615615

616616
Assert.Equal(tags.Count - 1, tags2.Count);
@@ -646,7 +646,7 @@ public void CanListTags()
646646
string path = SandboxBareTestRepo();
647647
using (var repo = new Repository(path))
648648
{
649-
Assert.Equal(expectedTags, SortedTags(repo.Tags, t => t.Name));
649+
Assert.Equal(expectedTags, SortedTags(repo.Tags, t => t.FriendlyName));
650650

651651
Assert.Equal(5, repo.Tags.Count());
652652
}
@@ -673,7 +673,7 @@ public void CanLookupALightweightTag()
673673
{
674674
Tag tag = repo.Tags["lw"];
675675
Assert.NotNull(tag);
676-
Assert.Equal("lw", tag.Name);
676+
Assert.Equal("lw", tag.FriendlyName);
677677
Assert.Equal(commitE90810BSha, tag.Target.Sha);
678678

679679
Assert.False(tag.IsAnnotated);
@@ -689,11 +689,11 @@ public void CanLookupATagByItsCanonicalName()
689689
{
690690
Tag tag = repo.Tags["refs/tags/lw"];
691691
Assert.NotNull(tag);
692-
Assert.Equal("lw", tag.Name);
692+
Assert.Equal("lw", tag.FriendlyName);
693693

694694
Tag tag2 = repo.Tags["refs/tags/lw"];
695695
Assert.NotNull(tag2);
696-
Assert.Equal("lw", tag2.Name);
696+
Assert.Equal("lw", tag2.FriendlyName);
697697

698698
Assert.Equal(tag, tag2);
699699
Assert.True((tag2 == tag));
@@ -708,7 +708,7 @@ public void CanLookupAnAnnotatedTag()
708708
{
709709
Tag tag = repo.Tags["e90810b"];
710710
Assert.NotNull(tag);
711-
Assert.Equal("e90810b", tag.Name);
711+
Assert.Equal("e90810b", tag.FriendlyName);
712712
Assert.Equal(commitE90810BSha, tag.Target.Sha);
713713

714714
Assert.True(tag.IsAnnotated);

LibGit2Sharp/Branch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public virtual Remote Remote
182182

183183
private string UpstreamBranchCanonicalNameFromLocalBranch()
184184
{
185-
ConfigurationEntry<string> mergeRefEntry = repo.Config.Get<string>("branch", Name, "merge");
185+
ConfigurationEntry<string> mergeRefEntry = repo.Config.Get<string>("branch", FriendlyName, "merge");
186186

187187
if (mergeRefEntry == null)
188188
{
@@ -194,7 +194,7 @@ private string UpstreamBranchCanonicalNameFromLocalBranch()
194194

195195
private string RemoteNameFromLocalBranch()
196196
{
197-
ConfigurationEntry<string> remoteEntry = repo.Config.Get<string>("branch", Name, "remote");
197+
ConfigurationEntry<string> remoteEntry = repo.Config.Get<string>("branch", FriendlyName, "remote");
198198

199199
if (remoteEntry == null)
200200
{

LibGit2Sharp/BranchCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite
154154
{
155155
throw new LibGit2SharpException(
156156
string.Format(CultureInfo.InvariantCulture,
157-
"Cannot rename branch '{0}'. It's a remote tracking branch.", branch.Name));
157+
"Cannot rename branch '{0}'. It's a remote tracking branch.", branch.FriendlyName));
158158
}
159159

160-
using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.Name))
160+
using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
161161
{
162162
using (Proxy.git_branch_move(referencePtr, newName, allowOverwrite))
163163
{
@@ -183,7 +183,7 @@ public virtual Branch Update(Branch branch, params Action<BranchUpdater>[] actio
183183
action(updater);
184184
}
185185

186-
return this[branch.Name];
186+
return this[branch.FriendlyName];
187187
}
188188

189189
private static bool LooksLikeABranchName(string referenceName)

LibGit2Sharp/BranchUpdater.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void SetUpstream(string upstreamBranchName)
125125
/// <param name="mergeBranchName">The merge branch in the upstream remote's namespace.</param>
126126
private void SetUpstreamBranch(string mergeBranchName)
127127
{
128-
string configKey = string.Format(CultureInfo.InvariantCulture, "branch.{0}.merge", branch.Name);
128+
string configKey = string.Format(CultureInfo.InvariantCulture, "branch.{0}.merge", branch.FriendlyName);
129129

130130
if (string.IsNullOrEmpty(mergeBranchName))
131131
{
@@ -143,7 +143,7 @@ private void SetUpstreamBranch(string mergeBranchName)
143143
/// <param name="remoteName">The name of the remote to set as the upstream branch.</param>
144144
private void SetUpstreamRemote(string remoteName)
145145
{
146-
string configKey = string.Format(CultureInfo.InvariantCulture, "branch.{0}.remote", branch.Name);
146+
string configKey = string.Format(CultureInfo.InvariantCulture, "branch.{0}.remote", branch.FriendlyName);
147147

148148
if (string.IsNullOrEmpty(remoteName))
149149
{

LibGit2Sharp/NetworkExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void Push(
4646
string.Format(
4747
CultureInfo.InvariantCulture,
4848
"The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
49-
branch.Name, branch.CanonicalName));
49+
branch.FriendlyName, branch.CanonicalName));
5050
}
5151
}
5252

0 commit comments

Comments
 (0)