File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 4
4
using LibGit2Sharp . Core ;
5
5
using LibGit2Sharp . Tests . TestHelpers ;
6
6
using Xunit ;
7
+ using Xunit . Extensions ;
7
8
8
9
namespace LibGit2Sharp . Tests
9
10
{
@@ -740,6 +741,35 @@ public void LookupNullTagNameThrows()
740
741
}
741
742
}
742
743
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
+
743
773
private static T [ ] SortedTags < T > ( IEnumerable < Tag > tags , Func < Tag , T > selector )
744
774
{
745
775
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
40
40
}
41
41
}
42
42
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
+
43
64
/// <summary>
44
65
/// Indicates whether the tag holds any metadata.
45
66
/// </summary>
You can’t perform that action at this time.
0 commit commentsComments 0 (0)