aboutsummaryrefslogtreecommitdiff
path: root/t/t1011-read-tree-sparse-checkout.sh
blob: 0c74beedd22600e8dfe852393a5a9a36350cfeb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/sh

test_description='sparse checkout tests

* (tag: removed, master) removed
| D	sub/added
* (HEAD, tag: top) modified and added
| M	init.t
| A	sub/added
* (tag: init) init
  A	init.t
'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-read-tree.sh

test_expect_success 'setup' '
	cat >expected <<-\EOF &&
	100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0	init.t
	100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	sub/added
	100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	sub/addedtoo
	100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	subsub/added
	EOF
	cat >expected.swt <<-\EOF &&
	H init.t
	H sub/added
	H sub/addedtoo
	H subsub/added
	EOF

	test_commit init &&
	echo modified >>init.t &&
	mkdir sub subsub &&
	touch sub/added sub/addedtoo subsub/added &&
	git add init.t sub/added sub/addedtoo subsub/added &&
	git commit -m "modified and added" &&
	git tag top &&
	git rm sub/added &&
	git commit -m removed &&
	git tag removed &&
	git checkout top &&
	git ls-files --stage >result &&
	test_cmp expected result
'

test_expect_success 'read-tree without .git/info/sparse-checkout' '
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files --stage >result &&
	test_cmp expected result &&
	git ls-files -t >result &&
	test_cmp expected.swt result
'

test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
	echo >.git/info/sparse-checkout &&
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt result &&
	test -f init.t &&
	test -f sub/added
'

test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
	git config core.sparsecheckout true &&
	echo >.git/info/sparse-checkout &&
	read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt result &&
	test -f init.t &&
	test -f sub/added
'

test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
	git config core.sparsecheckout true &&
	echo >.git/info/sparse-checkout &&
	read_tree_u_must_fail -m -u HEAD &&
	git ls-files --stage >result &&
	test_cmp expected result &&
	git ls-files -t >result &&
	test_cmp expected.swt result &&
	test -f init.t &&
	test -f sub/added
'

test_expect_success 'match directories with trailing slash' '
	cat >expected.swt-noinit <<-\EOF &&
	S init.t
	H sub/added
	H sub/addedtoo
	S subsub/added
	EOF

	echo sub/ > .git/info/sparse-checkout &&
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files -t > result &&
	test_cmp expected.swt-noinit result &&
	test ! -f init.t &&
	test -f sub/added
'

test_expect_success 'match directories without trailing slash' '
	echo sub >.git/info/sparse-checkout &&
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt-noinit result &&
	test ! -f init.t &&
	test -f sub/added
'

test_expect_success 'match directories with negated patterns' '
	cat >expected.swt-negation <<\EOF &&
S init.t
S sub/added
H sub/addedtoo
S subsub/added
EOF

	cat >.git/info/sparse-checkout <<\EOF &&
sub
!sub/added
EOF
	git read-tree -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt-negation result &&
	test ! -f init.t &&
	test ! -f sub/added &&
	test -f sub/addedtoo
'

test_expect_success 'match directories with negated patterns (2)' '
	cat >expected.swt-negation2 <<\EOF &&
H init.t
H sub/added
S sub/addedtoo
H subsub/added
EOF

	cat >.git/info/sparse-checkout <<\EOF &&
/*
!sub
sub/added
EOF
	git read-tree -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt-negation2 result &&
	test -f init.t &&
	test -f sub/added &&
	test ! -f sub/addedtoo
'

test_expect_success 'match directory pattern' '
	echo "s?b" >.git/info/sparse-checkout &&
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt-noinit result &&
	test ! -f init.t &&
	test -f sub/added
'

test_expect_success 'checkout area changes' '
	cat >expected.swt-nosub <<-\EOF &&
	H init.t
	S sub/added
	S sub/addedtoo
	S subsub/added
	EOF

	echo init.t >.git/info/sparse-checkout &&
	read_tree_u_must_succeed -m -u HEAD &&
	git ls-files -t >result &&
	test_cmp expected.swt-nosub result &&
	test -f init.t &&
	test ! -f sub/added
'

test_expect_success 'read-tree updates worktree, absent case' '
	echo sub/added >.git/info/sparse-checkout &&
	git checkout -f top &&
	read_tree_u_must_succeed -m -u HEAD^ &&
	test ! -f init.t
'

test_expect_success 'read-tree updates worktree, dirty case' '
	echo sub/added >.git/info/sparse-checkout &&
	git checkout -f top &&
	echo dirty >init.t &&
	read_tree_u_must_succeed -m -u HEAD^ &&
	grep -q dirty init.t &&
	rm init.t
'

test_expect_success 'read-tree removes worktree, dirty case' '
	echo init.t >.git/info/sparse-checkout &&
	git checkout -f top &&
	echo dirty >added &&
	read_tree_u_must_succeed -m -u HEAD^ &&
	grep -q dirty added
'

test_expect_success 'read-tree adds to worktree, absent case' '
	echo init.t >.git/info/sparse-checkout &&
	git checkout -f removed &&
	read_tree_u_must_succeed -u -m HEAD^ &&
	test ! -f sub/added
'

test_expect_success 'read-tree adds to worktree, dirty case' '
	echo init.t >.git/info/sparse-checkout &&
	git checkout -f removed &&
	mkdir sub &&
	echo dirty >sub/added &&
	read_tree_u_must_succeed -u -m HEAD^ &&
	grep -q dirty sub/added
'

test_expect_success 'index removal and worktree narrowing at the same time' '
	>empty &&
	echo init.t >.git/info/sparse-checkout &&
	echo sub/added >>.git/info/sparse-checkout &&
	git checkout -f top &&
	echo init.t >.git/info/sparse-checkout &&
	git checkout removed &&
	git ls-files sub/added >result &&
	test ! -f sub/added &&
	test_cmp empty result
'

test_expect_success 'read-tree --reset removes outside worktree' '
	>empty &&
	echo init.t >.git/info/sparse-checkout &&
	git checkout -f top &&
	git reset --hard removed &&
	git ls-files sub/added >result &&
	test_cmp empty result
'

test_expect_success 'print errors when failed to update worktree' '
	echo sub >.git/info/sparse-checkout &&
	git checkout -f init &&
	mkdir sub &&
	touch sub/added sub/addedtoo &&
	test_must_fail git checkout top 2>actual &&
	cat >expected <<\EOF &&
error: The following untracked working tree files would be overwritten by checkout:
	sub/added
	sub/addedtoo
Please move or remove them before you can switch branches.
Aborting
EOF
	test_cmp expected actual
'

test_expect_success 'checkout without --ignore-skip-worktree-bits' '
	echo "*" >.git/info/sparse-checkout &&
	git checkout -f top &&
	test_path_is_file init.t &&
	echo sub >.git/info/sparse-checkout &&
	git checkout &&
	echo modified >> sub/added &&
	git checkout . &&
	test_path_is_missing init.t &&
	git diff --exit-code HEAD
'

test_expect_success 'checkout with --ignore-skip-worktree-bits' '
	echo "*" >.git/info/sparse-checkout &&
	git checkout -f top &&
	test_path_is_file init.t &&
	echo sub >.git/info/sparse-checkout &&
	git checkout &&
	echo modified >> sub/added &&
	git checkout --ignore-skip-worktree-bits . &&
	test_path_is_file init.t &&
	git diff --exit-code HEAD
'

test_done