Skip to contentSkip to conversation

Ignore dirty submodule states during stash

PATCH Superseded Vasily Titskiy 3 participants 6 messages Jun 16, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Ignore dirty submodule states during stash

As stash does not know how to deal with submodules, it should not try to save/restore their states as it leads to redundant merge conflicts.

Added test checks if 'stash pop' does not trigger merge conflics in submodules.

---
 git-stash.sh     |  2 +-
 t/t3903-stash.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
git-stash.sh +1 -1
index c7c65e2..b500c44 100755
@@ -116,7 +116,7 @@ create_stash () {
 			git read-tree --index-output="$TMPindex" -m $i_tree &&
 			GIT_INDEX_FILE="$TMPindex" &&
 			export GIT_INDEX_FILE &&
-			git diff --name-only -z HEAD -- >"$TMP-stagenames" &&
+			git diff --name-only --ignore-submodules -z HEAD -- >"$TMP-stagenames" &&
 			git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
 			git write-tree &&
 			rm -f "$TMPindex"
t/t3903-stash.sh +34 -0
index 2142c1f..1be62f3 100755
@@ -731,4 +731,38 @@ test_expect_success 'stash list --cc shows combined diff' '
 	test_cmp expect actual
 '
 
+test_expect_success 'stash ignores changes in submodules' '
+	git submodule init &&
+	git init sub1 &&
+	(
+		cd sub1 &&
+		echo "x" >file1 &&
+		git add file1 &&
+		git commit -a -m "initial sub1"
+	) &&
+	git submodule add ./. sub1 &&
+	echo "main" >file1 &&
+	git add file1 &&
+	git commit -a -m "initial main" &&
+	# make changes in submodule
+	(
+		cd sub1 &&
+		echo "y" >>file1 &&
+		git commit -a -m "change y"
+	) &&
+	git commit sub1 -m "update reference" &&
+	# switch submodule to another revision
+	(
+		cd sub1 &&
+		echo "z" >>file1 &&
+		git commit -a -m "change z"
+	) &&
+	# everything is prepared, check if changes in submodules are ignored
+	echo "local change" >>file1 &&
+	git stash save &&
+	git checkout HEAD~1 &&
+	git submodule update &&
+	git stash pop
+'
+
 test_done
Signature · 1 line
2.1.4
#1 lore raw

t/t3903-stash.sh test_expect_success 'stash list --cc shows combined diff' ' · line 735

Quoted 10 lines · Vasily Titskiy
t/t3903-stash.sh +2 -0
index 2142c1f..1be62f3 100755
@@ -731,4 +731,38 @@ test_expect_success 'stash list --cc shows combined diff' '
 	test_cmp expect actual
 '
 
+test_expect_success 'stash ignores changes in submodules' '
+	git submodule init &&

Hmmmm... what is this "submodule init" needed for at this point in the test sequence?

Quoted 33 lines
t/t3903-stash.sh +32 -0
+	git init sub1 &&
+	(
+		cd sub1 &&
+		echo "x" >file1 &&
+		git add file1 &&
+		git commit -a -m "initial sub1"
+	) &&
+	git submodule add ./. sub1 &&
+	echo "main" >file1 &&
+	git add file1 &&
+	git commit -a -m "initial main" &&
+	# make changes in submodule
+	(
+		cd sub1 &&
+		echo "y" >>file1 &&
+		git commit -a -m "change y"
+	) &&
+	git commit sub1 -m "update reference" &&
+	# switch submodule to another revision
+	(
+		cd sub1 &&
+		echo "z" >>file1 &&
+		git commit -a -m "change z"
+	) &&
+	# everything is prepared, check if changes in submodules are ignored
+	echo "local change" >>file1 &&
+	git stash save &&
+	git checkout HEAD~1 &&
+	git submodule update &&
+	git stash pop
+'
+
 test_done
#2 lore raw

Hi Junio,

You're right, it's redundant here. Should I resubmit the path without this line?

--
Regards,
Vasily Titskiy

Quoted 50 lines · Junio C Hamano

t/t3903-stash.sh test_expect_success 'stash list --cc shows combined diff' ' · line 735

Quoted 10 lines · Vasily Titskiy
t/t3903-stash.sh +2 -0
index 2142c1f..1be62f3 100755
@@ -731,4 +731,38 @@ test_expect_success 'stash list --cc shows combined diff' '
      test_cmp expect actual
 '
 
+test_expect_success 'stash ignores changes in submodules' '
+     git submodule init &&

Hmmmm... what is this "submodule init" needed for at this point in the test sequence?

Quoted 33 lines
t/t3903-stash.sh +32 -0
+     git init sub1 &&
+     (
+             cd sub1 &&
+             echo "x" >file1 &&
+             git add file1 &&
+             git commit -a -m "initial sub1"
+     ) &&
+     git submodule add ./. sub1 &&
+     echo "main" >file1 &&
+     git add file1 &&
+     git commit -a -m "initial main" &&
+     # make changes in submodule
+     (
+             cd sub1 &&
+             echo "y" >>file1 &&
+             git commit -a -m "change y"
+     ) &&
+     git commit sub1 -m "update reference" &&
+     # switch submodule to another revision
+     (
+             cd sub1 &&
+             echo "z" >>file1 &&
+             git commit -a -m "change z"
+     ) &&
+     # everything is prepared, check if changes in submodules are ignored
+     echo "local change" >>file1 &&
+     git stash save &&
+     git checkout HEAD~1 &&
+     git submodule update &&
+     git stash pop
+'
+
 test_done
#3 lore raw
Quoted 1 line · Vasily Titskiy

You're right, it's redundant here. Should I resubmit the path without this line?

I wasn't pointing out that it was not needed. I was only asking what it was meant to do.

If you now think it shouldn't have been there, that merely means your code was wrong. It does not mean I'm right ;-)

With that line removed, would the patch now becomes right? Are there other bugs?

#4 lore raw

The command does nothing, so it's not needed. There is also a typo in my patch description, so I'll resend it again with needed changes. --
Regards,
Vasily Titskiy

Quoted 12 lines · Junio C Hamano
Quoted 1 line · Vasily Titskiy

You're right, it's redundant here. Should I resubmit the path without this line?

I wasn't pointing out that it was not needed. I was only asking what it was meant to do.

If you now think it shouldn't have been there, that merely means your code was wrong. It does not mean I'm right ;-)

With that line removed, would the patch now becomes right? Are there other bugs?