3 test_description
='git rm in sparse checked out working trees'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' "
10 touch a b c sub/d sub/dir/e &&
12 git commit -m files &&
14 cat >sparse_error_header <<-EOF &&
15 The following paths and/or pathspecs matched paths that exist
16 outside of your sparse-checkout definition, so will not be
20 cat >sparse_hint <<-EOF &&
21 hint: If you intend to update such entries, try one of the following:
22 hint: * Use the --sparse option.
23 hint: * Disable or modify the sparsity rules.
24 hint: Disable this message with \"git config advice.updateSparsePath false\"
27 echo b | cat sparse_error_header - >sparse_entry_b_error &&
28 cat sparse_entry_b_error sparse_hint >b_error_and_hint
31 for opt
in "" -f --dry-run
33 test_expect_success
"rm${opt:+ $opt} does not remove sparse entries" '
34 git sparse-checkout set --no-cone a &&
35 test_must_fail git rm $opt b 2>stderr &&
36 test_cmp b_error_and_hint stderr &&
37 git ls-files --error-unmatch b
41 test_expect_success
'recursive rm does not remove sparse entries' '
43 git sparse-checkout set sub/dir &&
45 git status --porcelain -uno >actual &&
46 cat >expected <<-\EOF &&
49 test_cmp expected actual &&
51 git rm --sparse -r sub &&
52 git status --porcelain -uno >actual2 &&
53 cat >expected2 <<-\EOF &&
57 test_cmp expected2 actual2
60 test_expect_success
'recursive rm --sparse removes sparse entries' '
62 git sparse-checkout set "sub/dir" &&
63 git rm --sparse -r sub &&
64 git status --porcelain -uno >actual &&
65 cat >expected <<-\EOF &&
69 test_cmp expected actual
72 test_expect_success
'rm obeys advice.updateSparsePath' '
74 git sparse-checkout set a &&
75 test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr &&
76 test_cmp sparse_entry_b_error stderr
79 test_expect_success
'do not advice about sparse entries when they do not match the pathspec' '
81 git sparse-checkout set a &&
82 test_must_fail git rm nonexistent 2>stderr &&
83 grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
84 ! grep -F -f sparse_error_header stderr
87 test_expect_success
'do not warn about sparse entries when pathspec matches dense entries' '
89 git sparse-checkout set a &&
90 git rm "[ba]" 2>stderr &&
91 test_must_be_empty stderr &&
92 git ls-files --error-unmatch b &&
93 test_must_fail git ls-files --error-unmatch a
96 test_expect_success
'do not warn about sparse entries with --ignore-unmatch' '
98 git sparse-checkout set a &&
99 git rm --ignore-unmatch b 2>stderr &&
100 test_must_be_empty stderr &&
101 git ls-files --error-unmatch b
104 test_expect_success
'refuse to rm a non-skip-worktree path outside sparse cone' '
106 git sparse-checkout set a &&
107 git update-index --no-skip-worktree b &&
108 test_must_fail git rm b 2>stderr &&
109 test_cmp b_error_and_hint stderr &&
110 git rm --sparse b 2>stderr &&
111 test_must_be_empty stderr &&
112 test_path_is_missing b
115 test_expect_success
'can remove files from non-sparse dir' '
117 git sparse-checkout disable &&
122 git sparse-checkout set --no-cone w !/x y/ &&
123 git rm w/f.t x/y/f.t 2>stderr &&
124 test_must_be_empty stderr
127 test_expect_success
'refuse to remove non-skip-worktree file from sparse dir' '
129 git sparse-checkout disable &&
131 test_commit x/y/z/f &&
132 git sparse-checkout set --no-cone !/x y/ !x/y/z &&
134 git update-index --no-skip-worktree x/y/z/f.t &&
135 test_must_fail git rm x/y/z/f.t 2>stderr &&
136 echo x/y/z/f.t | cat sparse_error_header - sparse_hint >expect &&
137 test_cmp expect stderr