Skip to content

Commit ffaaed8

Browse files
moygitster
authored andcommitted
rebase -i: clean error message for --continue after failed exec
After an "exec false" stops the rebase and gives the control back to the user, if changes are added to the index, "rebase --continue" fails with this message, which may technically be correct, but does not point at the real problem: .../git-rebase--interactive: line 774: .../.git/rebase-merge/author-script: No such file or directory We could try auto-amending HEAD, but this goes against the logic of .git/rebase-merge/author-script (see also the testcase 'auto-amend only edited commits after "edit"' in t3404-rebase-interactive.sh) to auto-amend something the user hasn't explicitely asked to edit. Instead of doing anything automatically, detect the situation and give a clean error message. While we're there, also clarify the error message in case '. "$author_script"' fails, which now corresponds to really weird senario where the author script exists but can't be read. Test-case-by: Johannes Sixt <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd2b8ae commit ffaaed8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

git-rebase--interactive.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,24 @@ continue)
647647
then
648648
: Nothing to commit -- skip this
649649
else
650+
if ! test -f "$author_script"
651+
then
652+
die "You have staged changes in your working tree. If these changes are meant to be
653+
squashed into the previous commit, run:
654+
655+
git commit --amend
656+
657+
If they are meant to go into a new commit, run:
658+
659+
git commit
660+
661+
In both case, once you're done, continue with:
662+
663+
git rebase --continue
664+
"
665+
fi
650666
. "$author_script" ||
651-
die "Cannot find the author identity"
667+
die "Error trying to find the author identity to amend commit"
652668
current_head=
653669
if test -f "$amend"
654670
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)