Skip to content

Commit 2c46103

Browse files
committed
Merge branch 'mm/rebase-i-exec-edit'
* mm/rebase-i-exec-edit: rebase -i: notice and warn if "exec $cmd" modifies the index or the working tree rebase -i: clean error message for --continue after failed exec
2 parents 703f05a + 1686519 commit 2c46103

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

git-rebase--interactive.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,18 +472,24 @@ do_next () {
472472
git rev-parse --verify HEAD > "$state_dir"/stopped-sha
473473
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
474474
status=$?
475+
# Run in subshell because require_clean_work_tree can die.
476+
dirty=f
477+
(require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
475478
if test "$status" -ne 0
476479
then
477480
warn "Execution failed: $rest"
481+
test "$dirty" = f ||
482+
warn "and made changes to the index and/or the working tree"
483+
478484
warn "You can fix the problem, and then run"
479485
warn
480486
warn " git rebase --continue"
481487
warn
482488
exit "$status"
483-
fi
484-
# Run in subshell because require_clean_work_tree can die.
485-
if ! (require_clean_work_tree "rebase")
489+
elif test "$dirty" = t
486490
then
491+
warn "Execution succeeded: $rest"
492+
warn "but left changes to the index and/or the working tree"
487493
warn "Commit or stash your changes, and then run"
488494
warn
489495
warn " git rebase --continue"
@@ -647,8 +653,24 @@ continue)
647653
then
648654
: Nothing to commit -- skip this
649655
else
656+
if ! test -f "$author_script"
657+
then
658+
die "You have staged changes in your working tree. If these changes are meant to be
659+
squashed into the previous commit, run:
660+
661+
git commit --amend
662+
663+
If they are meant to go into a new commit, run:
664+
665+
git commit
666+
667+
In both case, once you're done, continue with:
668+
669+
git rebase --continue
670+
"
671+
fi
650672
. "$author_script" ||
651-
die "Cannot find the author identity"
673+
die "Error trying to find the author identity to amend commit"
652674
current_head=
653675
if test -f "$amend"
654676
then

t/t3404-rebase-interactive.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ test_expect_success 'auto-amend only edited commits after "edit"' '
527527
git rebase --abort
528528
'
529529

530+
test_expect_success 'clean error after failed "exec"' '
531+
test_tick &&
532+
test_when_finished "git rebase --abort || :" &&
533+
(
534+
FAKE_LINES="1 exec_false" &&
535+
export FAKE_LINES &&
536+
test_must_fail git rebase -i HEAD^
537+
) &&
538+
echo "edited again" > file7 &&
539+
git add file7 &&
540+
test_must_fail git rebase --continue 2>error &&
541+
grep "You have staged changes in your working tree." error
542+
'
543+
530544
test_expect_success 'rebase a detached HEAD' '
531545
grandparent=$(git rev-parse HEAD~2) &&
532546
git checkout $(git rev-parse HEAD) &&

0 commit comments

Comments
 (0)