(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestDescribeCommit(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | repo := createTestRepo(t) |
| 13 | defer cleanupTestRepo(t, repo) |
| 14 | |
| 15 | describeOpts, err := DefaultDescribeOptions() |
| 16 | checkFatal(t, err) |
| 17 | |
| 18 | formatOpts, err := DefaultDescribeFormatOptions() |
| 19 | checkFatal(t, err) |
| 20 | |
| 21 | commitID, _ := seedTestRepo(t, repo) |
| 22 | |
| 23 | commit, err := repo.LookupCommit(commitID) |
| 24 | checkFatal(t, err) |
| 25 | |
| 26 | // No annotated tags can be used to describe master |
| 27 | _, err = commit.Describe(&describeOpts) |
| 28 | checkDescribeNoRefsFound(t, err) |
| 29 | |
| 30 | // Fallback |
| 31 | fallback := describeOpts |
| 32 | fallback.ShowCommitOidAsFallback = true |
| 33 | result, err := commit.Describe(&fallback) |
| 34 | checkFatal(t, err) |
| 35 | resultStr, err := result.Format(&formatOpts) |
| 36 | checkFatal(t, err) |
| 37 | compareStrings(t, "473bf77", resultStr) |
| 38 | |
| 39 | // Abbreviated |
| 40 | abbreviated := formatOpts |
| 41 | abbreviated.AbbreviatedSize = 2 |
| 42 | result, err = commit.Describe(&fallback) |
| 43 | checkFatal(t, err) |
| 44 | resultStr, err = result.Format(&abbreviated) |
| 45 | checkFatal(t, err) |
| 46 | compareStrings(t, "473b", resultStr) |
| 47 | |
| 48 | createTestTag(t, repo, commit) |
| 49 | |
| 50 | // Exact tag |
| 51 | patternOpts := describeOpts |
| 52 | patternOpts.Pattern = "v[0-9]*" |
| 53 | result, err = commit.Describe(&patternOpts) |
| 54 | checkFatal(t, err) |
| 55 | resultStr, err = result.Format(&formatOpts) |
| 56 | checkFatal(t, err) |
| 57 | compareStrings(t, "v0.0.0", resultStr) |
| 58 | |
| 59 | // Pattern no match |
| 60 | patternOpts.Pattern = "v[1-9]*" |
| 61 | result, err = commit.Describe(&patternOpts) |
| 62 | checkDescribeNoRefsFound(t, err) |
| 63 | |
| 64 | commitID, _ = updateReadme(t, repo, "update1") |
| 65 | commit, err = repo.LookupCommit(commitID) |
| 66 | checkFatal(t, err) |
| 67 |
nothing calls this directly
no test coverage detected
searching dependent graphs…