diff mbox series

builtin/stash: test push with new file added and removed

Message ID 20240821190921.18772-1-piotrsiupa@gmail.com (mailing list archive)
State New
Headers show
Series builtin/stash: test push with new file added and removed | expand

Commit Message

Piotr Siupa Aug. 21, 2024, 7:09 p.m. UTC
In the scenario when a new file is added to index, then it is deleted
from the workspace, and then a stash is created, the information about
the deletion is lost.
The resulting stash contains the file but not the information that it
was deleted. The file is also back in the workspace after the push.

This commit adds a test for such scenario (as a known breakage).

Signed-off-by: Piotr Siupa <piotrsiupa@gmail.com>
---
 t/t3903-stash.sh | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
diff mbox series

Patch

diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index a7f71f8126..84f0309b3d 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -469,6 +469,37 @@  test_expect_success 'stash rm and ignore (stage .gitignore)' '
 	test file = "$(cat .gitignore)"
 '
 
+test_expect_failure 'stash add and rm' '
+	test_when_finished "rm -rf add_and_rm" &&
+	git init add_and_rm &&
+	(
+		cd add_and_rm &&
+		git commit --allow-empty --message init &&
+
+		# create a stash with "file" ONLY in the index
+		echo content >file &&
+		git add file &&
+		rm file &&
+		git stash &&
+		# no reason for the file to reappear but is will not hurt to check
+		test_path_is_missing file &&
+
+		# apply the stash without "--index"
+		# it should behave as if "file" was not in the stash
+		git stash apply &&
+		test_path_is_missing file &&
+		test_must_fail git restore file &&
+
+		# apply the stash with "--index"
+		# it should restore "file" in index but not in workspace
+		git stash apply --index &&
+		test_path_is_missing file &&
+		git restore file &&
+		echo content >expect &&
+		test_cmp expect file
+	)
+'
+
 test_expect_success SYMLINKS 'stash file to symlink' '
 	git reset --hard &&
 	rm file &&