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 &&
151 cat sparse_hint >>expect &&
152 test_cmp expect stderr &&
153 git mv --sparse sub sub2 2>stderr &&
154 test_must_be_empty stderr &&
155 git commit -m "moved sub to sub2" &&
156 git rev-parse HEAD~1:sub >expect &&
157 git rev-parse HEAD:sub2 >actual &&
158 test_cmp expect actual &&
159 git reset --hard HEAD~1
162 test_expect_success
'recursive mv refuses to move sparse' '
164 # Use cone mode so "sub/" matches the sparse-checkout patterns
165 git sparse-checkout init --cone &&
166 git sparse-checkout set sub/dir sub2/dir &&
168 # Add contained contents to ensure we avoid non-existence errors
172 test_must_fail git mv sub sub2 2>stderr &&
173 cat sparse_error_header >expect &&
174 cat >>expect <<-\EOF &&
178 cat sparse_hint >>expect &&
179 test_cmp expect stderr &&
180 git mv --sparse sub sub2 2>stderr &&
181 test_must_be_empty stderr &&
182 git commit -m "moved sub to sub2" &&
183 git rev-parse HEAD~1:sub >expect &&
184 git rev-parse HEAD:sub2 >actual &&
185 test_cmp expect actual &&
186 git reset --hard HEAD~1