Skip to content

Commit

Permalink
rebase -i: Abort cleanly if new base cannot be checked out
Browse files Browse the repository at this point in the history
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 <icomfort@stanford.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ian Ward Comfort authored and Junio C Hamano committed Jun 11, 2010
1 parent 2543d9b commit b096374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,9 @@ EOF

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

output git checkout $ONTO || die_abort "could not detach HEAD"
git update-ref ORIG_HEAD $HEAD
output git checkout $ONTO && do_rest
do_rest
;;
esac
shift
Expand Down
10 changes: 10 additions & 0 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ test_expect_success 'abort' '
! test -d .git/rebase-merge
'

test_expect_success 'abort with error when new base cannot be checked out' '
git rm --cached file1 &&
git commit -m "remove file in base" &&
test_must_fail git rebase -i master > output 2>&1 &&
grep "Untracked working tree file .file1. would be overwritten" \
output &&
! test -d .git/rebase-merge &&
git reset --hard HEAD^
'

test_expect_success 'retain authorship' '
echo A > file7 &&
git add file7 &&
Expand Down

0 comments on commit b096374

Please sign in to comment.