Skip to content

Commit b12d3e9

Browse files
moygitster
authored andcommitted
rebase -i: fix post-rewrite hook with failed exec command
Usually, when 'git rebase' stops before completing the rebase, it is to give the user an opportunity to edit a commit (e.g. with the 'edit' command). In such cases, 'git rebase' leaves the sha1 of the commit being rewritten in "$state_dir"/stopped-sha, and subsequent 'git rebase --continue' will call the post-rewrite hook with this sha1 as <old-sha1> argument to the post-rewrite hook. The case of 'git rebase' stopping because of a failed 'exec' command is different: it gives the opportunity to the user to examine or fix the failure, but does not stop saying "here's a commit to edit, use --continue when you're done". So, there's no reason to call the post-rewrite hook for 'exec' commands. If the user did rewrite the commit, it would be with 'git commit --amend' which already called the post-rewrite hook. Fix the behavior to leave no stopped-sha file in case of failed exec command, and teach 'git rebase --continue' to skip record_in_rewritten if no stopped-sha file is found. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d968ca commit b12d3e9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

git-rebase--interactive.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ do_pick () {
486486
}
487487

488488
do_next () {
489-
rm -f "$msg" "$author_script" "$amend" || exit
489+
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
490490
read -r command sha1 rest < "$todo"
491491
case "$command" in
492492
"$comment_char"*|''|noop)
@@ -576,9 +576,6 @@ do_next () {
576576
read -r command rest < "$todo"
577577
mark_action_done
578578
printf 'Executing: %s\n' "$rest"
579-
# "exec" command doesn't take a sha1 in the todo-list.
580-
# => can't just use $sha1 here.
581-
git rev-parse --verify HEAD > "$state_dir"/stopped-sha
582579
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
583580
status=$?
584581
# Run in subshell because require_clean_work_tree can die.
@@ -874,7 +871,10 @@ first and then run 'git rebase --continue' again."
874871
fi
875872
fi
876873

877-
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
874+
if test -r "$state_dir"/stopped-sha
875+
then
876+
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
877+
fi
878878

879879
require_clean_work_tree "rebase"
880880
do_rest

t/t5407-post-rewrite-hook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ EOF
212212
verify_hook_input
213213
'
214214

215-
test_expect_failure 'git rebase -i (exec)' '
215+
test_expect_success 'git rebase -i (exec)' '
216216
git reset --hard D &&
217217
clear_hook_input &&
218218
FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&

0 commit comments

Comments
 (0)