Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t3602-rm-sparse-checkout.sh
blobfcdefba48cc76b9a86c8136342c828e30cd9e811
1 #!/bin/sh
3 test_description='git rm in sparse checked out working trees'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' "
9 mkdir -p sub/dir &&
10 touch a b c sub/d sub/dir/e &&
11 git add -A &&
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
17 updated in the index:
18 EOF
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\"
25 EOF
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
39 done
41 test_expect_success 'recursive rm does not remove sparse entries' '
42 git reset --hard &&
43 git sparse-checkout set sub/dir &&
44 git rm -r sub &&
45 git status --porcelain -uno >actual &&
46 cat >expected <<-\EOF &&
47 D sub/dir/e
48 EOF
49 test_cmp expected actual &&
51 git rm --sparse -r sub &&
52 git status --porcelain -uno >actual2 &&
53 cat >expected2 <<-\EOF &&
54 D sub/d
55 D sub/dir/e
56 EOF
57 test_cmp expected2 actual2
60 test_expect_success 'recursive rm --sparse removes sparse entries' '
61 git reset --hard &&
62 git sparse-checkout set "sub/dir" &&
63 git rm --sparse -r sub &&
64 git status --porcelain -uno >actual &&
65 cat >expected <<-\EOF &&
66 D sub/d
67 D sub/dir/e
68 EOF
69 test_cmp expected actual
72 test_expect_success 'rm obeys advice.updateSparsePath' '
73 git reset --hard &&
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' '
80 git reset --hard &&
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' '
88 git reset --hard &&
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' '
97 git reset --hard &&
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' '
105 git reset --hard &&
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' '
116 git reset --hard &&
117 git sparse-checkout disable &&
118 mkdir -p w x/y &&
119 test_commit w/f &&
120 test_commit x/y/f &&
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' '
128 git reset --hard &&
129 git sparse-checkout disable &&
130 mkdir -p x/y/z &&
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
140 test_done