|
| 1 | +using System.Linq; |
| 2 | +using LibGit2Sharp.Tests.TestHelpers; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace LibGit2Sharp.Tests |
| 6 | +{ |
| 7 | + public class DescribeFixture : BaseFixture |
| 8 | + { |
| 9 | + [Fact] |
| 10 | + public void CanDescribeACommit() |
| 11 | + { |
| 12 | + string path = SandboxBareTestRepo(); |
| 13 | + using (var repo = new Repository(path)) |
| 14 | + { |
| 15 | + // No annotated tags can be used to describe "master" |
| 16 | + var masterTip = repo.Branches["master"].Tip; |
| 17 | + Assert.Throws<NotFoundException>(() => repo.Describe(masterTip)); |
| 18 | + Assert.Equal("4c062a6", repo.Describe(masterTip, |
| 19 | + new DescribeOptions { UseCommitIdAsFallback = true })); |
| 20 | + Assert.Equal("4c06", repo.Describe(masterTip, |
| 21 | + new DescribeOptions { UseCommitIdAsFallback = true, MinimumCommitIdAbbreviatedSize = 2 })); |
| 22 | + |
| 23 | + // No lightweight tags can either be used to describe "master" |
| 24 | + Assert.Throws<NotFoundException>(() => repo.Describe(masterTip, |
| 25 | + new DescribeOptions{ Strategy = DescribeStrategy.Tags })); |
| 26 | + |
| 27 | + repo.ApplyTag("myTag", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); |
| 28 | + Assert.Equal("myTag-5-g4c062a6", repo.Describe(masterTip, |
| 29 | + new DescribeOptions { Strategy = DescribeStrategy.Tags })); |
| 30 | + Assert.Equal("myTag-5-g4c062a636", repo.Describe(masterTip, |
| 31 | + new DescribeOptions { Strategy = DescribeStrategy.Tags, MinimumCommitIdAbbreviatedSize = 9 })); |
| 32 | + Assert.Equal("myTag-4-gbe3563a", repo.Describe(masterTip.Parents.Single(), |
| 33 | + new DescribeOptions { Strategy = DescribeStrategy.Tags })); |
| 34 | + |
| 35 | + Assert.Equal("heads/master", repo.Describe(masterTip, |
| 36 | + new DescribeOptions { Strategy = DescribeStrategy.All })); |
| 37 | + Assert.Equal("heads/packed-test-3-gbe3563a", repo.Describe(masterTip.Parents.Single(), |
| 38 | + new DescribeOptions { Strategy = DescribeStrategy.All })); |
| 39 | + |
| 40 | + // "test" branch points to an annotated tag (also named "test") |
| 41 | + // Let's rename the branch to ease the understanding of what we |
| 42 | + // are exercising. |
| 43 | + |
| 44 | + repo.Branches.Rename(repo.Branches["test"], "ForLackOfABetterName"); |
| 45 | + |
| 46 | + var anotherTip = repo.Branches["ForLackOfABetterName"].Tip; |
| 47 | + Assert.Equal("test", repo.Describe(anotherTip)); |
| 48 | + Assert.Equal("test-0-g7b43849", repo.Describe(anotherTip, |
| 49 | + new DescribeOptions{ AlwaysRenderLongFormat = true })); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments