t1092: add tests for status/add and sparse files

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. 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. Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jul 14, 2021 at 13:12 UTC bf26c06f126219498a10ae9f8923cfb0bcbad823
1 file changed +38
t/t1092-sparse-checkout-compatibility.sh
+38
@@ -254,6 +254,44 @@ test_expect_success 'add, commit, checkout' '
254 test_all_match git checkout -
255 '
256
257 +test_expect_success 'status/add: outside sparse cone' '
258 + init_repos &&
259 +
260 + # adding a "missing" file outside the cone should fail
261 + test_sparse_match test_must_fail git add folder1/a &&
262 +
263 + # folder1 is at HEAD, but outside the sparse cone
264 + run_on_sparse mkdir folder1 &&
265 + cp initial-repo/folder1/a sparse-checkout/folder1/a &&
266 + cp initial-repo/folder1/a sparse-index/folder1/a &&
267 +
268 + test_sparse_match git status &&
269 +
270 + write_script edit-contents <<-\EOF &&
271 + echo text >>$1
272 + EOF
273 + run_on_sparse ../edit-contents folder1/a &&
274 + run_on_all ../edit-contents folder1/new &&
275 +
276 + test_sparse_match git status --porcelain=v2 &&
277 +
278 + # This "git add folder1/a" fails with a warning
279 + # in the sparse repos, differing from the full
280 + # repo. This is intentional.
281 + test_sparse_match test_must_fail git add folder1/a &&
282 + test_sparse_match test_must_fail git add --refresh folder1/a &&
283 + test_all_match git status --porcelain=v2 &&
284 +
285 + test_all_match git add . &&
286 + test_all_match git status --porcelain=v2 &&
287 + test_all_match git commit -m folder1/new &&
288 +
289 + run_on_all ../edit-contents folder1/newer &&
290 + test_all_match git add folder1/ &&
291 + test_all_match git status --porcelain=v2 &&
292 + test_all_match git commit -m folder1/newer
293 +'
294 +
295 test_expect_success 'checkout and reset --hard' '
296 init_repos &&
297