]>
Commit | Line | Data |
---|---|---|
d5f4b826 MT |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rm in sparse checked out working trees' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' " | |
8 | mkdir -p sub/dir && | |
9 | touch a b c sub/d sub/dir/e && | |
10 | git add -A && | |
11 | git commit -m files && | |
12 | ||
13 | cat >sparse_error_header <<-EOF && | |
6579e788 DS |
14 | The following paths and/or pathspecs matched paths that exist |
15 | outside of your sparse-checkout definition, so will not be | |
16 | updated in the index: | |
d5f4b826 MT |
17 | EOF |
18 | ||
19 | cat >sparse_hint <<-EOF && | |
6579e788 DS |
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. | |
d5f4b826 MT |
23 | hint: Disable this message with \"git config advice.updateSparsePath false\" |
24 | EOF | |
25 | ||
26 | echo b | cat sparse_error_header - >sparse_entry_b_error && | |
27 | cat sparse_entry_b_error sparse_hint >b_error_and_hint | |
28 | " | |
29 | ||
30 | for opt in "" -f --dry-run | |
31 | do | |
32 | test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' | |
dde13589 | 33 | git sparse-checkout set --no-cone a && |
d5f4b826 MT |
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 | |
37 | ' | |
38 | done | |
39 | ||
40 | test_expect_success 'recursive rm does not remove sparse entries' ' | |
41 | git reset --hard && | |
42 | git sparse-checkout set sub/dir && | |
20141e32 | 43 | git rm -r sub && |
d5f4b826 | 44 | git status --porcelain -uno >actual && |
d7c4415e | 45 | cat >expected <<-\EOF && |
20141e32 MT |
46 | D sub/dir/e |
47 | EOF | |
48 | test_cmp expected actual && | |
49 | ||
50 | git rm --sparse -r sub && | |
51 | git status --porcelain -uno >actual2 && | |
52 | cat >expected2 <<-\EOF && | |
d7c4415e DS |
53 | D sub/d |
54 | D sub/dir/e | |
55 | EOF | |
20141e32 | 56 | test_cmp expected2 actual2 |
d5f4b826 MT |
57 | ' |
58 | ||
f9786f9b DS |
59 | test_expect_success 'recursive rm --sparse removes sparse entries' ' |
60 | git reset --hard && | |
61 | git sparse-checkout set "sub/dir" && | |
62 | git rm --sparse -r sub && | |
63 | git status --porcelain -uno >actual && | |
64 | cat >expected <<-\EOF && | |
65 | D sub/d | |
66 | D sub/dir/e | |
67 | EOF | |
68 | test_cmp expected actual | |
69 | ' | |
70 | ||
d5f4b826 MT |
71 | test_expect_success 'rm obeys advice.updateSparsePath' ' |
72 | git reset --hard && | |
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 | |
76 | ' | |
77 | ||
78 | test_expect_success 'do not advice about sparse entries when they do not match the pathspec' ' | |
79 | git reset --hard && | |
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 | |
84 | ' | |
85 | ||
86 | test_expect_success 'do not warn about sparse entries when pathspec matches dense entries' ' | |
87 | git reset --hard && | |
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 | |
93 | ' | |
94 | ||
95 | test_expect_success 'do not warn about sparse entries with --ignore-unmatch' ' | |
96 | git reset --hard && | |
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 | |
101 | ' | |
102 | ||
d7c4415e DS |
103 | test_expect_success 'refuse to rm a non-skip-worktree path outside sparse cone' ' |
104 | git reset --hard && | |
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 | |
112 | ' | |
113 | ||
20141e32 MT |
114 | test_expect_success 'can remove files from non-sparse dir' ' |
115 | git reset --hard && | |
116 | git sparse-checkout disable && | |
117 | mkdir -p w x/y && | |
118 | test_commit w/f && | |
119 | test_commit x/y/f && | |
120 | ||
dde13589 | 121 | git sparse-checkout set --no-cone w !/x y/ && |
20141e32 MT |
122 | git rm w/f.t x/y/f.t 2>stderr && |
123 | test_must_be_empty stderr | |
124 | ' | |
125 | ||
126 | test_expect_success 'refuse to remove non-skip-worktree file from sparse dir' ' | |
127 | git reset --hard && | |
128 | git sparse-checkout disable && | |
129 | mkdir -p x/y/z && | |
130 | test_commit x/y/z/f && | |
dde13589 | 131 | git sparse-checkout set --no-cone !/x y/ !x/y/z && |
20141e32 MT |
132 | |
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 | |
137 | ' | |
138 | ||
d5f4b826 | 139 | test_done |