MCPcopy Create free account
hub / github.com/go-git/go-git / TestCommitAmend

Method TestCommitAmend

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

Source from the content-addressed store, hash-verified

114}
115
116func (s *WorktreeSuite) TestCommitAmend(c *C) {
117 fs := memfs.New()
118 w := &Worktree{
119 r: s.Repository,
120 Filesystem: fs,
121 }
122
123 err := w.Checkout(&CheckoutOptions{})
124 c.Assert(err, IsNil)
125
126 util.WriteFile(fs, "foo", []byte("foo"), 0644)
127
128 _, err = w.Add("foo")
129 c.Assert(err, IsNil)
130
131 _, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature()})
132 c.Assert(err, IsNil)
133
134 util.WriteFile(fs, "bar", []byte("bar"), 0644)
135
136 _, err = w.Add("bar")
137 c.Assert(err, IsNil)
138
139 amendedHash, err := w.Commit("bar\n", &CommitOptions{Amend: true})
140 c.Assert(err, IsNil)
141
142 headRef, err := w.r.Head()
143 c.Assert(err, IsNil)
144
145 c.Assert(amendedHash, Equals, headRef.Hash())
146
147 commit, err := w.r.CommitObject(headRef.Hash())
148 c.Assert(err, IsNil)
149 c.Assert(commit.Message, Equals, "bar\n")
150 c.Assert(commit.NumParents(), Equals, 1)
151
152 stats, err := commit.Stats()
153 c.Assert(err, IsNil)
154 c.Assert(stats, HasLen, 2)
155 c.Assert(stats[0], Equals, object.FileStat{
156 Name: "bar",
157 Addition: 1,
158 })
159 c.Assert(stats[1], Equals, object.FileStat{
160 Name: "foo",
161 Addition: 1,
162 })
163
164 assertStorageStatus(c, s.Repository, 14, 12, 11, amendedHash)
165}
166
167func (s *WorktreeSuite) TestAddAndCommitWithSkipStatus(c *C) {
168 expected := plumbing.NewHash("375a3808ffde7f129cdd3c8c252fd0fe37cfd13b")

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