MCPcopy Index your code
hub / github.com/go-git/go-git / TestCommitAmendWithChanges

Method TestCommitAmendWithChanges

worktree_commit_test.go:203–252  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

201}
202
203func (s *WorktreeSuite) TestCommitAmendWithChanges(c *C) {
204 fs := memfs.New()
205 w := &Worktree{
206 r: s.Repository,
207 Filesystem: fs,
208 }
209
210 err := w.Checkout(&CheckoutOptions{})
211 c.Assert(err, IsNil)
212
213 util.WriteFile(fs, "foo", []byte("foo"), 0644)
214
215 _, err = w.Add("foo")
216 c.Assert(err, IsNil)
217
218 _, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
219 c.Assert(err, IsNil)
220
221 util.WriteFile(fs, "bar", []byte("bar"), 0644)
222
223 _, err = w.Add("bar")
224 c.Assert(err, IsNil)
225
226 amendedHash, err := w.Commit("bar\n", &CommitOptions{Amend: true})
227 c.Assert(err, IsNil)
228
229 headRef, err := w.r.Head()
230 c.Assert(err, IsNil)
231
232 c.Assert(amendedHash, Equals, headRef.Hash())
233
234 commit, err := w.r.CommitObject(headRef.Hash())
235 c.Assert(err, IsNil)
236 c.Assert(commit.Message, Equals, "bar\n")
237 c.Assert(commit.NumParents(), Equals, 1)
238
239 stats, err := commit.Stats()
240 c.Assert(err, IsNil)
241 c.Assert(stats, HasLen, 2)
242 c.Assert(stats[0], Equals, object.FileStat{
243 Name: "bar",
244 Addition: 1,
245 })
246 c.Assert(stats[1], Equals, object.FileStat{
247 Name: "foo",
248 Addition: 1,
249 })
250
251 assertStorageStatus(c, s.Repository, 14, 12, 11, amendedHash)
252}
253
254func (s *WorktreeSuite) TestCommitAmendNothingToCommit(c *C) {
255 fs := memfs.New()

Callers

nothing calls this directly

Calls 10

CheckoutMethod · 0.95
AddMethod · 0.95
CommitMethod · 0.95
defaultSignatureFunction · 0.85
assertStorageStatusFunction · 0.85
HeadMethod · 0.80
CommitObjectMethod · 0.80
HashMethod · 0.65
NumParentsMethod · 0.65
StatsMethod · 0.45

Tested by

no test coverage detected