Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amend: Fix amending HEAD #116

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions revup/amend.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@ 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
continue
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)
Expand Down