rebase -i: interrupt rebase when "commit --amend" failed during "reword"

"commit --amend" could fail in cases like the user empties the commit message, or pre-commit failed. When it fails, rebase should be interrupted and alert the user, rather than ignoring the error and continue on rebasing. This also gives users a way to gracefully interrupt a "reword" if they decided they actually want to do an "edit", or even "rebase --abort". Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andrew Wong committed Nov 30, 2011 at 10:52 UTC 0becb3e4b94f19358f66ec2f4bbbf89904251bf5
1 file changed +23 -13
git-rebase--interactive.sh
+23 -13
@@ -143,6 +143,21 @@ die_with_patch () {
143 die "$2"
144 }
145
146 +exit_with_patch () {
147 + echo "$1" > "$state_dir"/stopped-sha
148 + make_patch $1
149 + git rev-parse --verify HEAD > "$amend"
150 + warn "You can amend the commit now, with"
151 + warn
152 + warn " git commit --amend"
153 + warn
154 + warn "Once you are satisfied with your changes, run"
155 + warn
156 + warn " git rebase --continue"
157 + warn
158 + exit $2
159 +}
160 +
161 die_abort () {
162 rm -rf "$state_dir"
163 die "$1"
@@ -395,7 +410,13 @@ do_next () {
410 mark_action_done
411 pick_one $sha1 ||
412 die_with_patch $sha1 "Could not apply $sha1... $rest"
398 - git commit --amend --no-post-rewrite
413 + git commit --amend --no-post-rewrite || {
414 + warn "Could not amend commit after successfully picking $sha1... $rest"
415 + warn "This is most likely due to an empty commit message, or the pre-commit hook"
416 + warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
417 + warn "you are able to reword the commit."
418 + exit_with_patch $sha1 1
419 + }
420 record_in_rewritten $sha1
421 ;;
422 edit|e)
@@ -404,19 +425,8 @@ do_next () {
425 mark_action_done
426 pick_one $sha1 ||
427 die_with_patch $sha1 "Could not apply $sha1... $rest"
407 - echo "$sha1" > "$state_dir"/stopped-sha
408 - make_patch $sha1
409 - git rev-parse --verify HEAD > "$amend"
428 warn "Stopped at $sha1... $rest"
411 - warn "You can amend the commit now, with"
412 - warn
413 - warn " git commit --amend"
414 - warn
415 - warn "Once you are satisfied with your changes, run"
416 - warn
417 - warn " git rebase --continue"
418 - warn
419 - exit 0
429 + exit_with_patch $sha1 0
430 ;;
431 squash|s|fixup|f)
432 case "$command" in