--- v7
+++ v3
@@ -1,77 +1,41 @@
From: Derrick Stolee <dstolee@microsoft.com>
-Before moving to update 'git status' and 'git add' to work with sparse
-indexes, add an explicit test that ensures the sparse-index works the
-same as a normal sparse-checkout when the worktree contains directories
-and files outside of the sparse cone.
+The cache_bottom member of 'struct unpack_trees_options' is used to
+track the range of index entries corresponding to a node of the cache
+tree. While recursing with traverse_by_cache_tree(), this value is
+preserved on the call stack using a local and then restored as that
+method returns.
-Specifically, 'folder1/a' is a file in our test repo, but 'folder1' is
-not in the sparse cone. When 'folder1/a' is modified, the file is not
-shown as modified and adding it will fail. This is new behavior as of
-a20f704 (add: warn when asked to update SKIP_WORKTREE entries,
-2021-04-08). Before that change, these adds would be silently ignored.
-
-Untracked files are fine: adding new files both with 'git add .' and
-'git add folder1/' works just as in a full checkout. This may not be
-entirely desirable, but we are not intending to change behavior at the
-moment, only document it. A future change could alter the behavior to
-be more sensible, and this test could be modified to satisfy the new
-expected behavior.
+The mark_ce_used() method normally modifies the cache_bottom member when
+it refers to the marked cache entry. However, sparse directory entries
+are stored as nodes in the cache-tree data structure as of 2de37c53
+(cache-tree: integrate with sparse directory entries, 2021-03-30). Thus,
+the cache_bottom will be modified as the cache-tree walk advances. Do
+not update it as well within mark_ce_used().
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
- t/t1092-sparse-checkout-compatibility.sh | 38 ++++++++++++++++++++++++
- 1 file changed, 38 insertions(+)
+ unpack-trees.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
-diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
-index 363d605c209..3f61e5686b5 100755
---- a/t/t1092-sparse-checkout-compatibility.sh
-+++ b/t/t1092-sparse-checkout-compatibility.sh
-@@ -254,6 +254,44 @@ test_expect_success 'add, commit, checkout' '
- test_all_match git checkout -
- '
+diff --git a/unpack-trees.c b/unpack-trees.c
+index dddf106d5bd4..1067db19c9d2 100644
+--- a/unpack-trees.c
++++ b/unpack-trees.c
+@@ -586,6 +586,13 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o)
+ {
+ ce->ce_flags |= CE_UNPACKED;
-+test_expect_success 'status/add: outside sparse cone' '
-+ init_repos &&
++ /*
++ * If this is a sparse directory, don't advance cache_bottom.
++ * That will be advanced later using the cache-tree data.
++ */
++ if (S_ISSPARSEDIR(ce->ce_mode))
++ return;
+
-+ # adding a "missing" file outside the cone should fail
-+ test_sparse_match test_must_fail git add folder1/a &&
-+
-+ # folder1 is at HEAD, but outside the sparse cone
-+ run_on_sparse mkdir folder1 &&
-+ cp initial-repo/folder1/a sparse-checkout/folder1/a &&
-+ cp initial-repo/folder1/a sparse-index/folder1/a &&
-+
-+ test_sparse_match git status &&
-+
-+ write_script edit-contents <<-\EOF &&
-+ echo text >>$1
-+ EOF
-+ run_on_sparse ../edit-contents folder1/a &&
-+ run_on_all ../edit-contents folder1/new &&
-+
-+ test_sparse_match git status --porcelain=v2 &&
-+
-+ # This "git add folder1/a" fails with a warning
-+ # in the sparse repos, differing from the full
-+ # repo. This is intentional.
-+ test_sparse_match test_must_fail git add folder1/a &&
-+ test_sparse_match test_must_fail git add --refresh folder1/a &&
-+ test_all_match git status --porcelain=v2 &&
-+
-+ test_all_match git add . &&
-+ test_all_match git status --porcelain=v2 &&
-+ test_all_match git commit -m folder1/new &&
-+
-+ run_on_all ../edit-contents folder1/newer &&
-+ test_all_match git add folder1/ &&
-+ test_all_match git status --porcelain=v2 &&
-+ test_all_match git commit -m folder1/newer
-+'
-+
- test_expect_success 'checkout and reset --hard' '
- init_repos &&
-
+ if (o->cache_bottom < o->src_index->cache_nr &&
+ o->src_index->cache[o->cache_bottom] == ce) {
+ int bottom = o->cache_bottom;
--
gitgitgadget