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 paths and/or pathspecs matched paths that exist
15 outside of your sparse-checkout definition, so will not be
19 cat >sparse_hint <<-EOF &&
20 hint: If you intend to update such entries, try one of the following:
21 hint: * Use the --sparse option.
22 hint: * Disable or modify the sparsity rules.
23 hint: Disable this message with \"git config advice.updateSparsePath false\"
26 echo b | cat sparse_error_header - >sparse_entry_b_error &&
27 cat sparse_entry_b_error sparse_hint >b_error_and_hint
30 for opt
in "" -f --dry-run
32 test_expect_success
"rm${opt:+ $opt} does not remove sparse entries" '
33 git sparse-checkout set --no-cone a &&
34 test_must_fail git rm $opt b 2>stderr &&
35 test_cmp b_error_and_hint stderr &&
36 git ls-files --error-unmatch b
40 test_expect_success
'recursive rm does not remove sparse entries' '
42 git sparse-checkout set sub/dir &&
44 git status --porcelain -uno >actual &&
45 cat >expected <<-\EOF &&
48 test_cmp expected actual &&
50 git rm --sparse -r sub &&
51 git status --porcelain -uno >actual2 &&
52 cat >expected2 <<-\EOF &&
56 test_cmp expected2 actual2
59 test_expect_success
'recursive rm --sparse removes sparse entries' '
61 git sparse-checkout set "sub/dir" &&
62 git rm --sparse -r sub &&
63 git status --porcelain -uno >actual &&
64 cat >expected <<-\EOF &&
68 test_cmp expected actual
71 test_expect_success
'rm obeys advice.updateSparsePath' '
73 git sparse-checkout set a &&
74 test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr &&
75 test_cmp sparse_entry_b_error stderr
78 test_expect_success
'do not advice about sparse entries when they do not match the pathspec' '
80 git sparse-checkout set a &&
81 test_must_fail git rm nonexistent 2>stderr &&
82 grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
83 ! grep -F -f sparse_error_header stderr
86 test_expect_success
'do not warn about sparse entries when pathspec matches dense entries' '
88 git sparse-checkout set a &&
89 git rm "[ba]" 2>stderr &&
90 test_must_be_empty stderr &&
91 git ls-files --error-unmatch b &&
92 test_must_fail git ls-files --error-unmatch a
95 test_expect_success
'do not warn about sparse entries with --ignore-unmatch' '
97 git sparse-checkout set a &&
98 git rm --ignore-unmatch b 2>stderr &&
99 test_must_be_empty stderr &&
100 git ls-files --error-unmatch b
103 test_expect_success
'refuse to rm a non-skip-worktree path outside sparse cone' '
105 git sparse-checkout set a &&
106 git update-index --no-skip-worktree b &&
107 test_must_fail git rm b 2>stderr &&
108 test_cmp b_error_and_hint stderr &&
109 git rm --sparse b 2>stderr &&
110 test_must_be_empty stderr &&
111 test_path_is_missing b
114 test_expect_success
'can remove files from non-sparse dir' '
116 git sparse-checkout disable &&
121 git sparse-checkout set --no-cone w !/x y/ &&
122 git rm w/f.t x/y/f.t 2>stderr &&
123 test_must_be_empty stderr
126 test_expect_success
'refuse to remove non-skip-worktree file from sparse dir' '
128 git sparse-checkout disable &&
130 test_commit x/y/z/f &&
131 git sparse-checkout set --no-cone !/x y/ !x/y/z &&
133 git update-index --no-skip-worktree x/y/z/f.t &&
134 test_must_fail git rm x/y/z/f.t 2>stderr &&
135 echo x/y/z/f.t | cat sparse_error_header - sparse_hint >expect &&
136 test_cmp expect stderr