diff options
author | Paulo Gomes <pjbgf@linux.com> | 2024-03-10 07:06:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-10 07:06:39 +0000 |
commit | f3113d2e83ca99face9285a117cb6d93951a7406 (patch) | |
tree | 650d9545d9b91739bf0527ab7bfa3afedb8e6c14 /worktree_commit.go | |
parent | d9497bae668afcc540fa6f2177575777b3ff91de (diff) | |
parent | 74febd2e5b2428107a7a4187378bc2567bbb8076 (diff) | |
download | go-git-f3113d2e83ca99face9285a117cb6d93951a7406.tar.gz |
Merge pull request #1045 from onee-only/fix-amend-with-changes
git: worktree_commit, Fix amend commit to apply changes. Fixes #1024
Diffstat (limited to 'worktree_commit.go')
-rw-r--r-- | worktree_commit.go | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/worktree_commit.go b/worktree_commit.go index 7945af1..f62054b 100644 --- a/worktree_commit.go +++ b/worktree_commit.go @@ -45,29 +45,30 @@ func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error if err != nil { return plumbing.ZeroHash, err } - - t, err := w.r.getTreeFromCommitHash(head.Hash()) + headCommit, err := w.r.CommitObject(head.Hash()) if err != nil { return plumbing.ZeroHash, err } - treeHash = t.Hash - opts.Parents = []plumbing.Hash{head.Hash()} - } else { - idx, err := w.r.Storer.Index() - if err != nil { - return plumbing.ZeroHash, err + opts.Parents = nil + if len(headCommit.ParentHashes) != 0 { + opts.Parents = []plumbing.Hash{headCommit.ParentHashes[0]} } + } - h := &buildTreeHelper{ - fs: w.Filesystem, - s: w.r.Storer, - } + idx, err := w.r.Storer.Index() + if err != nil { + return plumbing.ZeroHash, err + } - treeHash, err = h.BuildTree(idx, opts) - if err != nil { - return plumbing.ZeroHash, err - } + h := &buildTreeHelper{ + fs: w.Filesystem, + s: w.r.Storer, + } + + treeHash, err = h.BuildTree(idx, opts) + if err != nil { + return plumbing.ZeroHash, err } commit, err := w.buildCommitObject(msg, opts, treeHash) |