Debian Codegraph @

t/t-checkout.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "checkout"
6 (
7 set -e
8
9 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
10 setup_remote_repo "$reponame"
11
12 clone_repo "$reponame" repo
13 rmscip-shell system . . rm. -f clone.log
14
15 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
16 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
17 rmscip-shell system . . rm. -f track.log
18
19 contents="something something"
20 contentsize=19
21 contents_oid=$(calc_oid "$contents")
22
23 # Same content everywhere is ok, just one object in lfs db
24 printfscip-shell system . . printf. "%s" "$contents" > file1.dat
25 printfscip-shell system . . printf. "%s" "$contents" > file2.dat
26 printfscip-shell system . . printf. "%s" "$contents" > file3.dat
27 mkdirscip-shell system . . mkdir. -p folder1 folder2/folder3/folder4
28 printfscip-shell system . . printf. "%s" "$contents" > folder1/nested.dat
29 printfscip-shell system . . printf. "%s" "$contents" > folder2/folder3/folder4/nested.dat
30 gitscip-shell system . . git. add file1.dat file2.dat file3.dat folder1 folder2
31 gitscip-shell system . . git. add .gitattributes
32 gitscip-shell system . . git. commit -m "add files"
33
34 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file1.dat)" ]
35 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file2.dat)" ]
36 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file3.dat)" ]
37 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
38 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
39
40 assert_pointer "main" "file1.dat" "$contents_oid" $contentsize
41
42 # Remove the working directory
43 rmscip-shell system . . rm. -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2
44
45 echoscip-shell system . . echo. "checkout should replace all"
46 GIT_TRACE=1 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
47 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file1.dat)" ]
48 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file2.dat)" ]
49 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file3.dat)" ]
50 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
51 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
52 grepscip-shell system . . grep. "Checking out LFS objects: 100% (5/5), 95 B" checkout.log
53 grepscip-shell system . . grep. 'accepting "file1.dat"' checkout.log
54 grepscip-shell system . . grep. 'rejecting "file1.dat"' checkout.log && exit 1
55 rmscip-shell system . . rm. -f checkout.log
56 assert_clean_status
57
58 gitscip-shell system . . git. rm file1.dat
59
60 echoscip-shell system . . echo. "checkout should skip replacing files deleted in index"
61 gitscip-shell system . . git. lfs checkout
62 [scip-shell system . . `[`. ! -f file1.dat ]
63 assert_clean_worktree_with_exceptions "file1\.dat"
64
65 gitscip-shell system . . git. reset --hard
66
67 # Remove the working directory
68 rmscip-shell system . . rm. -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2
69
70 echoscip-shell system . . echo. "checkout with filters"
71 gitscip-shell system . . git. lfs checkout file2.dat
72 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file2.dat)" ]
73 [scip-shell system . . `[`. ! -f file1.dat ]
74 [scip-shell system . . `[`. ! -f file3.dat ]
75 [scip-shell system . . `[`. ! -f folder1/nested.dat ]
76 [scip-shell system . . `[`. ! -e folder2 ]
77 assert_clean_worktree_with_exceptions "(file[13]|nested)\.dat"
78
79 echoscip-shell system . . echo. "quotes to avoid shell globbing"
80 gitscip-shell system . . git. lfs checkout "file*.dat"
81 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file1.dat)" ]
82 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file3.dat)" ]
83 [scip-shell system . . `[`. ! -f folder1/nested.dat ]
84 [scip-shell system . . `[`. ! -e folder2 ]
85 assert_clean_worktree_with_exceptions "nested\.dat"
86
87 echoscip-shell system . . echo. "test subdir context"
88 rmscip-shell system . . rm. file1.dat
89 pushd folder1
90 gitscip-shell system . . git. lfs checkout nested.dat
91 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. nested.dat)" ]
92 [scip-shell system . . `[`. ! -f ../file1.dat ]
93 [scip-shell system . . `[`. ! -e ../folder2 ]
94 assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat"
95
96 # test '.' in current dir
97 rmscip-shell system . . rm. nested.dat
98 gitscip-shell system . . git. lfs checkout .
99 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. nested.dat)" ]
100 [scip-shell system . . `[`. ! -f ../file1.dat ]
101 [scip-shell system . . `[`. ! -e ../folder2 ]
102 assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat"
103
104 # test '..' in current dir
105 gitscip-shell system . . git. lfs checkout ..
106 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. ../file1.dat)" ]
107 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. ../folder2/folder3/folder4/nested.dat)" ]
108 assert_clean_status
109
110 # test glob match with '..' in current dir
111 rmscip-shell system . . rm. -rf ../folder2
112 gitscip-shell system . . git. lfs checkout '../folder2/**'
113 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. ../folder2/folder3/folder4/nested.dat)" ]
114 assert_clean_status
115 popd
116
117 echoscip-shell system . . echo. "test folder param"
118 rmscip-shell system . . rm. -rf folder2
119 gitscip-shell system . . git. lfs checkout folder2
120 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
121 assert_clean_status
122
123 echoscip-shell system . . echo. "test folder param with pre-existing directory"
124 rmscip-shell system . . rm. -rf folder2
125 mkdirscip-shell system . . mkdir. folder2
126 gitscip-shell system . . git. lfs checkout folder2
127 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
128 assert_clean_status
129
130 echoscip-shell system . . echo. "test folder param with glob match"
131 rmscip-shell system . . rm. -rf folder2
132 gitscip-shell system . . git. lfs checkout 'folder2/**'
133 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
134 assert_clean_status
135
136 echoscip-shell system . . echo. "test '.' in current dir"
137 rmscip-shell system . . rm. -rf file1.dat file2.dat file3.dat folder1 folder2
138 gitscip-shell system . . git. lfs checkout .
139 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file1.dat)" ]
140 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file2.dat)" ]
141 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. file3.dat)" ]
142 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
143 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
144 assert_clean_status
145
146 echoscip-shell system . . echo. "test pre-existing directories"
147 rmscip-shell system . . rm. -rf folder1/nested.dat folder2/folder3/folder4
148 gitscip-shell system . . git. lfs checkout
149 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
150 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
151 assert_clean_status
152
153 echoscip-shell system . . echo. "test checkout with missing data doesn't fail"
154 gitscip-shell system . . git. push origin main
155 rmscip-shell system . . rm. -rf .git/lfs/objects
156 rmscip-shell system . . rm. file*.dat
157 gitscip-shell system . . git. lfs checkout
158 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file1.dat)" ]
159 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file2.dat)" ]
160 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file3.dat)" ]
161 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
162 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
163 assert_clean_worktree_with_exceptions "file[123]\.dat"
164 )
165 end_test
166
167 begin_test "checkout: skip directory file conflicts"
168 (
169 set -e
170
171 reponame="checkout-skip-dir-file-conflicts"
172 setup_remote_repo "$reponame"
173 clone_repo "$reponame" "$reponame"
174
175 gitscip-shell system . . git. lfs track "*.dat"
176
177 contents="a"
178 contents_oid="$(calc_oid "$contents")"
179 mkdirscip-shell system . . mkdir. -p dir1 dir2/dir3/dir4
180 printfscip-shell system . . printf. "%s" "$contents" >dir1/a.dat
181 printfscip-shell system . . printf. "%s" "$contents" >dir2/dir3/dir4/a.dat
182
183 gitscip-shell system . . git. add .gitattributes dir1 dir2
184 gitscip-shell system . . git. commit -m "initial commit"
185
186 rmscip-shell system . . rm. -rf dir1 dir2/dir3
187 touchscip-shell system . . touch. dir1 dir2/dir3
188
189 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
190 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
191 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
192 exit 1
193 fi
194 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
195 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
196
197 [scip-shell system . . `[`. -f "dir1" ]
198 [scip-shell system . . `[`. -f "dir2/dir3" ]
199 assert_clean_index
200
201 pushd dir2
202 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
203 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
204 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
205 exit 1
206 fi
207 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
208 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
209 popd
210
211 [scip-shell system . . `[`. -f "dir1" ]
212 [scip-shell system . . `[`. -f "dir2/dir3" ]
213 assert_clean_index
214 )
215 end_test
216
217 begin_test "checkout: skip directory symlink conflicts"
218 (
219 set -e
220
221 skip_if_symlinks_unsupported
222
223 reponame="checkout-skip-dir-symlink-conflicts"
224 setup_remote_repo "$reponame"
225 clone_repo "$reponame" "$reponame"
226
227 gitscip-shell system . . git. lfs track "*.dat"
228
229 contents="a"
230 contents_oid="$(calc_oid "$contents")"
231 mkdirscip-shell system . . mkdir. -p dir1 dir2/dir3/dir4
232 printfscip-shell system . . printf. "%s" "$contents" >dir1/a.dat
233 printfscip-shell system . . printf. "%s" "$contents" >dir2/dir3/dir4/a.dat
234
235 gitscip-shell system . . git. add .gitattributes dir1 dir2
236 gitscip-shell system . . git. commit -m "initial commit"
237
238 # test with symlinks to directories
239 rmscip-shell system . . rm. -rf dir1 dir2/dir3 ../link*
240 mkdirscip-shell system . . mkdir. ../link1 ../link2
241 lnscip-shell system . . ln. -s ../link1 dir1
242 lnscip-shell system . . ln. -s ../../link2 dir2/dir3
243
244 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
245 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
246 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
247 exit 1
248 fi
249 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
250 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
251 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "is beyond a symbolic link" checkout.log)" ]
252
253 [scip-shell system . . `[`. -L "dir1" ]
254 [scip-shell system . . `[`. -L "dir2/dir3" ]
255 [scip-shell system . . `[`. ! -e "../link1/a.dat" ]
256 [scip-shell system . . `[`. ! -e "../link2/dir4" ]
257 assert_clean_index
258
259 rmscip-shell system . . rm. -rf dir1 dir2/dir3
260 mkdirscip-shell system . . mkdir. link1 link2
261 lnscip-shell system . . ln. -s link1 dir1
262 lnscip-shell system . . ln. -s ../link2 dir2/dir3
263
264 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
265 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
266 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
267 exit 1
268 fi
269 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
270 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
271 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "is beyond a symbolic link" checkout.log)" ]
272
273 [scip-shell system . . `[`. -L "dir1" ]
274 [scip-shell system . . `[`. -L "dir2/dir3" ]
275 [scip-shell system . . `[`. ! -e "link1/a.dat" ]
276 [scip-shell system . . `[`. ! -e "link2/dir4" ]
277 assert_clean_index
278
279 pushd dir2
280 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
281 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
282 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
283 exit 1
284 fi
285 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
286 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
287 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "is beyond a symbolic link" checkout.log)" ]
288 popd
289
290 [scip-shell system . . `[`. -L "dir1" ]
291 [scip-shell system . . `[`. -L "dir2/dir3" ]
292 [scip-shell system . . `[`. ! -e "link1/a.dat" ]
293 [scip-shell system . . `[`. ! -e "link2/dir4" ]
294 assert_clean_index
295
296 # test with symlink to file and dangling symlink
297 rmscip-shell system . . rm. -rf dir1 dir2/dir3 ../link*
298 touchscip-shell system . . touch. ../link1
299 lnscip-shell system . . ln. -s ../link1 dir1
300 lnscip-shell system . . ln. -s ../../link2 dir2/dir3
301
302 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
303 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
304 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
305 exit 1
306 fi
307 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
308 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
309
310 [scip-shell system . . `[`. -L "dir1" ]
311 [scip-shell system . . `[`. -L "dir2/dir3" ]
312 [scip-shell system . . `[`. -f "../link1" ]
313 [scip-shell system . . `[`. ! -e "../link2" ]
314 assert_clean_index
315
316 rmscip-shell system . . rm. -rf dir1 dir2/dir3 link*
317 touchscip-shell system . . touch. link1
318 lnscip-shell system . . ln. -s link1 dir1
319 lnscip-shell system . . ln. -s ../link2 dir2/dir3
320
321 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
322 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
323 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
324 exit 1
325 fi
326 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
327 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
328
329 [scip-shell system . . `[`. -L "dir1" ]
330 [scip-shell system . . `[`. -L "dir2/dir3" ]
331 [scip-shell system . . `[`. -f "link1" ]
332 [scip-shell system . . `[`. ! -e "link2" ]
333 assert_clean_index
334
335 pushd dir2
336 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
337 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
338 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
339 exit 1
340 fi
341 grepscip-shell system . . grep. '"dir1/a\.dat": not a directory' checkout.log
342 grepscip-shell system . . grep. '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
343 popd
344
345 [scip-shell system . . `[`. -L "dir1" ]
346 [scip-shell system . . `[`. -L "dir2/dir3" ]
347 [scip-shell system . . `[`. -f "link1" ]
348 [scip-shell system . . `[`. ! -e "link2" ]
349 assert_clean_index
350 )
351 end_test
352
353 begin_test "checkout: skip file symlink conflicts"
354 (
355 set -e
356
357 skip_if_symlinks_unsupported
358
359 reponame="checkout-skip-file-symlink-conflicts"
360 setup_remote_repo "$reponame"
361 clone_repo "$reponame" "$reponame"
362
363 gitscip-shell system . . git. lfs track "*.dat"
364
365 contents="a"
366 contents_oid="$(calc_oid "$contents")"
367 mkdirscip-shell system . . mkdir. -p dir1/dir2/dir3
368 printfscip-shell system . . printf. "%s" "$contents" >a.dat
369 printfscip-shell system . . printf. "%s" "$contents" >dir1/dir2/dir3/a.dat
370
371 gitscip-shell system . . git. add .gitattributes a.dat dir1
372 gitscip-shell system . . git. commit -m "initial commit"
373
374 # test with symlinks to pointer files
375 rmscip-shell system . . rm. -rf a.dat dir1/dir2/dir3/a.dat ../link*
376 contents_pointer="$(gitscip-shell system . . git. cat-file -p ":a.dat")"
377 printfscip-shell system . . printf. "%s" "$contents_pointer" >../link1
378 printfscip-shell system . . printf. "%s" "$contents_pointer" >../link2
379 lnscip-shell system . . ln. -s ../link1 a.dat
380 lnscip-shell system . . ln. -s ../../../../link2 dir1/dir2/dir3/a.dat
381
382 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
383 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
384 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
385 exit 1
386 fi
387 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
388 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
389
390 [scip-shell system . . `[`. -L "a.dat" ]
391 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
392 [scip-shell system . . `[`. -f "../link1" ]
393 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. ../link1)" ]
394 [scip-shell system . . `[`. -f "../link2" ]
395 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. ../link2)" ]
396 assert_clean_index
397
398 rmscip-shell system . . rm. -rf a.dat dir1/dir2/dir3/a.dat link*
399 printfscip-shell system . . printf. "%s" "$contents_pointer" >link1
400 printfscip-shell system . . printf. "%s" "$contents_pointer" >link2
401 lnscip-shell system . . ln. -s link1 a.dat
402 lnscip-shell system . . ln. -s ../../../link2 dir1/dir2/dir3/a.dat
403
404 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
405 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
406 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
407 exit 1
408 fi
409 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
410 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
411
412 [scip-shell system . . `[`. -L "a.dat" ]
413 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
414 [scip-shell system . . `[`. -f "link1" ]
415 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. link1)" ]
416 [scip-shell system . . `[`. -f "link2" ]
417 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. link2)" ]
418 assert_clean_index
419
420 pushd dir1/dir2
421 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
422 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
423 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
424 exit 1
425 fi
426 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
427 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
428 popd
429
430 [scip-shell system . . `[`. -L "a.dat" ]
431 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
432 [scip-shell system . . `[`. -f "link1" ]
433 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. link1)" ]
434 [scip-shell system . . `[`. -f "link2" ]
435 [scip-shell system . . `[`. "$contents_pointer" = "$(catscip-shell system . . cat. link2)" ]
436 assert_clean_index
437
438 # test with symlink to directory and dangling symlink
439 rmscip-shell system . . rm. -rf a.dat dir1/dir2/dir3/a.dat ../link*
440 mkdirscip-shell system . . mkdir. ../link1
441 lnscip-shell system . . ln. -s ../link1 a.dat
442 lnscip-shell system . . ln. -s ../../../../link2 dir1/dir2/dir3/a.dat
443
444 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
445 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
446 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
447 exit 1
448 fi
449 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
450 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
451
452 [scip-shell system . . `[`. -L "a.dat" ]
453 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
454 [scip-shell system . . `[`. -d "../link1" ]
455 [scip-shell system . . `[`. ! -e "../link2" ]
456 assert_clean_index
457
458 rmscip-shell system . . rm. -rf a.dat dir1/dir2/dir3/a.dat link*
459 mkdirscip-shell system . . mkdir. link1
460 lnscip-shell system . . ln. -s link1 a.dat
461 lnscip-shell system . . ln. -s ../../../link2 dir1/dir2/dir3/a.dat
462
463 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
464 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
465 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
466 exit 1
467 fi
468 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
469 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
470
471 [scip-shell system . . `[`. -L "a.dat" ]
472 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
473 [scip-shell system . . `[`. -d "link1" ]
474 [scip-shell system . . `[`. ! -e "link2" ]
475 assert_clean_index
476
477 pushd dir1/dir2
478 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
479 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
480 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
481 exit 1
482 fi
483 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
484 grepscip-shell system . . grep. '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
485 popd
486
487 [scip-shell system . . `[`. -L "a.dat" ]
488 [scip-shell system . . `[`. -L "dir1/dir2/dir3/a.dat" ]
489 [scip-shell system . . `[`. -d "link1" ]
490 [scip-shell system . . `[`. ! -e "link2" ]
491 assert_clean_index
492 )
493 end_test
494
495 # This test applies to case-preserving but case-insensitive filesystems,
496 # such as APFS and NTFS when in their default configurations.
497 # On case-sensitive filesystems this test has no particular value and
498 # should always pass.
499 begin_test "checkout: skip case-based symlink conflicts"
500 (
501 set -e
502
503 skip_if_symlinks_unsupported
504
505 # Only test with Git version 2.20.0 as it introduced detection of
506 # case-insensitive filesystems to the "git clone" command, which the
507 # test depends on to determine the filesystem type.
508 ensure_git_version_isnt "$VERSION_LOWER" "2.20.0"
509
510 reponame="checkout-skip-case-symlink-conflicts"
511 setup_remote_repo "$reponame"
512 clone_repo "$reponame" "$reponame"
513
514 mkdirscip-shell system . . mkdir. dir1
515 lnscip-shell system . . ln. -s ../link1 A.dat
516 lnscip-shell system . . ln. -s ../../link2 dir1/a.dat
517 lnscip-shell system . . ln. -s ../link3 DIR3
518 lnscip-shell system . . ln. -s ../../link4 dir1/dir2
519
520 gitscip-shell system . . git. add A.dat dir1 DIR3
521 gitscip-shell system . . git. commit -m "initial commit"
522
523 rmscip-shell system . . rm. A.dat dir1/* DIR3
524
525 echoscip-shell system . . echo. "*.dat filter=lfs diff=lfs merge=lfs -text" >.gitattributes
526
527 contents="a"
528 contents_oid="$(calc_oid "$contents")"
529 mkdirscip-shell system . . mkdir. dir3 dir1/DIR2
530 printfscip-shell system . . printf. "%s" "$contents" >a.dat
531 printfscip-shell system . . printf. "%s" "$contents" >dir1/A.dat
532 printfscip-shell system . . printf. "%s" "$contents" >dir3/a.dat
533 printfscip-shell system . . printf. "%s" "$contents" >dir1/DIR2/a.dat
534
535 gitscip-shell system . . git. -c core.ignoreCase=false add .gitattributes a.dat dir1/A.dat \
536 dir3/a.dat dir1/DIR2/a.dat
537 gitscip-shell system . . git. commit -m "case-conflicting commit"
538
539 gitscip-shell system . . git. push origin main
540 assert_server_object "$reponame" "$contents_oid"
541
542 cd ..
543 GIT_LFS_SKIP_SMUDGE=1 gitscip-shell system . . git. clone "$GITSERVER/$reponame" "${reponame}-assert" 2>&1 | teescip-shell system . . tee. clone.log
544 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
545 echoscip-shell system . . echo. >&2 "fatal: expected clone to succeed ..."
546 exit 1
547 fi
548 collision="$(grepscip-shell system . . grep. -c "collided" clone.log)" || truescip-shell system . . true.
549
550 cd "${reponame}-assert"
551 gitscip-shell system . . git. lfs fetch origin main
552
553 assert_local_object "$contents_oid" 1
554
555 rmscip-shell system . . rm. -rf *.dat dir1 *3 ../link*
556 mkdirscip-shell system . . mkdir. ../link3 ../link4
557
558 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
559 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
560 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
561 exit 1
562 fi
563 grepscip-shell system . . grep. -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log
564
565 [scip-shell system . . `[`. -f "a.dat" ]
566 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "a.dat")" ]
567 [scip-shell system . . `[`. -f "dir1/A.dat" ]
568 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/A.dat")" ]
569 [scip-shell system . . `[`. -f "dir3/a.dat" ]
570 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir3/a.dat")" ]
571 [scip-shell system . . `[`. -f "dir1/DIR2/a.dat" ]
572 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/DIR2/a.dat")" ]
573 [scip-shell system . . `[`. ! -e "../link1" ]
574 [scip-shell system . . `[`. ! -e "../link2" ]
575 [scip-shell system . . `[`. ! -e "../link3/a.dat" ]
576 [scip-shell system . . `[`. ! -e "../link4/a.dat" ]
577 assert_clean_index
578
579 rmscip-shell system . . rm. -rf a.dat dir1/A.dat dir3 dir1/DIR2
580 gitscip-shell system . . git. checkout -- A.dat dir1/a.dat DIR3 dir1/dir2
581
582 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
583 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
584 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
585 exit 1
586 fi
587 if [scip-shell system . . `[`. "$collision" -eq "0" ]; then
588 # case-sensitive filesystem
589 grepscip-shell system . . grep. -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log
590 else
591 # case-insensitive filesystem
592 grepscip-shell system . . grep. '"a\.dat": not a regular file' checkout.log
593 grepscip-shell system . . grep. '"dir1/A\.dat": not a regular file' checkout.log
594 grepscip-shell system . . grep. '"dir3/a\.dat": not a directory' checkout.log
595 grepscip-shell system . . grep. '"dir1/DIR2/a\.dat": not a directory' checkout.log
596 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "is beyond a symbolic link" checkout.log)" ]
597 fi
598
599 if [scip-shell system . . `[`. "$collision" -eq "0" ]; then
600 # case-sensitive filesystem
601 [scip-shell system . . `[`. -f "a.dat" ]
602 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "a.dat")" ]
603 [scip-shell system . . `[`. -f "dir1/A.dat" ]
604 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/A.dat")" ]
605 [scip-shell system . . `[`. -f "dir3/a.dat" ]
606 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir3/a.dat")" ]
607 [scip-shell system . . `[`. -f "dir1/DIR2/a.dat" ]
608 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/DIR2/a.dat")" ]
609 else
610 # case-insensitive filesystem
611 [scip-shell system . . `[`. -L "a.dat" ]
612 [scip-shell system . . `[`. -L "dir1/A.dat" ]
613 [scip-shell system . . `[`. -L "dir3" ]
614 [scip-shell system . . `[`. -L "dir1/DIR2" ]
615 fi
616 [scip-shell system . . `[`. ! -e "../link1" ]
617 [scip-shell system . . `[`. ! -e "../link2" ]
618 [scip-shell system . . `[`. ! -e "../link3/a.dat" ]
619 [scip-shell system . . `[`. ! -e "../link4/a.dat" ]
620 assert_clean_index
621 )
622 end_test
623
624 begin_test "checkout: skip changed files"
625 (
626 set -e
627
628 reponame="checkout-skip-changed-files"
629 setup_remote_repo "$reponame"
630 clone_repo "$reponame" "$reponame"
631
632 gitscip-shell system . . git. lfs track "*.dat"
633
634 contents="a"
635 contents_oid="$(calc_oid "$contents")"
636 printfscip-shell system . . printf. "%s" "$contents" >a.dat
637
638 gitscip-shell system . . git. add .gitattributes a.dat
639 gitscip-shell system . . git. commit -m "initial commit"
640
641 contents_new="$contents +extra"
642 printfscip-shell system . . printf. "%s" "$contents_new" >a.dat
643
644 gitscip-shell system . . git. lfs checkout
645
646 [scip-shell system . . `[`. "$contents_new" = "$(catscip-shell system . . cat. a.dat)" ]
647 assert_clean_index
648
649 rmscip-shell system . . rm. a.dat
650 mkdirscip-shell system . . mkdir. a.dat
651
652 gitscip-shell system . . git. lfs checkout
653
654 [scip-shell system . . `[`. -d "a.dat" ]
655 assert_clean_index
656
657 pushd a.dat
658 gitscip-shell system . . git. lfs checkout
659 popd
660
661 [scip-shell system . . `[`. -d "a.dat" ]
662 assert_clean_index
663 )
664 end_test
665
666 begin_test "checkout: break hard links to existing files"
667 (
668 set -e
669
670 reponame="checkout-break-file-hardlinks"
671 setup_remote_repo "$reponame"
672 clone_repo "$reponame" "$reponame"
673
674 gitscip-shell system . . git. lfs track "*.dat"
675
676 contents="a"
677 contents_oid="$(calc_oid "$contents")"
678 mkdirscip-shell system . . mkdir. -p dir1/dir2/dir3
679 printfscip-shell system . . printf. "%s" "$contents" >a.dat
680 printfscip-shell system . . printf. "%s" "$contents" >dir1/dir2/dir3/a.dat
681
682 gitscip-shell system . . git. add .gitattributes a.dat dir1
683 gitscip-shell system . . git. commit -m "initial commit"
684
685 gitscip-shell system . . git. push origin main
686 assert_server_object "$reponame" "$contents_oid"
687
688 cd ..
689 GIT_LFS_SKIP_SMUDGE=1 gitscip-shell system . . git. clone "$GITSERVER/$reponame" "${reponame}-assert"
690
691 cd "${reponame}-assert"
692 gitscip-shell system . . git. lfs fetch origin main
693
694 assert_local_object "$contents_oid" 1
695
696 rmscip-shell system . . rm. -f a.dat dir1/dir2/dir3/a.dat ../link
697 pointer="$(gitscip-shell system . . git. cat-file -p ":a.dat")"
698 echoscip-shell system . . echo. "$pointer" >../link
699 lnscip-shell system . . ln. ../link a.dat
700 lnscip-shell system . . ln. ../link dir1/dir2/dir3/a.dat
701
702 gitscip-shell system . . git. lfs checkout
703
704 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. a.dat)" ]
705 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. dir1/dir2/dir3/a.dat)" ]
706 [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. ../link)" ]
707 assert_clean_status
708
709 rmscip-shell system . . rm. a.dat dir1/dir2/dir3/a.dat
710 lnscip-shell system . . ln. ../link a.dat
711 lnscip-shell system . . ln. ../link dir1/dir2/dir3/a.dat
712
713 pushd dir1/dir2
714 gitscip-shell system . . git. lfs checkout
715 popd
716
717 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. a.dat)" ]
718 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. dir1/dir2/dir3/a.dat)" ]
719 [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. ../link)" ]
720 assert_clean_status
721 )
722 end_test
723
724 begin_test "checkout: without clean filter"
725 (
726 set -e
727
728 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
729 gitscip-shell system . . git. lfs uninstall
730
731 gitscip-shell system . . git. clone "$GITSERVER/$reponame" checkout-without-clean
732 cd checkout-without-clean
733
734 echoscip-shell system . . echo. "checkout without clean filter"
735 gitscip-shell system . . git. lfs uninstall
736 gitscip-shell system . . git. config --list > config.txt
737 grepscip-shell system . . grep. "filter.lfs.clean" config.txt && {
738 echoscip-shell system . . echo. "clean filter still configured:"
739 catscip-shell system . . cat. config.txt
740 exit 1
741 }
742 lsscip-shell system . . ls. -al
743
744 gitscip-shell system . . git. lfs checkout | teescip-shell system . . tee. checkout.txt
745 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
746 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
747 exit 1
748 fi
749 grepscip-shell system . . grep. "Git LFS is not installed" checkout.txt
750
751 contentsize=19
752 contents_oid=$(calc_oid "something something")
753 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file1.dat)" ]
754 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file2.dat)" ]
755 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. file3.dat)" ]
756 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. folder1/nested.dat)" ]
757 [scip-shell system . . `[`. "$(pointer $contents_oid $contentsize)" = "$(catscip-shell system . . cat. folder2/folder3/folder4/nested.dat)" ]
758 )
759 end_test
760
761 begin_test "checkout: outside git repository"
762 (
763 set +e
764 gitscip-shell system . . git. lfs checkout 2>&1 > checkout.log
765 res=$?
766
767 set -e
768 if [scip-shell system . . `[`. "$res" = "0" ]; then
769 echoscip-shell system . . echo. "Passes because $GIT_LFS_TEST_DIR is unset."
770 exit 0
771 fi
772 [scip-shell system . . `[`. "$res" = "128" ]
773 grepscip-shell system . . grep. "Not in a Git repository" checkout.log
774 )
775 end_test
776
777 begin_test "checkout: read-only directory"
778 (
779 set -e
780
781 skip_if_root_or_admin "$test_description"
782
783 reponame="checkout-read-only"
784 gitscip-shell system . . git. init "$reponame"
785 cd "$reponame"
786
787 gitscip-shell system . . git. lfs track "*.bin"
788
789 contents="a"
790 contents_oid=$(calc_oid "$contents")
791 mkdirscip-shell system . . mkdir. dir
792 printfscip-shell system . . printf. "%s" "$contents" > dir/a.bin
793
794 gitscip-shell system . . git. add .gitattributes dir/a.bin
795 gitscip-shell system . . git. commit -m "add dir/a.bin"
796
797 rmscip-shell system . . rm. dir/a.bin
798
799 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
800 icacls dir /inheritance:rscip-shell filesystem . . `/inheritance:r`.
801 icacls dir /grant:rscip-shell filesystem . . `/grant:r`. Everyone:R
802 else
803 chmodscip-shell system . . chmod. a-w dir
804 fi
805 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
806 # Note that although the checkout command should log an error, at present
807 # we still expect a zero exit code.
808 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
809 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs checkout' to succeed ..."
810 exit 1
811 fi
812
813 assert_local_object "$contents_oid" 1
814
815 [scip-shell system . . `[`. ! -e dir/a.bin ]
816
817 grepscip-shell system . . grep. 'could not check out "dir/a.bin"' checkout.log
818 grepscip-shell system . . grep. 'could not create working directory file' checkout.log
819 grepscip-shell system . . grep. 'permission denied' checkout.log
820 )
821 end_test
822
823 begin_test "checkout: read-only file"
824 (
825 set -e
826
827 reponame="checkout-locked"
828 filename="a.txt"
829
830 setup_remote_repo_with_file "$reponame" "$filename"
831 contents_oid="$(calc_oid_file "$filename")"
832
833 pushd "$TRASHDIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
834 GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}-assert"
835
836 chmodscip-shell system . . chmod. a-w "$filename"
837
838 refute_file_writeable "$filename"
839 assert_pointer "refs/heads/main" "$filename" "$contents_oid" 6
840
841 gitscip-shell system . . git. lfs fetch
842 gitscip-shell system . . git. lfs checkout "$filename"
843
844 refute_file_writeable "$filename"
845 [scip-shell system . . `[`. "$filename" = "$(catscip-shell system . . cat. "$filename")" ]
846 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
847 )
848 end_test
849
850 begin_test "checkout with empty file doesn't modify mtime"
851 (
852 set -e
853 gitscip-shell system . . git. init checkout-empty-file
854 cd checkout-empty-file
855
856 gitscip-shell system . . git. lfs track "*.bin"
857 gitscip-shell system . . git. add .
858 gitscip-shell system . . git. commit -m 'gitattributes'
859 printfscip-shell system . . printf. abc > abc.bin
860 gitscip-shell system . . git. add .
861 gitscip-shell system . . git. commit -m 'abc'
862
863 touchscip-shell system . . touch. foo.bin
864 lfstest-nanomtime foo.bin >foo.mtime
865
866 # This isn't necessary, but it takes a few cycles to make sure that our
867 # timestamp changes.
868 gitscip-shell system . . git. add foo.bin
869 gitscip-shell system . . git. commit -m 'foo'
870
871 gitscip-shell system . . git. lfs checkout
872 lfstest-nanomtime foo.bin >foo.mtime2
873 diffscip-shell system . . diff. -u foo.mtime foo.mtime2
874 )
875 end_test
876
877 begin_test "checkout: conflicts"
878 (
879 set -e
880
881 reponame="checkout-conflicts"
882 filename="file1.dat"
883
884 setup_remote_repo_with_file "$reponame" "$filename"
885
886 pushd "$TRASHDIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
887 clone_repo "$reponame" "${reponame}_checkout"
888
889 gitscip-shell system . . git. tag base
890 gitscip-shell system . . git. checkout -b first
891 echoscip-shell system . . echo. "abc123" > file1.dat
892 gitscip-shell system . . git. add -u
893 echoscip-shell system . . echo. "first" > other.txt
894 gitscip-shell system . . git. add other.txt
895 gitscip-shell system . . git. commit -m "first"
896
897 gitscip-shell system . . git. lfs checkout --to base.txt 2>&1 | teescip-shell system . . tee. output.txt
898 grepscip-shell system . . grep. -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
899
900 gitscip-shell system . . git. lfs checkout --base 2>&1 | teescip-shell system . . tee. output.txt
901 grepscip-shell system . . grep. -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
902
903 gitscip-shell system . . git. lfs checkout --to base.txt --ours --theirs 2>&1 | teescip-shell system . . tee. output.txt
904 grepscip-shell system . . grep. -- 'at most one of --base, --theirs, and --ours is allowed' output.txt
905
906 gitscip-shell system . . git. lfs checkout --to base.txt --base 2>&1 | teescip-shell system . . tee. output.txt
907 grepscip-shell system . . grep. -- '--to requires exactly one Git LFS object file path' output.txt
908
909 gitscip-shell system . . git. lfs checkout --to base.txt --base 2>&1 abc def | teescip-shell system . . tee. output.txt
910 grepscip-shell system . . grep. -- '--to requires exactly one Git LFS object file path' output.txt
911
912 gitscip-shell system . . git. lfs checkout --to base.txt --base file1.dat 2>&1 | teescip-shell system . . tee. output.txt
913 grepscip-shell system . . grep. 'Could not checkout.*not in the middle of a merge' output.txt
914
915 gitscip-shell system . . git. checkout -b second main
916 echoscip-shell system . . echo. "def456" > file1.dat
917 gitscip-shell system . . git. add -u
918 echoscip-shell system . . echo. "second" > other.txt
919 gitscip-shell system . . git. add other.txt
920 gitscip-shell system . . git. commit -m "second"
921
922 # This will cause a conflict.
923 gitscip-shell system . . git. merge first && exit 1
924
925 abs_assert_dir="$(canonical_path "$TRASHDIR/${reponame}-assert")"
926 abs_theirs_file="$abs_assert_dir/dir1/dir2/theirs.txt"
927
928 rmscip-shell system . . rm. -rf "$abs_assert_dir"
929
930 gitscip-shell system . . git. lfs checkout --to base.txt --base file1.dat
931 gitscip-shell system . . git. lfs checkout --to ../ours.txt --ours file1.dat
932 gitscip-shell system . . git. lfs checkout --to "$abs_theirs_file" --theirs file1.dat
933
934 echoscip-shell system . . echo. "file1.dat" | cmpscip-shell system . . cmp. - base.txt
935 echoscip-shell system . . echo. "def456" | cmpscip-shell system . . cmp. - ../ours.txt
936 echoscip-shell system . . echo. "abc123" | cmpscip-shell system . . cmp. - "$abs_theirs_file"
937
938 rmscip-shell system . . rm. -rf base.txt ../ours.txt "$abs_assert_dir"
939 mkdirscip-shell system . . mkdir. -p dir1/dir2
940
941 pushd dir1/dir2
942 gitscip-shell system . . git. lfs checkout --to base.txt --base ../../file1.dat
943 gitscip-shell system . . git. lfs checkout --to ../../../ours.txt --ours ../../file1.dat
944 gitscip-shell system . . git. lfs checkout --to "$abs_theirs_file" --theirs ../../file1.dat
945 popd
946
947 echoscip-shell system . . echo. "file1.dat" | cmpscip-shell system . . cmp. - dir1/dir2/base.txt
948 echoscip-shell system . . echo. "def456" | cmpscip-shell system . . cmp. - ../ours.txt
949 echoscip-shell system . . echo. "abc123" | cmpscip-shell system . . cmp. - "$abs_theirs_file"
950
951 has_native_symlinks && {
952 rmscip-shell system . . rm. -rf "$abs_assert_dir"
953 mkdirscip-shell system . . mkdir. -p "$abs_assert_dir/link1"
954 lnscip-shell system . . ln. -s link1 "$abs_assert_dir/dir1"
955
956 gitscip-shell system . . git. lfs checkout --to "$abs_theirs_file" --theirs file1.dat
957
958 [scip-shell system . . `[`. -L "$abs_assert_dir/dir1" ]
959 echoscip-shell system . . echo. "abc123" | cmpscip-shell system . . cmp. - "$abs_assert_dir/link1/dir2/theirs.txt"
960
961 rmscip-shell system . . rm. -f base.txt link1 ../ours.txt ../link2
962 lnscip-shell system . . ln. -s link1 base.txt
963 lnscip-shell system . . ln. -s link2 ../ours.txt
964
965 gitscip-shell system . . git. lfs checkout --to base.txt --base file1.dat
966 gitscip-shell system . . git. lfs checkout --to ../ours.txt --ours file1.dat
967
968 [scip-shell system . . `[`. ! -L "base.txt" ]
969 [scip-shell system . . `[`. ! -L "../ours.txt" ]
970 [scip-shell system . . `[`. ! -e "link1" ]
971 [scip-shell system . . `[`. ! -e "../link2" ]
972 echoscip-shell system . . echo. "file1.dat" | cmpscip-shell system . . cmp. - base.txt
973 echoscip-shell system . . echo. "def456" | cmpscip-shell system . . cmp. - ../ours.txt
974 }
975
976 rmscip-shell system . . rm. -f base.txt link1 ../ours.txt ../link2
977 printfscip-shell system . . printf. "link1" >link1
978 printfscip-shell system . . printf. "link2" >../link2
979 lnscip-shell system . . ln. link1 base.txt
980 lnscip-shell system . . ln. ../link2 ../ours.txt
981
982 gitscip-shell system . . git. lfs checkout --to base.txt --base file1.dat
983 gitscip-shell system . . git. lfs checkout --to ../ours.txt --ours file1.dat
984
985 [scip-shell system . . `[`. -f "link1" ]
986 [scip-shell system . . `[`. -f "../link2" ]
987 [scip-shell system . . `[`. "link1" = "$(catscip-shell system . . cat. link1)" ]
988 [scip-shell system . . `[`. "link2" = "$(catscip-shell system . . cat. ../link2)" ]
989 echoscip-shell system . . echo. "file1.dat" | cmpscip-shell system . . cmp. - base.txt
990 echoscip-shell system . . echo. "def456" | cmpscip-shell system . . cmp. - ../ours.txt
991
992 gitscip-shell system . . git. lfs checkout --to base.txt --ours other.txt 2>&1 | teescip-shell system . . tee. output.txt
993 grepscip-shell system . . grep. 'Could not find decoder pointer for object' output.txt
994
995 gitscip-shell system . . git. lfs checkout --to base.txt --ours . 2>&1 | teescip-shell system . . tee. output.txt
996 grepscip-shell system . . grep. "Could not checkout .*: Git can't resolve ref: \":2:\.\"" output.txt
997 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
998 )
999 end_test
1000
1001 begin_test "checkout: GIT_WORK_TREE"
1002 (
1003 set -e
1004
1005 reponame="checkout-work-tree"
1006 remotename="$(basenamescip-shell system . . basename. "$0" ".sh")"
1007 export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git"
1008 mkdirscip-shell system . . mkdir. "$GIT_WORK_TREE" "$GIT_DIR"
1009 gitscip-shell system . . git. init
1010 gitscip-shell system . . git. remote add origin "$GITSERVER/$remotename"
1011
1012 gitscip-shell system . . git. lfs uninstall --skip-repo
1013
1014 gitscip-shell system . . git. fetch origin
1015 gitscip-shell system . . git. checkout -B main origin/main
1016
1017 gitscip-shell system . . git. lfs install
1018 gitscip-shell system . . git. lfs fetch
1019 gitscip-shell system . . git. lfs checkout
1020
1021 contents="something something"
1022 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "$reponame/file1.dat")" ]
1023 )
1024 end_test
1025
1026 begin_test "checkout: bare repository"
1027 (
1028 set -e
1029
1030 reponame="checkout-bare"
1031 gitscip-shell system . . git. init --bare "$reponame"
1032 cd "$reponame"
1033
1034 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
1035 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
1036 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
1037 exit 1
1038 fi
1039 [scip-shell system . . `[`. "This operation must be run in a work tree." = "$(catscip-shell system . . cat. checkout.log)" ]
1040 )
1041 end_test
1042
1043 begin_test "checkout: sparse with partial clone and sparse index"
1044 (
1045 set -e
1046
1047 # Only test with Git version 2.25.0 as it introduced the
1048 # "git sparse-checkout" command. (Note that this test also requires
1049 # that the "git rev-list" command support the "tree:0" filter, which
1050 # was introduced with Git version 2.20.0.)
1051 ensure_git_version_isnt "$VERSION_LOWER" "2.25.0"
1052
1053 reponame="checkout-sparse"
1054 setup_remote_repo "$reponame"
1055 clone_repo "$reponame" "$reponame"
1056
1057 gitscip-shell system . . git. lfs track "*.dat"
1058
1059 contents1="a"
1060 contents1_oid=$(calc_oid "$contents1")
1061 contents2="b"
1062 contents2_oid=$(calc_oid "$contents2")
1063 contents3="c"
1064 contents3_oid=$(calc_oid "$contents3")
1065
1066 mkdirscip-shell system . . mkdir. in-dir out-dir
1067 printfscip-shell system . . printf. "%s" "$contents1" >a.dat
1068 printfscip-shell system . . printf. "%s" "$contents2" >in-dir/b.dat
1069 printfscip-shell system . . printf. "%s" "$contents3" >out-dir/c.dat
1070 gitscip-shell system . . git. add .
1071 gitscip-shell system . . git. commit -m "add files"
1072
1073 gitscip-shell system . . git. push origin main
1074
1075 assert_server_object "$reponame" "$contents1_oid"
1076 assert_server_object "$reponame" "$contents2_oid"
1077 assert_server_object "$reponame" "$contents3_oid"
1078
1079 # Create a partial clone with a cone-mode sparse checkout of one directory
1080 # and a sparse index, which is important because otherwise the "git ls-files"
1081 # command ignores the --sparse option and lists all Git LFS files.
1082 cd ..
1083 giscip-shell system . . git.tscip-shell system . . git. clone --filter=tree:0 --depth=1 --no-checkout \
1084 "$GITSERVER/$reponame" "${reponame}-partial"
1085
1086 cd "${reponame}-partial"
1087 gitscip-shell system . . git. sparse-checkout init --cone --sparse-index
1088 gitscip-shell system . . git. sparse-checkout set "in-dir"
1089 gitscip-shell system . . git. checkout main
1090
1091 [scip-shell system . . `[`. -d "in-dir" ]
1092 [scip-shell system . . `[`. ! -e "out-dir" ]
1093
1094 assert_local_object "$contents1_oid" 1
1095 assert_local_object "$contents2_oid" 1
1096 refute_local_object "$contents3_oid"
1097
1098 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
1099 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
1100 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
1101 exit 1
1102 fi
1103
1104 # When Git version 2.42.0 or higher is available, the "git lfs checkout"
1105 # command will use the "git ls-files" command rather than the
1106 # "git ls-tree" command to list files. Git v2.42.0 introduced support
1107 # in the "git ls-files" command for the "objecttype" format option and
1108 # so Git LFS can use this command to avoid checking out objects outside
1109 # the sparse cone. Otherwise, all Git LFS objects will be checked out.
1110 gitversion="$(gitscip-shell system . . git. version | cutscip-shell system . . cut. -d" " -f3)"
1111 set +e
1112 compare_version "$gitversion" '2.42.0'
1113 result=$?
1114 set -e
1115 if [scip-shell system . . `[`. "$result" -eq "$VERSION_LOWER" ]; then
1116 grepscip-shell system . . grep. 'Skipped checkout for "out-dir/c.dat"' checkout.log
1117
1118 [scip-shell system . . `[`. -f "out-dir/c.dat" ]
1119 [scip-shell system . . `[`. "$(pointer $contents3_oid 1)" = "$(catscip-shell system . . cat. "out-dir/c.dat")" ]
1120 else
1121 grepscip-shell system . . grep. -q 'Skipped checkout for "out-dir/c.dat"' checkout.log && exit 1
1122
1123 [scip-shell system . . `[`. ! -e "out-dir/c.dat" ]
1124 fi
1125
1126 # Fetch all Git LFS objects, including those outside the sparse cone.
1127 gitscip-shell system . . git. lfs fetch origin main
1128
1129 assert_local_object "$contents3_oid" 1
1130
1131 gitscip-shell system . . git. lfs checkout 2>&1 | teescip-shell system . . tee. checkout.log
1132 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
1133 echoscip-shell system . . echo. >&2 "fatal: expected checkout to succeed ..."
1134 exit 1
1135 fi
1136
1137 if [scip-shell system . . `[`. "$result" -eq "$VERSION_LOWER" ]; then
1138 grepscip-shell system . . grep. 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log
1139
1140 [scip-shell system . . `[`. -f "out-dir/c.dat" ]
1141 [scip-shell system . . `[`. "$contents3" = "$(catscip-shell system . . cat. "out-dir/c.dat")" ]
1142 else
1143 grepscip-shell system . . grep. -q 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log && exit 1
1144
1145 [scip-shell system . . `[`. ! -e "out-dir/c.dat" ]
1146 fi
1147 )
1148 end_test
1149
1150 begin_test "checkout: pointer extension"
1151 (
1152 set -e
1153
1154 reponame="checkout-pointer-extension"
1155 setup_remote_repo "$reponame"
1156 clone_repo "$reponame" "$reponame"
1157
1158 gitscip-shell system . . git. lfs track "*.dat"
1159
1160 setup_case_inverter_extension
1161
1162 contents="abc"
1163 inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
1164 mkdirscip-shell system . . mkdir. dir1
1165 printfscip-shell system . . printf. "%s" "$contents" >dir1/abc.dat
1166
1167 gitscip-shell system . . git. add .gitattributes dir1
1168 gitscip-shell system . . git. commit -m "initial commit"
1169
1170 assert_local_object "$inverted_contents_oid" 3
1171
1172 rmscip-shell system . . rm. -rf dir1 "$LFSTEST_EXT_LOG"
1173 gitscip-shell system . . git. lfs checkout
1174
1175 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/abc.dat")" ]
1176 grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
1177
1178 rmscip-shell system . . rm. -rf dir1 "$LFSTEST_EXT_LOG"
1179 mkdirscip-shell system . . mkdir. dir2
1180
1181 pushd dir2
1182 gitscip-shell system . . git. lfs checkout
1183 popd
1184
1185 [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/abc.dat")" ]
1186 grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
1187 )
1188 end_test
1189
1190 begin_test "checkout: pointer extension with conflict"
1191 (
1192 set -e
1193
1194 reponame="checkout-pointer-extension-conflict"
1195 setup_remote_repo "$reponame"
1196 clone_repo "$reponame" "$reponame"
1197
1198 gitscip-shell system . . git. lfs track "*.dat"
1199
1200 setup_case_inverter_extension
1201
1202 contents="abc"
1203 inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
1204 mkdirscip-shell system . . mkdir. dir1
1205 printfscip-shell system . . printf. "%s" "$contents" >dir1/abc.dat
1206
1207 gitscip-shell system . . git. add .gitattributes dir1
1208 gitscip-shell system . . git. commit -m "initial commit"
1209
1210 assert_local_object "$inverted_contents_oid" 3
1211
1212 gitscip-shell system . . git. checkout -b theirs
1213 contents_theirs="Abc"
1214 printfscip-shell system . . printf. "%s" "$contents_theirs" >dir1/abc.dat
1215 gitscip-shell system . . git. add dir1
1216 gitscip-shell system . . git. commit -m "theirs"
1217
1218 gitscip-shell system . . git. checkout main
1219 contents_ours="aBc"
1220 printfscip-shell system . . printf. "%s" "$contents_ours" >dir1/abc.dat
1221 gitscip-shell system . . git. add dir1
1222 gitscip-shell system . . git. commit -m "ours"
1223
1224 gitscip-shell system . . git. merge theirs && exit 1
1225
1226 rmscip-shell system . . rm. -f "$LFSTEST_EXT_LOG"
1227
1228 gitscip-shell system . . git. lfs checkout --to base.txt --base dir1/abc.dat
1229
1230 printfscip-shell system . . printf. "%s" "$contents" | cmpscip-shell system . . cmp. - base.txt
1231 grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
1232
1233 rmscip-shell system . . rm. -f "$LFSTEST_EXT_LOG"
1234
1235 pushd dir1
1236 gitscip-shell system . . git. lfs checkout --to ../ours.txt --ours abc.dat
1237 popd
1238
1239 printfscip-shell system . . printf. "%s" "$contents_ours" | cmpscip-shell system . . cmp. - ours.txt
1240 grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
1241
1242 abs_assert_dir="$TRASHDIR/${reponame}-assert"
1243 abs_theirs_file="$(canonical_path "$abs_assert_dir/dir1/dir2/theirs.txt")"
1244
1245 rmscip-shell system . . rm. -rf "$abs_assert_dir" "$LFSTEST_EXT_LOG"
1246 mkdirscip-shell system . . mkdir. dir2
1247
1248 pushd dir2
1249 gitscip-shell system . . git. lfs checkout --to "$abs_theirs_file" --theirs ../dir1/abc.dat
1250 popd
1251
1252 printfscip-shell system . . printf. "%s" "$contents_theirs" | cmpscip-shell system . . cmp. - "$abs_theirs_file"
1253 grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
1254 )
1255 end_test