Skip to content

Commit 7b9f29c

Browse files
committed
Merge branch 'cw/rebase-i-root'
Finishing touches to the "rebase -i --root" (new feature for 1.7.12). * cw/rebase-i-root: rebase -i: handle fixup of root commit correctly
2 parents b00445b + 2147f84 commit 7b9f29c

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

git-rebase--interactive.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,25 +493,28 @@ do_next () {
493493
author_script_content=$(get_author_ident_from_commit HEAD)
494494
echo "$author_script_content" > "$author_script"
495495
eval "$author_script_content"
496-
output git reset --soft HEAD^
497-
pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
496+
if ! pick_one -n $sha1
497+
then
498+
git rev-parse --verify HEAD >"$amend"
499+
die_failed_squash $sha1 "$rest"
500+
fi
498501
case "$(peek_next_command)" in
499502
squash|s|fixup|f)
500503
# This is an intermediate commit; its message will only be
501504
# used in case of trouble. So use the long version:
502-
do_with_author output git commit --no-verify -F "$squash_msg" ||
505+
do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
503506
die_failed_squash $sha1 "$rest"
504507
;;
505508
*)
506509
# This is the final command of this squash/fixup group
507510
if test -f "$fixup_msg"
508511
then
509-
do_with_author git commit --no-verify -F "$fixup_msg" ||
512+
do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
510513
die_failed_squash $sha1 "$rest"
511514
else
512515
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
513516
rm -f "$GIT_DIR"/MERGE_MSG
514-
do_with_author git commit --no-verify -e ||
517+
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
515518
die_failed_squash $sha1 "$rest"
516519
fi
517520
rm -f "$squash_msg" "$fixup_msg"
@@ -748,21 +751,19 @@ In both case, once you're done, continue with:
748751
fi
749752
. "$author_script" ||
750753
die "Error trying to find the author identity to amend commit"
751-
current_head=
752754
if test -f "$amend"
753755
then
754756
current_head=$(git rev-parse --verify HEAD)
755757
test "$current_head" = $(cat "$amend") ||
756758
die "\
757759
You have uncommitted changes in your working tree. Please, commit them
758760
first and then run 'git rebase --continue' again."
759-
git reset --soft HEAD^ ||
760-
die "Cannot rewind the HEAD"
761+
do_with_author git commit --amend --no-verify -F "$msg" -e ||
762+
die "Could not commit staged changes."
763+
else
764+
do_with_author git commit --no-verify -F "$msg" -e ||
765+
die "Could not commit staged changes."
761766
fi
762-
do_with_author git commit --no-verify -F "$msg" -e || {
763-
test -n "$current_head" && git reset --soft $current_head
764-
die "Could not commit staged changes."
765-
}
766767
fi
767768

768769
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"

t/t3404-rebase-interactive.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,4 +903,12 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
903903
git rebase --abort
904904
'
905905

906+
test_expect_success 'rebase -i --root fixup root commit' '
907+
git checkout B &&
908+
FAKE_LINES="1 fixup 2" git rebase -i --root &&
909+
test A = $(git cat-file commit HEAD | sed -ne \$p) &&
910+
test B = $(git show HEAD:file1) &&
911+
test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
912+
'
913+
906914
test_done

0 commit comments

Comments
 (0)