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
This commit is contained in:
Junio C Hamano
2012-07-25 15:46:59 -07:00
2 changed files with 21 additions and 12 deletions

View File

@ -493,25 +493,28 @@ do_next () {
author_script_content=$(get_author_ident_from_commit HEAD) author_script_content=$(get_author_ident_from_commit HEAD)
echo "$author_script_content" > "$author_script" echo "$author_script_content" > "$author_script"
eval "$author_script_content" eval "$author_script_content"
output git reset --soft HEAD^ if ! pick_one -n $sha1
pick_one -n $sha1 || die_failed_squash $sha1 "$rest" then
git rev-parse --verify HEAD >"$amend"
die_failed_squash $sha1 "$rest"
fi
case "$(peek_next_command)" in case "$(peek_next_command)" in
squash|s|fixup|f) squash|s|fixup|f)
# This is an intermediate commit; its message will only be # This is an intermediate commit; its message will only be
# used in case of trouble. So use the long version: # used in case of trouble. So use the long version:
do_with_author output git commit --no-verify -F "$squash_msg" || do_with_author output git commit --amend --no-verify -F "$squash_msg" ||
die_failed_squash $sha1 "$rest" die_failed_squash $sha1 "$rest"
;; ;;
*) *)
# This is the final command of this squash/fixup group # This is the final command of this squash/fixup group
if test -f "$fixup_msg" if test -f "$fixup_msg"
then then
do_with_author git commit --no-verify -F "$fixup_msg" || do_with_author git commit --amend --no-verify -F "$fixup_msg" ||
die_failed_squash $sha1 "$rest" die_failed_squash $sha1 "$rest"
else else
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
rm -f "$GIT_DIR"/MERGE_MSG rm -f "$GIT_DIR"/MERGE_MSG
do_with_author git commit --no-verify -e || do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e ||
die_failed_squash $sha1 "$rest" die_failed_squash $sha1 "$rest"
fi fi
rm -f "$squash_msg" "$fixup_msg" rm -f "$squash_msg" "$fixup_msg"
@ -748,7 +751,6 @@ In both case, once you're done, continue with:
fi fi
. "$author_script" || . "$author_script" ||
die "Error trying to find the author identity to amend commit" die "Error trying to find the author identity to amend commit"
current_head=
if test -f "$amend" if test -f "$amend"
then then
current_head=$(git rev-parse --verify HEAD) current_head=$(git rev-parse --verify HEAD)
@ -756,13 +758,12 @@ In both case, once you're done, continue with:
die "\ die "\
You have uncommitted changes in your working tree. Please, commit them You have uncommitted changes in your working tree. Please, commit them
first and then run 'git rebase --continue' again." first and then run 'git rebase --continue' again."
git reset --soft HEAD^ || do_with_author git commit --amend --no-verify -F "$msg" -e ||
die "Cannot rewind the HEAD" die "Could not commit staged changes."
else
do_with_author git commit --no-verify -F "$msg" -e ||
die "Could not commit staged changes."
fi fi
do_with_author git commit --no-verify -F "$msg" -e || {
test -n "$current_head" && git reset --soft $current_head
die "Could not commit staged changes."
}
fi fi
record_in_rewritten "$(cat "$state_dir"/stopped-sha)" record_in_rewritten "$(cat "$state_dir"/stopped-sha)"

View File

@ -903,4 +903,12 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
git rebase --abort git rebase --abort
' '
test_expect_success 'rebase -i --root fixup root commit' '
git checkout B &&
FAKE_LINES="1 fixup 2" git rebase -i --root &&
test A = $(git cat-file commit HEAD | sed -ne \$p) &&
test B = $(git show HEAD:file1) &&
test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
'
test_done test_done