git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "D. Ben Knoble" <ben.knoble+github@gmail.com>
To: git@vger.kernel.org
Cc: "D. Ben Knoble" <ben.knoble+github@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	John Cai <johncai86@gmail.com>
Subject: [PATCH 6/9] t3903: adjust stash test to account for --[no-]index with breaking changes
Date: Sat, 10 May 2025 14:33:41 -0400	[thread overview]
Message-ID: <20250510183358.36806-7-ben.knoble+github@gmail.com> (raw)
In-Reply-To: <20250510183358.36806-1-ben.knoble+github@gmail.com>

A few tests check the results of the index after applying a stash; with
breaking changes from previous commits that automatically restore the
stashed index, the expected values are wrong.

A few of the relevant tests check the restoration of <pathspec>s; with
the aforementioned breaking changes, things get more interesting. In
particular, if we "git stash push -- foo" but have "bar" in the index,
then when applying the stash we get a conflict: "bar" was not removed
from the index by the stash, but it was included in the recorded index
in the stash. In those cases, apply the stash with "--no-index" (which
would be the required user behavior).

Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
---

Notes:
    It looks like the pathspec filtering is not applied to the stashed
    index; should it be?

 t/t3903-stash.sh | 158 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 147 insertions(+), 11 deletions(-)

diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index b8936a653b..36e1d3ec08 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -99,7 +99,7 @@ setup_stash()
 	test_cmp expect file
 '
 
-test_expect_success 'apply stashed changes' '
+test_expect_success !WITH_BREAKING_CHANGES 'apply stashed changes' '
 	git reset --hard &&
 	echo 5 >other-file &&
 	git add other-file &&
@@ -111,6 +111,18 @@ setup_stash()
 	test 1 = $(git show HEAD:file)
 '
 
+test_expect_success WITH_BREAKING_CHANGES 'apply stashed changes' '
+	git reset --hard &&
+	echo 5 >other-file &&
+	git add other-file &&
+	test_tick &&
+	git commit -m other-file &&
+	git stash apply &&
+	test 3 = $(cat file) &&
+	test 2 = $(git show :file) &&
+	test 1 = $(git show HEAD:file)
+'
+
 test_expect_success 'apply stashed changes (including index)' '
 	git reset --hard HEAD^ &&
 	echo 6 >other-file &&
@@ -136,7 +148,7 @@ setup_stash()
 	test_must_fail git stash drop --foo
 '
 
-test_expect_success 'drop top stash' '
+test_expect_success !WITH_BREAKING_CHANGES 'drop top stash' '
 	git reset --hard &&
 	git stash list >expected &&
 	echo 7 >file &&
@@ -150,7 +162,21 @@ setup_stash()
 	test 1 = $(git show HEAD:file)
 '
 
-test_expect_success 'drop middle stash' '
+test_expect_success WITH_BREAKING_CHANGES 'drop top stash' '
+	git reset --hard &&
+	git stash list >expected &&
+	echo 7 >file &&
+	git stash &&
+	git stash drop &&
+	git stash list >actual &&
+	test_cmp expected actual &&
+	git stash apply &&
+	test 3 = $(cat file) &&
+	test 2 = $(git show :file) &&
+	test 1 = $(git show HEAD:file)
+'
+
+test_expect_success !WITH_BREAKING_CHANGES 'drop middle stash' '
 	git reset --hard &&
 	echo 8 >file &&
 	git stash &&
@@ -170,7 +196,27 @@ setup_stash()
 	test 1 = $(git show HEAD:file)
 '
 
-test_expect_success 'drop middle stash by index' '
+test_expect_success WITH_BREAKING_CHANGES 'drop middle stash' '
+	git reset --hard &&
+	echo 8 >file &&
+	git stash &&
+	echo 9 >file &&
+	git stash &&
+	git stash drop stash@{1} &&
+	test 2 = $(git stash list | wc -l) &&
+	git stash apply &&
+	test 9 = $(cat file) &&
+	test 1 = $(git show :file) &&
+	test 1 = $(git show HEAD:file) &&
+	git reset --hard &&
+	git stash drop &&
+	git stash apply &&
+	test 3 = $(cat file) &&
+	test 2 = $(git show :file) &&
+	test 1 = $(git show HEAD:file)
+'
+
+test_expect_success !WITH_BREAKING_CHANGES 'drop middle stash by index' '
 	git reset --hard &&
 	echo 8 >file &&
 	git stash &&
@@ -227,7 +273,7 @@ setup_stash()
 	test_cmp expect actual
 '
 
-test_expect_success 'stash pop' '
+test_expect_success !WITH_BREAKING_CHANGES 'stash pop' '
 	git reset --hard &&
 	git stash pop &&
 	test 3 = $(cat file) &&
@@ -236,6 +282,15 @@ setup_stash()
 	test 0 = $(git stash list | wc -l)
 '
 
+test_expect_success WITH_BREAKING_CHANGES 'stash pop' '
+	git reset --hard &&
+	git stash pop &&
+	test 3 = $(cat file) &&
+	test 2 = $(git show :file) &&
+	test 1 = $(git show HEAD:file) &&
+	test 0 = $(git stash list | wc -l)
+'
+
 cat >expect <<EOF
 diff --git a/file2 b/file2
 new file mode 100644
@@ -320,7 +375,7 @@ setup_stash()
 	test_must_be_empty output.out
 '
 
-test_expect_success 'pop -q works and is quiet' '
+test_expect_success !WITH_BREAKING_CHANGES 'pop -q works and is quiet' '
 	git stash pop -q >output.out 2>&1 &&
 	echo bar >expect &&
 	git show :file >actual &&
@@ -328,6 +383,14 @@ setup_stash()
 	test_must_be_empty output.out
 '
 
+test_expect_success WITH_BREAKING_CHANGES 'pop -q works and is quiet' '
+	git stash pop -q >output.out 2>&1 &&
+	echo test >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	test_must_be_empty output.out
+'
+
 test_expect_success 'pop -q --index works and is quiet' '
 	echo foo >file &&
 	git add file &&
@@ -1166,7 +1229,7 @@ setup_stash()
 	test_cmp expect actual
 '
 
-test_expect_success 'stash -- <pathspec> stashes and restores the file' '
+test_expect_success !WITH_BREAKING_CHANGES 'stash -- <pathspec> stashes and restores the file' '
 	>foo &&
 	>bar &&
 	git add foo bar &&
@@ -1178,7 +1241,19 @@ setup_stash()
 	test_path_is_file bar
 '
 
-test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
+test_expect_success WITH_BREAKING_CHANGES 'stash -- <pathspec> stashes and restores the file' '
+	>foo &&
+	>bar &&
+	git add foo bar &&
+	git stash push -- foo &&
+	test_path_is_file bar &&
+	test_path_is_missing foo &&
+	git stash pop --no-index &&
+	test_path_is_file foo &&
+	test_path_is_file bar
+'
+
+test_expect_success !WITH_BREAKING_CHANGES 'stash -- <pathspec> stashes in subdirectory' '
 	mkdir sub &&
 	>foo &&
 	>bar &&
@@ -1194,7 +1269,23 @@ setup_stash()
 	test_path_is_file bar
 '
 
-test_expect_success 'stash with multiple pathspec arguments' '
+test_expect_success WITH_BREAKING_CHANGES 'stash -- <pathspec> stashes in subdirectory' '
+	mkdir sub &&
+	>foo &&
+	>bar &&
+	git add foo bar &&
+	(
+		cd sub &&
+		git stash push -- ../foo
+	) &&
+	test_path_is_file bar &&
+	test_path_is_missing foo &&
+	git stash pop --no-index &&
+	test_path_is_file foo &&
+	test_path_is_file bar
+'
+
+test_expect_success !WITH_BREAKING_CHANGES 'stash with multiple pathspec arguments' '
 	>foo &&
 	>bar &&
 	>extra &&
@@ -1209,7 +1300,22 @@ setup_stash()
 	test_path_is_file extra
 '
 
-test_expect_success 'stash with file including $IFS character' '
+test_expect_success WITH_BREAKING_CHANGES 'stash with multiple pathspec arguments' '
+	>foo &&
+	>bar &&
+	>extra &&
+	git add foo bar extra &&
+	git stash push -- foo bar &&
+	test_path_is_missing bar &&
+	test_path_is_missing foo &&
+	test_path_is_file extra &&
+	git stash pop --no-index &&
+	test_path_is_file foo &&
+	test_path_is_file bar &&
+	test_path_is_file extra
+'
+
+test_expect_success !WITH_BREAKING_CHANGES 'stash with file including $IFS character' '
 	>"foo bar" &&
 	>foo &&
 	>bar &&
@@ -1224,6 +1330,21 @@ setup_stash()
 	test_path_is_file bar
 '
 
+test_expect_success WITH_BREAKING_CHANGES 'stash with file including $IFS character' '
+	>"foo bar" &&
+	>foo &&
+	>bar &&
+	git add foo* &&
+	git stash push -- "foo b*" &&
+	test_path_is_missing "foo bar" &&
+	test_path_is_file foo &&
+	test_path_is_file bar &&
+	git stash pop --no-index &&
+	test_path_is_file "foo bar" &&
+	test_path_is_file foo &&
+	test_path_is_file bar
+'
+
 test_expect_success 'stash with pathspec matching multiple paths' '
 	echo original >file &&
 	echo original >other-file &&
@@ -1297,7 +1418,7 @@ setup_stash()
 	test_path_is_file untracked
 '
 
-test_expect_success 'stash without verb with pathspec' '
+test_expect_success !WITH_BREAKING_CHANGES 'stash without verb with pathspec' '
 	>"foo bar" &&
 	>foo &&
 	>bar &&
@@ -1312,6 +1433,21 @@ setup_stash()
 	test_path_is_file bar
 '
 
+test_expect_success WITH_BREAKING_CHANGES 'stash without verb with pathspec' '
+	>"foo bar" &&
+	>foo &&
+	>bar &&
+	git add foo* &&
+	git stash -- "foo b*" &&
+	test_path_is_missing "foo bar" &&
+	test_path_is_file foo &&
+	test_path_is_file bar &&
+	git stash pop --no-index &&
+	test_path_is_file "foo bar" &&
+	test_path_is_file foo &&
+	test_path_is_file bar
+'
+
 test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
 	git reset &&
 	>foo &&
-- 
2.48.1


  parent reply	other threads:[~2025-05-10 18:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-10 18:33 [PATCH 0/9] make stash apply with --index by default D. Ben Knoble
2025-05-10 18:33 ` [PATCH 1/9] t3903: reduce dependencies on previous tests D. Ben Knoble
2025-05-10 18:33 ` [PATCH 2/9] t3905: remove unneeded blank line D. Ben Knoble
2025-05-10 18:33 ` [PATCH 3/9] BreakingChanges: announce stash {apply,pop} will imply --index D. Ben Knoble
2025-05-10 18:33 ` [PATCH 4/9] stash: restore the index by default when breaking changes are enabled D. Ben Knoble
2025-05-10 18:33 ` [PATCH 5/9] t0450: mark stash documentation as a known discrepancy D. Ben Knoble
2025-05-10 18:33 ` D. Ben Knoble [this message]
2025-05-10 18:33 ` [PATCH 7/9] t3904: adjust stash -p test to account for index states with breaking changes D. Ben Knoble
2025-05-10 18:33 ` [PATCH 8/9] t3905: adjust stash -u tests for " D. Ben Knoble
2025-05-10 18:33 ` [PATCH 9/9] t3906: adjust stash submodule tests to account " D. Ben Knoble
2025-05-12 12:52 ` [PATCH 0/9] make stash apply with --index by default Junio C Hamano
2025-05-20 14:36 ` D. Ben Knoble
2025-05-20 14:39 ` D. Ben Knoble
2025-09-16  0:37 ` [PATCH v2 0/4] Teach git-stash to use --index from config D. Ben Knoble
2025-09-16  0:37   ` [PATCH v2 1/4] t3903: reduce dependencies on previous tests D. Ben Knoble
2025-09-16  0:37   ` [PATCH v2 2/4] t3905: remove unneeded blank line D. Ben Knoble
2025-09-16  0:37   ` [PATCH v2 3/4] stash: refactor private config globals D. Ben Knoble
2025-09-16  0:37   ` [PATCH v2 4/4] stash: honor stash.index in apply, pop modes D. Ben Knoble
2025-09-16  9:18     ` Phillip Wood
2025-09-16 17:07       ` D. Ben Knoble
2025-09-16  9:24   ` [PATCH v2 0/4] Teach git-stash to use --index from config Phillip Wood
2025-09-16 17:06     ` D. Ben Knoble
2025-09-16 16:49   ` Junio C Hamano
2025-09-22  1:39   ` [PATCH v3 " D. Ben Knoble
2025-09-22  1:39     ` [PATCH v3 1/4] t3903: reduce dependencies on previous tests D. Ben Knoble
2025-09-22  1:39     ` [PATCH v3 2/4] t3905: remove unneeded blank line D. Ben Knoble
2025-09-22  1:39     ` [PATCH v3 3/4] stash: refactor private config globals D. Ben Knoble
2025-09-22  1:39     ` [PATCH v3 4/4] stash: honor stash.index in apply, pop modes D. Ben Knoble
2025-09-22 14:11       ` Phillip Wood
2025-09-24 20:40         ` D. Ben Knoble
2025-09-29 10:01           ` Phillip Wood
2025-10-06 12:59             ` [PATCH] doc: explain the impact of stash.index on --autostash options D. Ben Knoble
2025-10-09 22:54               ` Kristoffer Haugsbakk
2025-10-11 14:44                 ` D. Ben Knoble
2025-10-11 17:28                   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250510183358.36806-7-ben.knoble+github@gmail.com \
    --to=ben.knoble+github@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johncai86@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).