File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 44using LibGit2Sharp . Core ;
55using LibGit2Sharp . Tests . TestHelpers ;
66using Xunit ;
7+ using Xunit . Extensions ;
78
89namespace LibGit2Sharp . Tests
910{
@@ -740,6 +741,35 @@ public void LookupNullTagNameThrows()
740741 }
741742 }
742743
744+ [ Fact ]
745+ public void CanRetrieveThePeeledTargetOfATagPointingToATag ( )
746+ {
747+ string path = SandboxBareTestRepo ( ) ;
748+ using ( var repo = new Repository ( path ) )
749+ {
750+ Tag tag = repo . Tags [ "test" ] ;
751+
752+ Assert . True ( tag . Target is TagAnnotation ) ;
753+ Assert . True ( tag . PeeledTarget is Commit ) ;
754+ }
755+ }
756+
757+ [ Theory ]
758+ [ InlineData ( "e90810b" ) ]
759+ [ InlineData ( "lw" ) ]
760+ [ InlineData ( "point_to_blob" ) ]
761+ [ InlineData ( "tag_without_tagger" ) ]
762+ public void PeeledTargetAndTargetAreEqualWhenTagIsNotChained ( string tagName )
763+ {
764+ string path = SandboxBareTestRepo ( ) ;
765+ using ( var repo = new Repository ( path ) )
766+ {
767+ Tag tag = repo . Tags [ tagName ] ;
768+
769+ Assert . Equal < GitObject > ( tag . Target , tag . PeeledTarget ) ;
770+ }
771+ }
772+
743773 private static T [ ] SortedTags < T > ( IEnumerable < Tag > tags , Func < Tag , T > selector )
744774 {
745775 return tags . OrderBy ( t => t . CanonicalName , StringComparer . Ordinal ) . Select ( selector ) . ToArray ( ) ;
Original file line number Diff line number Diff line change @@ -40,6 +40,27 @@ public virtual GitObject Target
4040 }
4141 }
4242
43+ /// <summary>
44+ /// Gets the peeled <see cref="GitObject"/> that this tag points to.
45+ /// </summary>
46+ public virtual GitObject PeeledTarget
47+ {
48+ get
49+ {
50+ GitObject target = TargetObject ;
51+
52+ var annotation = target as TagAnnotation ;
53+
54+ while ( annotation != null )
55+ {
56+ target = annotation . Target ;
57+ annotation = target as TagAnnotation ;
58+ }
59+
60+ return target ;
61+ }
62+ }
63+
4364 /// <summary>
4465 /// Indicates whether the tag holds any metadata.
4566 /// </summary>
You can’t perform that action at this time.
0 commit comments