git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] pull --rebase: exit early when the working directory is dirty

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 21, 2008, 11:32 UTC
Message-ID
<alpine.DEB.1.00.0805211230290.30431@racer>

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>
---
 git-pull.sh     |    5 +++++
 t/t5520-pull.sh |   18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index bf0c298..9a9e764 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 9484129..997b2db 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
-- 
1.5.5.1.497.ga63a5
Next: Andreas Ericsson
Message 1 of 4 in “pull --rebase: exit early when the working directory is dirty”
  1. pull --rebase: exit early when the working directory is dirtyJohannes Schindelin, May 21, 2008
  2. Andreas EricssonMay 21, 2008
  3. Jan KrügerMay 21, 2008
  4. Geert BoschMay 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.