Skip to content

Commit 0becb3e

Browse files
andrewkwwgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e501a7 commit 0becb3e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

git-rebase--interactive.sh

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ die_with_patch () {
143143
die "$2"
144144
}
145145

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+
146161
die_abort () {
147162
rm -rf "$state_dir"
148163
die "$1"
@@ -395,7 +410,13 @@ do_next () {
395410
mark_action_done
396411
pick_one $sha1 ||
397412
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+
}
399420
record_in_rewritten $sha1
400421
;;
401422
edit|e)
@@ -404,19 +425,8 @@ do_next () {
404425
mark_action_done
405426
pick_one $sha1 ||
406427
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"
410428
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
420430
;;
421431
squash|s|fixup|f)
422432
case "$command" in

0 commit comments

Comments
 (0)