MCPcopy Create free account
hub / github.com/libgit2/git2go / TestDescribeCommit

Function TestDescribeCommit

describe_test.go:10–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func 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

Callers

nothing calls this directly

Calls 15

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
DefaultDescribeOptionsFunction · 0.85
checkFatalFunction · 0.85
seedTestRepoFunction · 0.85
checkDescribeNoRefsFoundFunction · 0.85
compareStringsFunction · 0.85
createTestTagFunction · 0.85
updateReadmeFunction · 0.85
LookupCommitMethod · 0.80
DescribeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…