From 9fb13d03c24b00fdc6f3d1930ed87916e431f5af Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Thu, 27 Apr 2023 12:54:43 -0700 Subject: [PATCH] amend: Fix amending HEAD Previous change to amend tried to eliminate a double-call of write-tree, which was both used to elide the final cherrypick as well as make the temp commit that is used for cherry-picking. However it erroneously didn't set the top tree for the len == 1 case which meant that amends of HEAD itself did not actually do any amending. Fix this by writing the tree in the correct line, and pointing the temp commit to that tree. This still manages to avoid a double call to write-tree. Because drop is always false when making the temp commit, we know the tree must have been written earlier. --- revup/amend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/revup/amend.py b/revup/amend.py index 820b5a5..df9ba2b 100644 --- a/revup/amend.py +++ b/revup/amend.py @@ -194,7 +194,8 @@ async def get_has_unstaged() -> bool: if has_diff: new_commit = stack[0].parents[0] - + if not args.drop: + stack[-1].tree = GitTreeHash(await git_ctx.git_stdout("write-tree")) for i, commit_obj in enumerate(stack): if i == 0 and args.drop: # Drop the target commit @@ -202,11 +203,10 @@ async def get_has_unstaged() -> bool: elif i == 0 and len(stack) > 1: # Perform an amend for the first commit, unless there's only one # in which case we can use the tree shortcut. - temp_commit = CommitHeader( - GitTreeHash(await git_ctx.git_stdout("write-tree")), [git.HEAD_COMMIT] - ) + temp_commit = CommitHeader(stack[-1].tree, [git.HEAD_COMMIT]) temp_commit.title = temp_commit.commit_msg = "cached changes" temp_commit.commit_id = await git_ctx.commit_tree(temp_commit) + # drop must be false, so this will be the result of write-tree from above stack[-1].tree = temp_commit.tree try: new_commit = await git_ctx.synthetic_amend(commit_obj, temp_commit)