3 test_description
='git mv in sparse working trees'
7 test_expect_success
'setup' "
8 mkdir -p sub/dir sub/dir2 &&
9 touch a b c sub/d sub/dir/e sub/dir2/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\"
27 test_expect_success
'mv refuses to move sparse-to-sparse' '
28 test_when_finished rm -f e &&
30 git sparse-checkout set a &&
32 test_must_fail git mv b e 2>stderr &&
33 cat sparse_error_header >expect &&
36 cat sparse_hint >>expect &&
37 test_cmp expect stderr &&
38 git mv --sparse b e 2>stderr &&
39 test_must_be_empty stderr
42 test_expect_success
'mv refuses to move sparse-to-sparse, ignores failure' '
43 test_when_finished rm -f b c e &&
45 git sparse-checkout set a &&
47 # tracked-to-untracked
49 git mv -k b e 2>stderr &&
51 test_path_is_missing e &&
52 cat sparse_error_header >expect &&
55 cat sparse_hint >>expect &&
56 test_cmp expect stderr &&
58 git mv --sparse b e 2>stderr &&
59 test_must_be_empty stderr &&
60 test_path_is_missing b &&
66 git mv -k b c 2>stderr &&
68 test_path_is_missing c &&
69 cat sparse_error_header >expect &&
72 cat sparse_hint >>expect &&
73 test_cmp expect stderr &&
75 git mv --sparse b c 2>stderr &&
76 test_must_be_empty stderr &&
77 test_path_is_missing b &&
81 test_expect_success
'mv refuses to move non-sparse-to-sparse' '
82 test_when_finished rm -f b c e &&
84 git sparse-checkout set a &&
86 # tracked-to-untracked
87 test_must_fail git mv a e 2>stderr &&
89 test_path_is_missing e &&
90 cat sparse_error_header >expect &&
92 cat sparse_hint >>expect &&
93 test_cmp expect stderr &&
94 git mv --sparse a e 2>stderr &&
95 test_must_be_empty stderr &&
96 test_path_is_missing a &&
102 test_must_fail git mv a c 2>stderr &&
103 test_path_exists a &&
104 test_path_is_missing c &&
105 cat sparse_error_header >expect &&
107 cat sparse_hint >>expect &&
108 test_cmp expect stderr &&
109 git mv --sparse a c 2>stderr &&
110 test_must_be_empty stderr &&
111 test_path_is_missing a &&
115 test_expect_success
'mv refuses to move sparse-to-non-sparse' '
116 test_when_finished rm -f b c e &&
118 git sparse-checkout set a e &&
120 # tracked-to-untracked
122 test_must_fail git mv b e 2>stderr &&
123 cat sparse_error_header >expect &&
125 cat sparse_hint >>expect &&
126 test_cmp expect stderr &&
127 git mv --sparse b e 2>stderr &&
128 test_must_be_empty stderr
131 test_expect_success
'recursive mv refuses to move (possible) sparse' '
132 test_when_finished rm -rf b c e sub2 &&
134 # Without cone mode, "sub" and "sub2" do not match
135 git sparse-checkout set sub/dir sub2/dir &&
137 # Add contained contents to ensure we avoid non-existence errors
139 touch sub/d sub/dir2/e &&
141 test_must_fail git mv sub sub2 2>stderr &&
142 cat sparse_error_header >expect &&
143 cat >>expect <<-\EOF &&
149 cat sparse_hint >>expect &&
150 test_cmp expect stderr &&
151 git mv --sparse sub sub2 2>stderr &&
152 test_must_be_empty stderr &&
153 git commit -m "moved sub to sub2" &&
154 git rev-parse HEAD~1:sub >expect &&
155 git rev-parse HEAD:sub2 >actual &&
156 test_cmp expect actual &&
157 git reset --hard HEAD~1
160 test_expect_success
'recursive mv refuses to move sparse' '
162 # Use cone mode so "sub/" matches the sparse-checkout patterns
163 git sparse-checkout init --cone &&
164 git sparse-checkout set sub/dir sub2/dir &&
166 # Add contained contents to ensure we avoid non-existence errors
170 test_must_fail git mv sub sub2 2>stderr &&
171 cat sparse_error_header >expect &&
172 cat >>expect <<-\EOF &&
176 cat sparse_hint >>expect &&
177 test_cmp expect stderr &&
178 git mv --sparse sub sub2 2>stderr &&
179 test_must_be_empty stderr &&
180 git commit -m "moved sub to sub2" &&
181 git rev-parse HEAD~1:sub >expect &&
182 git rev-parse HEAD:sub2 >actual &&
183 test_cmp expect actual &&
184 git reset --hard HEAD~1
187 test_expect_success
'can move files to non-sparse dir' '
189 git sparse-checkout init --no-cone &&
190 git sparse-checkout set a b c w !/x y/ &&
193 git mv a w/new-a 2>stderr &&
194 git mv b x/y/new-b 2>stderr &&
195 test_must_be_empty stderr
198 test_expect_success
'refuse to move file to non-skip-worktree sparse path' '
200 git sparse-checkout init --no-cone &&
201 git sparse-checkout set a !/x y/ !x/y/z &&
204 test_must_fail git mv a x/y/z/new-a 2>stderr &&
205 echo x/y/z/new-a | cat sparse_error_header - sparse_hint >expect &&
206 test_cmp expect stderr