Skip to content

Commit b096374

Browse files
icomfortgitster
authored andcommitted
rebase -i: Abort cleanly if new base cannot be checked out
Untracked content in the working tree may prevent rebase -i from checking out the new base onto which it wants to replay commits, if the new base commit includes files at those (now untracked) paths. Currently, rebase -i dies uncleanly in this situation, updating ORIG_HEAD and leaving a useless .git/rebase-merge directory, with which the user can do nothing useful except rebase --abort. Make rebase -i abort the procedure itself instead, as non-interactive rebase already does, and add a test for this behavior. Signed-off-by: Ian Ward Comfort <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2543d9b commit b096374

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

git-rebase--interactive.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,9 @@ EOF
974974

975975
test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
976976

977+
output git checkout $ONTO || die_abort "could not detach HEAD"
977978
git update-ref ORIG_HEAD $HEAD
978-
output git checkout $ONTO && do_rest
979+
do_rest
979980
;;
980981
esac
981982
shift

t/t3404-rebase-interactive.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ test_expect_success 'abort' '
146146
! test -d .git/rebase-merge
147147
'
148148

149+
test_expect_success 'abort with error when new base cannot be checked out' '
150+
git rm --cached file1 &&
151+
git commit -m "remove file in base" &&
152+
test_must_fail git rebase -i master > output 2>&1 &&
153+
grep "Untracked working tree file .file1. would be overwritten" \
154+
output &&
155+
! test -d .git/rebase-merge &&
156+
git reset --hard HEAD^
157+
'
158+
149159
test_expect_success 'retain authorship' '
150160
echo A > file7 &&
151161
git add file7 &&

0 commit comments

Comments
 (0)