Skip to content

Commit edd2cd3

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca267ae commit edd2cd3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ test_sparse_match () {
187187
test_cmp sparse-checkout-err sparse-index-err
188188
}
189189

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+
190200
test_expect_success 'sparse-index contents' '
191201
init_repos &&
192202
@@ -291,6 +301,20 @@ test_expect_success 'add, commit, checkout' '
291301
test_all_match git checkout -
292302
'
293303

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+
294318
test_expect_success 'commit including unstaged changes' '
295319
init_repos &&
296320
@@ -339,7 +363,11 @@ test_expect_success 'status/add: outside sparse cone' '
339363
340364
# Adding the path outside of the sparse-checkout cone should fail.
341365
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 &&
342368
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 &&
343371
344372
# NEEDSWORK: Adding a newly-tracked file outside the cone succeeds
345373
test_sparse_match git add folder1/new &&

0 commit comments

Comments
 (0)