Skip to contentSkip to conversation

pull: allow dirty tree when rebase.autostash enabled

PATCH Superseded Kevin Daudt 3 participants 16 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pull: allow dirty tree when rebase.autostash enabled

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
git-pull.sh +4 -1
index 0917d0d..6b9e8a3 100755
@@ -239,7 +239,10 @@ test true = "$rebase" && {
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
 	else
-		require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		if [ $(git config --bool --get rebase.autostash || echo false) = "false" ]
+		then
+			require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		fi
 	fi
 	oldremoteref= &&
 	test -n "$curr_branch" &&
t/t5520-pull.sh +17 -0
index 7efd45b..d849a19 100755
@@ -297,6 +297,23 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+
+	test_when_finished "git rm -f file4" && 
+	git checkout to-rebase &&
+	git update-ref refs/remotes/me/copy copy^ &&
+	COPY=$(git rev-parse --verify me/copy) &&
+	git rebase --onto $COPY copy &&
+	test_config branch.to-rebase.remote me &&
+	test_config branch.to-rebase.merge refs/heads/copy &&
+	test_config branch.to-rebase.rebase true &&
+	test_config rebase.autostash true &&
+	echo dirty >> file4 &&
+	git add file4 &&
+	git pull
+
+'
+
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
Signature · 1 line
2.4.2
#1 lore raw

Hi,

Some comments which may not necessarily be correct.

Quoted 6 lines · Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.
---

Missing sign-off.

Quoted 9 lines
 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
git-pull.sh +0 -0
index 0917d0d..6b9e8a3 100755

git-pull.sh test true = "$rebase" && { · line 242

Quoted 5 lines
git-pull.sh +1 -1
@@ -239,7 +239,10 @@ test true = "$rebase" && {
                        die "$(gettext "updating an unborn branch with changes added to the index")"
                fi
        else
-               require_clean_work_tree "pull with rebase" "Please commit or stash them."
+               if [ $(git config --bool --get rebase.autostash || echo false) = "false" ]

"false" doesn't need to be quoted.

Quoted 11 lines
git-pull.sh +3 -0
+               then
+                       require_clean_work_tree "pull with rebase" "Please commit or stash them."
+               fi
        fi
        oldremoteref= &&
        test -n "$curr_branch" &&
t/t5520-pull.sh +0 -0
index 7efd45b..d849a19 100755

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 301

Quoted 5 lines
t/t5520-pull.sh +2 -0
@@ -297,6 +297,23 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+

I know the surrounding old tests use a newline, but I think that all new tests should use the modern style of not having a newline, since t5520 already consists of a mix of old and modern styles anyway.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 302

Quoted 1 line
t/t5520-pull.sh +1 -0
+       test_when_finished "git rm -f file4" &&

There is trailing whitespace here.

Furthermore, git rm -f will fail if "file4" does not exist in the index. Perhaps it should be moved below the "git add" below.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 305

Quoted 3 lines
t/t5520-pull.sh +3 -0
+       git checkout to-rebase &&
+       git update-ref refs/remotes/me/copy copy^ &&
+       COPY=$(git rev-parse --verify me/copy) &&

$COPY is not used anywhere in the test.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 311

Quoted 6 lines
t/t5520-pull.sh +6 -0
+       git rebase --onto $COPY copy &&
+       test_config branch.to-rebase.remote me &&
+       test_config branch.to-rebase.merge refs/heads/copy &&
+       test_config branch.to-rebase.rebase true &&
+       test_config rebase.autostash true &&
+       echo dirty >> file4 &&

file4 does not exist, so we don't need to append to it. I know the above few tests do not adhere to it, but CodingGuidelines says that redirection operators do not have a space after

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 313

Quoted 2 lines
t/t5520-pull.sh +2 -0
+       git add file4 &&
+       git pull

I think we should check for file contents to ensure that git-pull/git-stash/git-rebase is doing its job properly.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 314

Quoted 1 line
t/t5520-pull.sh +1 -0
+

Same as above, no need the newline.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 316

Quoted 2 lines
t/t5520-pull.sh +2 -0
+'
+

With all that said, I wonder if this test, and the test above ("pull --rebase dies early with dirty working directory") could be vastly simplified, since we are not testing if we can handle a rebased upstream.

E.g., my simplified version for the above test would be something like:

    git checkout -f to-rebase &&
    git rebase --onto copy^ copy &&
    test_config rebase.autostash true &&
    echo dirty >file4 &&
    git add file4 &&
    test_when_finished "git rm -f file4" &&
    git pull --rebase . me/copy &&
    test "$(cat file4)" = dirty &&
    test "$(cat file2)" = file

It's still confusing though, because we cannot take advantage of the 'before-rebase' tag introduced in the above tests. I would much prefer if this test and the ("pull --rebase dies with dirty working directory") test could be moved to the --rebase tests at lines 214+. Also, this section in the t5520 test suite always gives me a headache trying to decipher what it is trying to do ><

Thanks,
Paul

#2 lore raw

PATCH v2 1/2 t5520-pull: Simplify --rebase with dirty tree test

In reply to Kevin Daudt

Simplify the test case for testing git aborts the pull --rebase when the work tree is dirty.

---
This is a preparation for the next pathch.

Changes since v1:
- Moved the tests just belof the first --rebase test
- Simplified both tests to only test if the rebase either succeded for failed

 t/t5520-pull.sh | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)
t/t5520-pull.sh +13 -19
index 7efd45b..925ad49 100755
@@ -122,6 +122,19 @@ test_expect_success '--rebase' '
 	test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
 	test new = $(git show HEAD:file2)
 '
+
+test_expect_success 'pull --rebase dies early with dirty working directory' '
+	git reset --hard before-rebase &&
+	before=$(git rev-parse --verify before-rebase) &&
+	test_config branch.to-rebase.rebase true &&
+	echo dirty >>file &&
+	cp file expect &&
+	git add file &&
+	test_must_fail git pull . copy &&
+	test $(git rev-parse --verify to-rebase) = $before &&
+	test_cmp file expect
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
@@ -278,25 +291,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 
 '
 
-test_expect_success 'pull --rebase dies early with dirty working directory' '
-
-	git checkout to-rebase &&
-	git update-ref refs/remotes/me/copy copy^ &&
-	COPY=$(git rev-parse --verify me/copy) &&
-	git rebase --onto $COPY copy &&
-	test_config branch.to-rebase.remote me &&
-	test_config branch.to-rebase.merge refs/heads/copy &&
-	test_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_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
Signature · 1 line
2.4.2
#3 lore raw

PATCH v2 2/2 pull: allow dirty tree when rebase.autostash enabled

From: Kevin Daudt <[email protected]>

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
git-pull.sh +4 -1
index 0917d0d..f0a3b6e 100755
@@ -239,7 +239,10 @@ test true = "$rebase" && {
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
 	else
-		require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		if [ $(git config --bool --get rebase.autostash || echo false) = false ]
+		then
+			require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		fi
 	fi
 	oldremoteref= &&
 	test -n "$curr_branch" &&
t/t5520-pull.sh +12 -0
index 925ad49..d06119f 100755
@@ -135,6 +135,18 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_cmp file expect
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config branch.to-rebase.rebase true &&
+	test_config rebase.autostash true &&
+	git checkout HEAD -- file &&
+	echo dirty > new_file &&
+	git add new_file &&
+	git pull . copy &&
+	test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
+	test $(cat new_file) = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
Signature · 1 line
2.4.2
#4 lore raw
Quoted 9 lines · Kevin Daudt

From: Kevin Daudt <[email protected]>

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

Ehh? The sign-off does not match the author of the patch.

Quoted 27 lines
---
 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
git-pull.sh +4 -1
index 0917d0d..f0a3b6e 100755
@@ -239,7 +239,10 @@ test true = "$rebase" && {
                        die "$(gettext "updating an unborn branch with changes added to the index")"
                fi
        else
-               require_clean_work_tree "pull with rebase" "Please commit or stash them."
+               if [ $(git config --bool --get rebase.autostash || echo false) = false ]
+               then
+                       require_clean_work_tree "pull with rebase" "Please commit or stash them."
+               fi
        fi
        oldremoteref= &&
        test -n "$curr_branch" &&
t/t5520-pull.sh +0 -0
index 925ad49..d06119f 100755

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 139

Quoted 5 lines
t/t5520-pull.sh +2 -0
@@ -135,6 +135,18 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
        test_cmp file expect
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+       test_config branch.to-rebase.rebase true &&

Ok, though I wonder why not just a git pull --rebase...

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 141

Quoted 2 lines
t/t5520-pull.sh +2 -0
+       test_config rebase.autostash true &&
+       git checkout HEAD -- file &&

Why not git reset --hard before-rebase? If we don't reset HEAD, then how would we know if we actually did a rebase?

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 142

Quoted 1 line
t/t5520-pull.sh +1 -0
+       echo dirty > new_file &&

style: echo dirty >new_file &&

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 145

Quoted 3 lines
t/t5520-pull.sh +3 -0
+       git add new_file &&
+       git pull . copy &&
+       test $(git rev-parse HEAD^) = $(git rev-parse copy) &&

Okay, although it would be better to use "test_cmp_rev HEAD^ copy" because it prints out the hashes if they are different.

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 146

Quoted 1 line
t/t5520-pull.sh +1 -0
+       test $(cat new_file) = dirty &&

"$(cat new_file)" should be quoted to prevent field splitting.

Quoted 8 lines
t/t5520-pull.sh +3 -1
+       test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
        git reset --hard before-rebase &&
        test_config pull.rebase true &&
--

2.4.2

Thanks,
Paul

#5 lore raw
Quoted 6 lines · Paul Tan
Quoted 3 lines · Kevin Daudt

From: Kevin Daudt <[email protected]>

Ehh? The sign-off does not match the author of the patch.

I changed it, but aparently forgot to reset the author for that commit

Quoted 7 lines

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 139

Quoted 5 lines

'

t/t5520-pull.sh +2 -0
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+       test_config branch.to-rebase.rebase true &&

Ok, though I wonder why not just a git pull --rebase...

Copied that from another test, but was doubting whether to use it or not.

Quoted 7 lines

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 141

Quoted 3 lines
t/t5520-pull.sh +2 -0
+       test_config rebase.autostash true &&
+       git checkout HEAD -- file &&

Why not git reset --hard before-rebase? If we don't reset HEAD, then how would we know if we actually did a rebase?

Good tip, thanks.

Quoted 4 lines
Quoted 1 line

+ echo dirty > new_file &&

style: echo dirty >new_file &&

Fixed

Quoted 7 lines

t/t5520-pull.sh test_expect_success 'pull --rebase dies early with dirty working directory' ' · line 145

Quoted 3 lines
t/t5520-pull.sh +3 -0
+       git add new_file &&
+       git pull . copy &&
+       test $(git rev-parse HEAD^) = $(git rev-parse copy) &&

Okay, although it would be better to use "test_cmp_rev HEAD^ copy" because it prints out the hashes if they are different.

Didn't know about that, and aparently, also not documented. Thanks.

Quoted 4 lines
Quoted 1 line

+ test $(cat new_file) = dirty &&

"$(cat new_file)" should be quoted to prevent field splitting.

Fixed

New patch is coming.

#6 lore raw

PATCH v3 1/1 pull: allow dirty tree when rebase.autostash enabled

In reply to Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
Changes to v2:
- Dropped the change of the existing --rebase test
- Improvements to the test.

Verified that the test fails before the change, and succeeds after the change.

 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
git-pull.sh +4 -1
index 0917d0d..f0a3b6e 100755
@@ -239,7 +239,10 @@ test true = "$rebase" && {
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
 	else
-		require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		if [ $(git config --bool --get rebase.autostash || echo false) = false ]
+		then
+			require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		fi
 	fi
 	oldremoteref= &&
 	test -n "$curr_branch" &&
t/t5520-pull.sh +11 -0
index af31f04..aa247ec 100755
@@ -233,6 +233,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
Signature · 1 line
2.4.3
#7 lore raw
Quoted 24 lines · Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
Changes to v2:
- Dropped the change of the existing --rebase test
- Improvements to the test.

Verified that the test fails before the change, and succeeds after the change.

 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
git-pull.sh +0 -0
index 0917d0d..f0a3b6e 100755

git-pull.sh test true = "$rebase" && { · line 242

Quoted 5 lines
git-pull.sh +1 -1
@@ -239,7 +239,10 @@ test true = "$rebase" && {
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
 	else
-		require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		if [ $(git config --bool --get rebase.autostash || echo false) = false ]

Style (use of []).

Shouldn't you be doing

if ...
then
on an unborn
elif we are not doing autostash
require clean work tree
fi

which does not need unnecessarily deep nesting?

Quoted 28 lines
git-pull.sh +3 -0
+		then
+			require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		fi
 	fi
 	oldremoteref= &&
 	test -n "$curr_branch" &&
t/t5520-pull.sh +11 -0
index af31f04..aa247ec 100755
@@ -233,6 +233,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
#8 lore raw

kd/

Quoted 6 lines · Junio C Hamano

git-pull.sh test true = "$rebase" && { · line 242

Quoted 2 lines · Kevin Daudt
git-pull.sh +1 -1
-		require_clean_work_tree "pull with rebase" "Please commit or stash them."
+		if [ $(git config --bool --get rebase.autostash || echo false) = false ]

Style (use of []).

Fixed it.

Quoted 12 lines

Shouldn't you be doing

if ...
then
on an unborn
elif we are not doing autostash
require clean work tree
fi

which does not need unnecessarily deep nesting?

You are right, much simpler. New patch is underway.

#9 lore raw

PATCH v4 1/1 pull: allow dirty tree when rebase.autostash enabled

In reply to Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
 git-pull.sh     |  3 ++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
git-pull.sh +2 -1
index a814bf6..ff28d3f 100755
@@ -284,7 +284,8 @@ test true = "$rebase" && {
 		then
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
-	else
+	elif test $(git config --bool --get rebase.autostash || echo false) = false
+	then
 		require_clean_work_tree "pull with rebase" "Please commit or stash them."
 	fi
 	oldremoteref= &&
t/t5520-pull.sh +11 -0
index f4a7193..a0013ee 100755
@@ -245,6 +245,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
Signature · 1 line
2.4.5
#10 lore raw
Quoted 9 lines · Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---

I applied it, tried to run today's integration cycle, and then ended up ejecting it from my tree for now, as this seemed to break 5520 when merged to 'pu' X-<.

Well, that is partly expected, as Paul's builtin/pull.c does not know about it (yet).

Quoted 40 lines
 git-pull.sh     |  3 ++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
git-pull.sh +2 -1
index a814bf6..ff28d3f 100755
@@ -284,7 +284,8 @@ test true = "$rebase" && {
 		then
 			die "$(gettext "updating an unborn branch with changes added to the index")"
 		fi
-	else
+	elif test $(git config --bool --get rebase.autostash || echo false) = false
+	then
 		require_clean_work_tree "pull with rebase" "Please commit or stash them."
 	fi
 	oldremoteref= &&
t/t5520-pull.sh +11 -0
index f4a7193..a0013ee 100755
@@ -245,6 +245,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
#11 lore raw

PATCH v5 1/1 pull: allow dirty tree when rebase.autostash enabled

Quoted 12 lines · Junio C Hamano
Quoted 9 lines · Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---

Quoted 6 lines

I applied it, tried to run today's integration cycle, and then ended up ejecting it from my tree for now, as this seemed to break 5520 when merged to 'pu' X-<.

Well, that is partly expected, as Paul's builtin/pull.c does not know about it (yet).

Yeah, sorry about that.

Here's a modified patch for the C code.

Regards,
Paul

--- >8 ---
From: Kevin Daudt <[email protected]>
Date: Sat, 4 Jul 2015 23:42:38 +0200

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
 builtin/pull.c  |  6 +++++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
builtin/pull.c +5 -1
index 722a83c..b7bc1ff 100644
@@ -823,10 +823,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		hashclr(orig_head);
 
 	if (opt_rebase) {
+		int autostash = 0;
+
 		if (is_null_sha1(orig_head) && !is_cache_unborn())
 			die(_("Updating an unborn branch with changes added to the index."));
 
-		die_on_unclean_work_tree(prefix);
+		git_config_get_bool("rebase.autostash", &autostash);
+		if (!autostash)
+			die_on_unclean_work_tree(prefix);
 
 		if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
 			hashclr(rebase_fork_point);
t/t5520-pull.sh +11 -0
index f4a7193..a0013ee 100755
@@ -245,6 +245,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
Signature · 1 line
2.5.0.rc1.21.gbd65f2d.dirty
#12 lore raw
Quoted 89 lines · Paul Tan
Quoted 12 lines · Junio C Hamano
Quoted 9 lines · Kevin Daudt

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---

Quoted 6 lines

I applied it, tried to run today's integration cycle, and then ended up ejecting it from my tree for now, as this seemed to break 5520 when merged to 'pu' X-<.

Well, that is partly expected, as Paul's builtin/pull.c does not know about it (yet).

Yeah, sorry about that.

Here's a modified patch for the C code.

Regards,
Paul

--- >8 ---
From: Kevin Daudt <[email protected]>
Date: Sat, 4 Jul 2015 23:42:38 +0200

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.

---
 builtin/pull.c  |  6 +++++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
builtin/pull.c +5 -1
index 722a83c..b7bc1ff 100644
@@ -823,10 +823,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		hashclr(orig_head);
 
 	if (opt_rebase) {
+		int autostash = 0;
+
 		if (is_null_sha1(orig_head) && !is_cache_unborn())
 			die(_("Updating an unborn branch with changes added to the index."));
 
-		die_on_unclean_work_tree(prefix);
+		git_config_get_bool("rebase.autostash", &autostash);
+		if (!autostash)
+			die_on_unclean_work_tree(prefix);
 
 		if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
 			hashclr(rebase_fork_point);
t/t5520-pull.sh +11 -0
index f4a7193..a0013ee 100755
@@ -245,6 +245,17 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
Signature · 1 line
2.5.0.rc1.21.gbd65f2d.dirty

Any news about this? Is it still waiting for something?

#13 lore raw
Quoted 3 lines · Kevin Daudt

On Tue, Jul 07, 2015 at 11:59:56AM +0800, Paul Tan wrote:

Any news about this? Is it still waiting for something?

Paul's patch was buried in the noise and I didn't notice it.

I'd prefer to see a new feature like this, that did not exist in the original, be done on top of the "rewrite pull in C" topic, which will need a bit more time to mature and be merged to 'master'.

Thanks.

#14 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Kevin Daudt

On Tue, Jul 07, 2015 at 11:59:56AM +0800, Paul Tan wrote:

Any news about this? Is it still waiting for something?

Quoted 7 lines

Paul's patch was buried in the noise and I didn't notice it.

I'd prefer to see a new feature like this, that did not exist in the original, be done on top of the "rewrite pull in C" topic, which will need a bit more time to mature and be merged to 'master'.

Thanks.

Ok, no problem.

#15 lore raw

Re: [PATCH v2 1/2] t5520-pull: Simplify --rebase with dirty tree test

In reply to Kevin Daudt
Quoted 12 lines · Kevin Daudt
t/t5520-pull.sh +0 -8
@@ -278,25 +291,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 
 '
 
-test_expect_success 'pull --rebase dies early with dirty working directory' '
-
-       git checkout to-rebase &&
-       git update-ref refs/remotes/me/copy copy^ &&
-       COPY=$(git rev-parse --verify me/copy) &&
-       git rebase --onto $COPY copy &&
-       test_config branch.to-rebase.remote me &&
-       test_config branch.to-rebase.merge refs/heads/copy &&

t/t5520-pull.sh test_expect_success 'rebased upstream + fetch + pull --rebase' ' · line 298

Quoted 10 lines
t/t5520-pull.sh +0 -10
-       test_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)
-
-'

Eh whoops, I don't think we should touch this test. It comes from f9189cf, which states that:

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.

Which makes me believe that "die-ing early with dirty working directory" has something to do with the rebased upstream handling feature of git-pull, and so this test is correct in testing that, and thus we should not touch it.

The location of the test in the other patch is fine though.

Thanks,
Paul