3 test_description
='git rm in sparse checked out working trees'
7 test_expect_success
'setup' "
9 touch a b c sub/d sub/dir/e &&
11 git commit -m files &&
13 cat >sparse_error_header <<-EOF &&
14 The following pathspecs didn't match any eligible path, but they do match index
15 entries outside the current sparse checkout:
18 cat >sparse_hint <<-EOF &&
19 hint: Disable or modify the sparsity rules if you intend to update such entries.
20 hint: Disable this message with \"git config advice.updateSparsePath false\"
23 echo b | cat sparse_error_header - >sparse_entry_b_error &&
24 cat sparse_entry_b_error sparse_hint >b_error_and_hint
27 for opt
in "" -f --dry-run
29 test_expect_success
"rm${opt:+ $opt} does not remove sparse entries" '
30 git sparse-checkout set a &&
31 test_must_fail git rm $opt b 2>stderr &&
32 test_cmp b_error_and_hint stderr &&
33 git ls-files --error-unmatch b
37 test_expect_success
'recursive rm does not remove sparse entries' '
39 git sparse-checkout set sub/dir &&
41 git status --porcelain -uno >actual &&
42 echo "D sub/dir/e" >expected &&
43 test_cmp expected actual
46 test_expect_success
'rm obeys advice.updateSparsePath' '
48 git sparse-checkout set a &&
49 test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr &&
50 test_cmp sparse_entry_b_error stderr
53 test_expect_success
'do not advice about sparse entries when they do not match the pathspec' '
55 git sparse-checkout set a &&
56 test_must_fail git rm nonexistent 2>stderr &&
57 grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
58 ! grep -F -f sparse_error_header stderr
61 test_expect_success
'do not warn about sparse entries when pathspec matches dense entries' '
63 git sparse-checkout set a &&
64 git rm "[ba]" 2>stderr &&
65 test_must_be_empty stderr &&
66 git ls-files --error-unmatch b &&
67 test_must_fail git ls-files --error-unmatch a
70 test_expect_success
'do not warn about sparse entries with --ignore-unmatch' '
72 git sparse-checkout set a &&
73 git rm --ignore-unmatch b 2>stderr &&
74 test_must_be_empty stderr &&
75 git ls-files --error-unmatch b