1
+#!/bin/sh
2
+
3
+test_description='git mv in sparse working trees'
4
+
5
+. ./test-lib.sh
6
+
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 &&
12
+
13
+ cat >sparse_error_header <<-EOF &&
14
+ The following pathspecs didn't match any eligible path, but they do match index
15
+ entries outside the current sparse checkout:
16
+ EOF
17
+
18
+ cat >sparse_hint <<-EOF
19
+ hint: Disable or modify the sparsity rules if you intend to update such entries.
20
+ hint: Disable this message with \"git config advice.updateSparsePath false\"
21
+ EOF
22
+"
23
+
24
+test_expect_success 'mv refuses to move sparse-to-sparse' '
25
+ test_when_finished rm -f e &&
26
+ git reset --hard &&
27
+ git sparse-checkout set a &&
28
+ touch b &&
29
+ test_must_fail git mv b e 2>stderr &&
30
+ cat sparse_error_header >expect &&
31
+ echo b >>expect &&
32
+ echo e >>expect &&
33
+ cat sparse_hint >>expect &&
34
+ test_cmp expect stderr &&
35
+ git mv --sparse b e 2>stderr &&
36
+ test_must_be_empty stderr
37
+'
38
+
39
+test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
40
+ test_when_finished rm -f b c e &&
41
+ git reset --hard &&
42
+ git sparse-checkout set a &&
43
+
44
+ # tracked-to-untracked
45
+ touch b &&
46
+ git mv -k b e 2>stderr &&
47
+ test_path_exists b &&
48
+ test_path_is_missing e &&
49
+ cat sparse_error_header >expect &&
50
+ echo b >>expect &&
51
+ echo e >>expect &&
52
+ cat sparse_hint >>expect &&
53
+ test_cmp expect stderr &&
54
+
55
+ git mv --sparse b e 2>stderr &&
56
+ test_must_be_empty stderr &&
57
+ test_path_is_missing b &&
58
+ test_path_exists e &&
59
+
60
+ # tracked-to-tracked
61
+ git reset --hard &&
62
+ touch b &&
63
+ git mv -k b c 2>stderr &&
64
+ test_path_exists b &&
65
+ test_path_is_missing c &&
66
+ cat sparse_error_header >expect &&
67
+ echo b >>expect &&
68
+ echo c >>expect &&
69
+ cat sparse_hint >>expect &&
70
+ test_cmp expect stderr &&
71
+
72
+ git mv --sparse b c 2>stderr &&
73
+ test_must_be_empty stderr &&
74
+ test_path_is_missing b &&
75
+ test_path_exists c
76
+'
77
+
78
+test_expect_success 'mv refuses to move non-sparse-to-sparse' '
79
+ test_when_finished rm -f b c e &&
80
+ git reset --hard &&
81
+ git sparse-checkout set a &&
82
+
83
+ # tracked-to-untracked
84
+ test_must_fail git mv a e 2>stderr &&
85
+ test_path_exists a &&
86
+ test_path_is_missing e &&
87
+ cat sparse_error_header >expect &&
88
+ echo e >>expect &&
89
+ cat sparse_hint >>expect &&
90
+ test_cmp expect stderr &&
91
+ git mv --sparse a e 2>stderr &&
92
+ test_must_be_empty stderr &&
93
+ test_path_is_missing a &&
94
+ test_path_exists e &&
95
+
96
+ # tracked-to-tracked
97
+ rm e &&
98
+ git reset --hard &&
99
+ test_must_fail git mv a c 2>stderr &&
100
+ test_path_exists a &&
101
+ test_path_is_missing c &&
102
+ cat sparse_error_header >expect &&
103
+ echo c >>expect &&
104
+ cat sparse_hint >>expect &&
105
+ test_cmp expect stderr &&
106
+ git mv --sparse a c 2>stderr &&
107
+ test_must_be_empty stderr &&
108
+ test_path_is_missing a &&
109
+ test_path_exists c
110
+'
111
+
112
+test_expect_success 'mv refuses to move sparse-to-non-sparse' '
113
+ test_when_finished rm -f b c e &&
114
+ git reset --hard &&
115
+ git sparse-checkout set a e &&
116
+
117
+ # tracked-to-untracked
118
+ touch b &&
119
+ test_must_fail git mv b e 2>stderr &&
120
+ cat sparse_error_header >expect &&
121
+ echo b >>expect &&
122
+ cat sparse_hint >>expect &&
123
+ test_cmp expect stderr &&
124
+ git mv --sparse b e 2>stderr &&
125
+ test_must_be_empty stderr
126
+'
127
+
128
+test_expect_success 'recursive mv refuses to move (possible) sparse' '
129
+ test_when_finished rm -rf b c e sub2 &&
130
+ git reset --hard &&
131
+ # Without cone mode, "sub" and "sub2" do not match
132
+ git sparse-checkout set sub/dir sub2/dir &&
133
+
134
+ # Add contained contents to ensure we avoid non-existence errors
135
+ mkdir sub/dir2 &&
136
+ touch sub/d sub/dir2/e &&
137
+
138
+ test_must_fail git mv sub sub2 2>stderr &&
139
+ cat sparse_error_header >expect &&
140
+ cat >>expect <<-\EOF &&
141
+ sub/d
142
+ sub2/d
143
+ sub/dir/e
144
+ sub2/dir/e
145
+ sub/dir2/e
146
+ sub2/dir2/e
147
+ EOF
148
+ cat sparse_hint >>expect &&
149
+ test_cmp expect stderr &&
150
+ git mv --sparse sub sub2 2>stderr &&
151
+ test_must_be_empty stderr &&
152
+ git commit -m "moved sub to sub2" &&
153
+ git rev-parse HEAD~1:sub >expect &&
154
+ git rev-parse HEAD:sub2 >actual &&
155
+ test_cmp expect actual &&
156
+ git reset --hard HEAD~1
157
+'
158
+
159
+test_expect_success 'recursive mv refuses to move sparse' '
160
+ git reset --hard &&
161
+ # Use cone mode so "sub/" matches the sparse-checkout patterns
162
+ git sparse-checkout init --cone &&
163
+ git sparse-checkout set sub/dir sub2/dir &&
164
+
165
+ # Add contained contents to ensure we avoid non-existence errors
166
+ mkdir sub/dir2 &&
167
+ touch sub/dir2/e &&
168
+
169
+ test_must_fail git mv sub sub2 2>stderr &&
170
+ cat sparse_error_header >expect &&
171
+ cat >>expect <<-\EOF &&
172
+ sub/dir2/e
173
+ sub2/dir2/e
174
+ EOF
175
+ cat sparse_hint >>expect &&
176
+ test_cmp expect stderr &&
177
+ git mv --sparse sub sub2 2>stderr &&
178
+ test_must_be_empty stderr &&
179
+ git commit -m "moved sub to sub2" &&
180
+ git rev-parse HEAD~1:sub >expect &&
181
+ git rev-parse HEAD:sub2 >actual &&
182
+ test_cmp expect actual &&
183
+ git reset --hard HEAD~1
184
+'
185
+
186
+test_done