Skip to content

Commit f9189cf

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dee2775 commit f9189cf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

git-pull.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ error_on_no_merge_candidates () {
107107
}
108108

109109
test true = "$rebase" && {
110+
git update-index --refresh &&
111+
git diff-files --quiet &&
112+
git diff-index --cached --quiet HEAD -- ||
113+
die "refusing to pull with rebase: your working tree is not up-to-date"
114+
110115
. git-parse-remote &&
111116
origin="$1"
112117
test -z "$origin" && origin=$(get_default_remote)

t/t5520-pull.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,22 @@ test_expect_success '--rebase with rebased upstream' '
9292
9393
'
9494

95+
test_expect_success 'pull --rebase dies early with dirty working directory' '
96+
97+
git update-ref refs/remotes/me/copy copy^ &&
98+
COPY=$(git rev-parse --verify me/copy) &&
99+
git rebase --onto $COPY copy &&
100+
git config branch.to-rebase.remote me &&
101+
git config branch.to-rebase.merge refs/heads/copy &&
102+
git config branch.to-rebase.rebase true &&
103+
echo dirty >> file &&
104+
git add file &&
105+
test_must_fail git pull &&
106+
test $COPY = $(git rev-parse --verify me/copy) &&
107+
git checkout HEAD -- file &&
108+
git pull &&
109+
test $COPY != $(git rev-parse --verify me/copy)
110+
111+
'
112+
95113
test_done

0 commit comments

Comments
 (0)