diff options
author | John Cai <jcai@gitlab.com> | 2022-01-03 15:40:28 -0500 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-01-03 15:49:31 -0500 |
commit | 5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0 (patch) | |
tree | a310e673d288758403d0e99086cec6f801480d3b /worktree_commit_test.go | |
parent | f0b111ab70e4e90013658b0835929b2083902017 (diff) | |
download | go-git-5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0.tar.gz |
Add Amend option to CommitOptions
Adds an Amend option to CommitOptions that behaves like git --amend.
This change includes modifications to the Validate function to disallow
a Commit call with both Amend and either Parents or All enabled.
Diffstat (limited to 'worktree_commit_test.go')
-rw-r--r-- | worktree_commit_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/worktree_commit_test.go b/worktree_commit_test.go index 097c6e5..547c820 100644 --- a/worktree_commit_test.go +++ b/worktree_commit_test.go @@ -89,6 +89,37 @@ func (s *WorktreeSuite) TestCommitParent(c *C) { assertStorageStatus(c, s.Repository, 13, 11, 10, expected) } +func (s *WorktreeSuite) TestCommitAmend(c *C) { + fs := memfs.New() + w := &Worktree{ + r: s.Repository, + Filesystem: fs, + } + + err := w.Checkout(&CheckoutOptions{}) + c.Assert(err, IsNil) + + util.WriteFile(fs, "foo", []byte("foo"), 0644) + + _, err = w.Add("foo") + c.Assert(err, IsNil) + + _, err = w.Commit("foo\n", &CommitOptions{Author: defaultSignature()}) + c.Assert(err, IsNil) + + + amendedHash, err := w.Commit("bar\n", &CommitOptions{Amend: true}) + c.Assert(err, IsNil) + + headRef, err := w.r.Head() + c.Assert(amendedHash, Equals, headRef.Hash()) + commit, err := w.r.CommitObject(headRef.Hash()) + c.Assert(err, IsNil) + c.Assert(commit.Message, Equals, "bar\n") + + assertStorageStatus(c, s.Repository, 13, 11, 11, amendedHash) +} + func (s *WorktreeSuite) TestCommitAll(c *C) { expected := plumbing.NewHash("aede6f8c9c1c7ec9ca8d287c64b8ed151276fa28") |