t/gpg: simplify test for unknown key
[git/debian.git] / t / t7002-mv-sparse-checkout.sh
blob545748949aa4e21203e2d2f978413c95351787da
1 #!/bin/sh
3 test_description='git mv in sparse working trees'
5 . ./test-lib.sh
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 &&
10 git add -A &&
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
16 updated in the index:
17 EOF
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\"
24 EOF
27 test_expect_success 'mv refuses to move sparse-to-sparse' '
28 test_when_finished rm -f e &&
29 git reset --hard &&
30 git sparse-checkout set a &&
31 touch b &&
32 test_must_fail git mv b e 2>stderr &&
33 cat sparse_error_header >expect &&
34 echo b >>expect &&
35 echo e >>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 &&
44 git reset --hard &&
45 git sparse-checkout set a &&
47 # tracked-to-untracked
48 touch b &&
49 git mv -k b e 2>stderr &&
50 test_path_exists b &&
51 test_path_is_missing e &&
52 cat sparse_error_header >expect &&
53 echo b >>expect &&
54 echo e >>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 &&
61 test_path_exists e &&
63 # tracked-to-tracked
64 git reset --hard &&
65 touch b &&
66 git mv -k b c 2>stderr &&
67 test_path_exists b &&
68 test_path_is_missing c &&
69 cat sparse_error_header >expect &&
70 echo b >>expect &&
71 echo c >>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 &&
78 test_path_exists c
81 test_expect_success 'mv refuses to move non-sparse-to-sparse' '
82 test_when_finished rm -f b c e &&
83 git reset --hard &&
84 git sparse-checkout set a &&
86 # tracked-to-untracked
87 test_must_fail git mv a e 2>stderr &&
88 test_path_exists a &&
89 test_path_is_missing e &&
90 cat sparse_error_header >expect &&
91 echo e >>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 &&
97 test_path_exists e &&
99 # tracked-to-tracked
100 rm e &&
101 git reset --hard &&
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 &&
106 echo c >>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 &&
112 test_path_exists c
115 test_expect_success 'mv refuses to move sparse-to-non-sparse' '
116 test_when_finished rm -f b c e &&
117 git reset --hard &&
118 git sparse-checkout set a e &&
120 # tracked-to-untracked
121 touch b &&
122 test_must_fail git mv b e 2>stderr &&
123 cat sparse_error_header >expect &&
124 echo b >>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 &&
133 git reset --hard &&
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
138 mkdir sub/dir2 &&
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 &&
144 sub/d
145 sub2/d
146 sub/dir/e
147 sub2/dir/e
148 sub/dir2/e
149 sub2/dir2/e
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' '
163 git reset --hard &&
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
169 mkdir sub/dir2 &&
170 touch sub/dir2/e &&
172 test_must_fail git mv sub sub2 2>stderr &&
173 cat sparse_error_header >expect &&
174 cat >>expect <<-\EOF &&
175 sub/dir2/e
176 sub2/dir2/e
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
189 test_done