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

Function TestCherrypickCommit

cherrypick_test.go:88–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestCherrypickCommit(t *testing.T) {
89 t.Parallel()
90 repo := createTestRepo(t)
91 defer cleanupTestRepo(t, repo)
92
93 c1, _ := seedTestRepo(t, repo)
94 c2, _ := updateReadme(t, repo, content)
95
96 commit1, err := repo.LookupCommit(c1)
97 if err != nil {
98 t.Fatal(err)
99 }
100 commit2, err := repo.LookupCommit(c2)
101 if err != nil {
102 t.Fatal(err)
103 }
104
105 checkout(t, repo, commit1)
106
107 if got := readReadme(t, repo); got == content {
108 t.Fatalf("README = %q, want %q", got, content)
109 }
110
111 opts, err := DefaultCherrypickOptions()
112 if err != nil {
113 t.Fatal(err)
114 }
115
116 idx, err := repo.CherrypickCommit(commit2, commit1, opts)
117 if err != nil {
118 t.Fatal(err)
119 }
120 defer idx.Free()
121
122 // The file is only updated in the index, not in the working directory.
123 if got := readReadme(t, repo); got == content {
124 t.Errorf("README = %q, want %q", got, content)
125 }
126 if got := repo.State(); got != RepositoryStateNone {
127 t.Errorf("repo.State() = %v, want %v", got, RepositoryStateCherrypick)
128 }
129
130 if got := idx.EntryCount(); got != 1 {
131 t.Fatalf("idx.EntryCount() = %v, want %v", got, 1)
132 }
133 entry, err := idx.EntryByIndex(0)
134 if err != nil {
135 t.Fatal(err)
136 }
137 if entry.Path != "README" {
138 t.Errorf("entry.Path = %v, want %v", entry.Path, "README")
139 }
140}

Callers

nothing calls this directly

Calls 13

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
updateReadmeFunction · 0.85
checkoutFunction · 0.85
readReadmeFunction · 0.85
DefaultCherrypickOptionsFunction · 0.85
LookupCommitMethod · 0.80
CherrypickCommitMethod · 0.80
StateMethod · 0.80
FreeMethod · 0.65
EntryCountMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…