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

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

From
Piotr Siupa <piotrsiupa@gmail.com>
Date
Aug 21, 2024, 19:09 UTC
Message-ID
<20240821190921.18772-1-piotrsiupa@gmail.com>

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 --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 &&
-- 
2.34.1
Message 1 of 1 in “builtin/stash: test push with new file added and removed”
  1. builtin/stash: test push with new file added and removedPiotr Siupa, Aug 21, 2024

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.