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

[RFC PATCH 1/5] t1011: add testcase demonstrating accidental loss of user modifications

From
Elijah Newren <newren@gmail.com>
Date
Jan 9, 2022, 04:57 UTC
Message-ID
<20220109045732.2497526-2-newren@gmail.com>
In-Reply-To
<20220109045732.2497526-1-newren@gmail.com>

If a user has a file with local modifications that is not marked as SKIP_WORKTREE, but the sparsity patterns are such that it should be marked that way, and the user then invokes a command like

   * git checkout -q HEAD^
or
   * git read-tree -mu HEAD^

Then the file will be deleted along with all the users' modifications. Add a testcase demonstrating this problem.

Note: This bug only triggers if something other than 'HEAD' is given;
if the commands above had specified 'HEAD', then the users' file would
be left alone.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t1011-read-tree-sparse-checkout.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh
index 24092c09a9..1b2395b8a8 100755
--- a/t/t1011-read-tree-sparse-checkout.sh
+++ b/t/t1011-read-tree-sparse-checkout.sh
@@ -187,6 +187,27 @@ test_expect_success 'read-tree updates worktree, absent case' '
 	test ! -f init.t
 '
 
+test_expect_success 'read-tree will not throw away dirty changes, non-sparse' '
+	echo "/*" >.git/info/sparse-checkout &&
+	read_tree_u_must_succeed -m -u HEAD &&
+
+	echo dirty >init.t &&
+	read_tree_u_must_fail -m -u HEAD^ &&
+	test_path_is_file init.t &&
+	grep -q dirty init.t
+'
+
+test_expect_failure 'read-tree will not throw away dirty changes, sparse' '
+	echo "/*" >.git/info/sparse-checkout &&
+	read_tree_u_must_succeed -m -u HEAD &&
+
+	echo dirty >init.t &&
+	echo sub/added >.git/info/sparse-checkout &&
+	read_tree_u_must_fail -m -u HEAD^ &&
+	test_path_is_file init.t &&
+	grep -q dirty init.t
+'
+
 test_expect_success 'read-tree updates worktree, dirty case' '
 	echo sub/added >.git/info/sparse-checkout &&
 	git checkout -f top &&
-- 
2.34.1.442.ge63c19bdd2.dirty
Previous: Elijah NewrenNext: Elijah Newren
Message 2 of 11 in “Remove the present-despite-SKIP_WORKTREE class of bugs”
  1. 0/5 Remove the present-despite-SKIP_WORKTREE class of bugsElijah Newren, Jan 9, 2022
  2. 1/5 t1011: add testcase demonstrating accidental loss of user modificationsElijah Newren, Jan 9, 2022
  3. 2/5 unpack-trees: fix accidental loss of user changesElijah Newren, Jan 9, 2022
  4. 3/5 repo_read_index: ensure SKIP_WORKTREE means skip worktreeElijah Newren, Jan 9, 2022
  5. Victoria DyeJan 10, 2022
  6. Elijah NewrenJan 11, 2022
  7. Victoria DyeJan 11, 2022
  8. 4/5 Update documentation related to sparsity and the skip-worktree bitElijah Newren, Jan 9, 2022
  9. 5/5 Accelerate ensure_skip_worktree_means_skip_worktree by cachingElijah Newren, Jan 9, 2022
  10. Victoria DyeJan 11, 2022
  11. Elijah NewrenJan 11, 2022

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.