From f9189cf8f2427b10a40b5b3e530e2c893bc64ae9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 21 May 2008 12:32:16 +0100 Subject: [PATCH] pull --rebase: exit early when the working directory is dirty 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 Signed-off-by: Junio C Hamano --- git-pull.sh | 5 +++++ t/t5520-pull.sh | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/git-pull.sh b/git-pull.sh index bf0c2985a..809e537a4 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -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) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 9484129ca..997b2db82 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -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 -- 2.26.2