Skip to content

Commit

Permalink
pull --rebase: exit early when the working directory is dirty
Browse files Browse the repository at this point in the history
When rebasing fails during "pull --rebase", you cannot just clean up the
working directory and call "pull --rebase" again, since the remote branch
was already fetched.

Therefore, die early when the working directory is dirty.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed May 23, 2008
1 parent dee2775 commit f9189cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions git-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ error_on_no_merge_candidates () {
}

test true = "$rebase" && {
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --cached --quiet HEAD -- ||
die "refusing to pull with rebase: your working tree is not up-to-date"

. git-parse-remote &&
origin="$1"
test -z "$origin" && origin=$(get_default_remote)
Expand Down
18 changes: 18 additions & 0 deletions t/t5520-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,22 @@ test_expect_success '--rebase with rebased upstream' '
'

test_expect_success 'pull --rebase dies early with dirty working directory' '
git update-ref refs/remotes/me/copy copy^ &&
COPY=$(git rev-parse --verify me/copy) &&
git rebase --onto $COPY copy &&
git config branch.to-rebase.remote me &&
git config branch.to-rebase.merge refs/heads/copy &&
git config branch.to-rebase.rebase true &&
echo dirty >> file &&
git add file &&
test_must_fail git pull &&
test $COPY = $(git rev-parse --verify me/copy) &&
git checkout HEAD -- file &&
git pull &&
test $COPY != $(git rev-parse --verify me/copy)
'

test_done

0 comments on commit f9189cf

Please sign in to comment.