(c *C)
| 201 | } |
| 202 | |
| 203 | func (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 | |
| 254 | func (s *WorktreeSuite) TestCommitAmendNothingToCommit(c *C) { |
| 255 | fs := memfs.New() |
nothing calls this directly
no test coverage detected