t1092: behavior for adding sparse files
Add some tests to demonstrate the current behavior around adding files outside of the sparse-checkout cone. Currently, untracked files are handled differently from tracked files. A future change will make these cases be handled the same way. Further expand checking that a failed 'git add' does not stage changes to the index. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Sep 24, 2021 at 15:39 UTC
edd2cd345f8e916c6fc70fa3dafd14dcf1694991
1 file changed
+28
t/t1092-sparse-checkout-compatibility.sh
+28
@@ -187,6 +187,16 @@ test_sparse_match () {
187
test_cmp sparse-checkout-err sparse-index-err
188
}
189
190
+test_sparse_unstaged () {
191
+ file=$1 &&
192
+ for repo in sparse-checkout sparse-index
193
+ do
194
+ # Skip "unmerged" paths
195
+ git -C $repo diff --staged --diff-filter=u -- "$file" >diff &&
196
+ test_must_be_empty diff || return 1
197
+ done
198
+}
199
+
200
test_expect_success 'sparse-index contents' '
201
init_repos &&
202
@@ -291,6 +301,20 @@ test_expect_success 'add, commit, checkout' '
301
test_all_match git checkout -
302
'
303
304
+# NEEDSWORK: This documents current behavior, but is not a desirable
305
+# behavior (untracked files are handled differently than tracked).
306
+test_expect_success 'add outside sparse cone' '
307
+ init_repos &&
308
+
309
+ run_on_sparse mkdir folder1 &&
310
+ run_on_sparse ../edit-contents folder1/a &&
311
+ run_on_sparse ../edit-contents folder1/newfile &&
312
+ test_sparse_match test_must_fail git add folder1/a &&
313
+ grep "Disable or modify the sparsity rules" sparse-checkout-err &&
314
+ test_sparse_unstaged folder1/a &&
315
+ test_sparse_match git add folder1/newfile
316
+'
317
+
318
test_expect_success 'commit including unstaged changes' '
319
init_repos &&
320
@@ -339,7 +363,11 @@ test_expect_success 'status/add: outside sparse cone' '
363
364
# Adding the path outside of the sparse-checkout cone should fail.
365
test_sparse_match test_must_fail git add folder1/a &&
366
+ grep "Disable or modify the sparsity rules" sparse-checkout-err &&
367
+ test_sparse_unstaged folder1/a &&
368
test_sparse_match test_must_fail git add --refresh folder1/a &&
369
+ grep "Disable or modify the sparsity rules" sparse-checkout-err &&
370
+ test_sparse_unstaged folder1/a &&
371
372
# NEEDSWORK: Adding a newly-tracked file outside the cone succeeds
373
test_sparse_match git add folder1/new &&