Debian Codegraph @

t/t-fetch.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 contents="a"
6 contents_oid=$(calc_oid "$contents")
7 b="b"
8 b_oid=$(calc_oid "$b")
9 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
10
11 begin_test "init for fetch tests"
12 (
13 set -e
14
15 setup_remote_repo "$reponame"
16
17 clone_repo "$reponame" repo
18
19 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
20 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
21
22
23 printfscip-shell system . . printf. "%s" "$contents" > a.dat
24 gitscip-shell system . . git. add a.dat
25 gitscip-shell system . . git. add .gitattributes
26 gitscip-shell system . . git. commit -m "add a.dat" 2>&1 | teescip-shell system . . tee. commit.log
27 grepscip-shell system . . grep. "main (root-commit)" commit.log
28 grepscip-shell system . . grep. "2 files changed" commit.log
29 grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log
30 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
31
32 [scip-shell system . . `[`. "a" = "$(catscip-shell system . . cat. a.dat)" ]
33
34 assert_local_object "$contents_oid" 1
35
36 refute_server_object "$reponame" "$contents_oid"
37
38 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
39 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
40 grepscip-shell system . . grep. "main -> main" push.log
41
42 assert_server_object "$reponame" "$contents_oid"
43
44 # Add an empty file
45 touchscip-shell system . . touch. empty.dat
46 gitscip-shell system . . git. add empty.dat
47 gitscip-shell system . . git. commit -m 'empty'
48
49 # Add a file in a different branch
50 gitscip-shell system . . git. checkout -b newbranch
51 printfscip-shell system . . printf. "%s" "$b" > b.dat
52 gitscip-shell system . . git. add b.dat
53 gitscip-shell system . . git. commit -m "add b.dat"
54 assert_local_object "$b_oid" 1
55
56 gitscip-shell system . . git. push origin newbranch
57 assert_server_object "$reponame" "$b_oid"
58
59 # These clones are used for subsequent tests
60 clone_repo "$reponame" clone
61 gitscip-shell system . . git. clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared"
62 )
63 end_test
64
65 begin_test "fetch"
66 (
67 set -e
68 cd clone
69 rmscip-shell system . . rm. -rf .git/lfs/objects
70
71 gitscip-shell system . . git. lfs fetch --dry-run 2>&1 | teescip-shell system . . tee. fetch.log
72 grepscip-shell system . . grep. "fetch $contents_oid => a\.dat" fetch.log
73 refute_local_object "$contents_oid"
74
75 gitscip-shell system . . git. lfs fetch
76 assert_local_object "$contents_oid" 1
77
78 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
79 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
80
81 gitscip-shell system . . git. lfs fetch --dry-run 2>&1 | teescip-shell system . . tee. fetch.log
82 grepscip-shell system . . grep. "fetch .* => a\.dat" fetch.log && exit 1 || truescip-shell system . . true.
83 )
84 end_test
85
86 begin_test "fetch --json"
87 (
88 set -e
89 cd clone
90 rmscip-shell system . . rm. -rf .git/lfs/objects
91
92 gitscip-shell system . . git. lfs fetch --dry-run --json | teescip-shell system . . tee. fetch-dry-run.json
93 gitscip-shell system . . git. lfs fetch --json | teescip-shell system . . tee. fetch.json
94 assert_local_object "$contents_oid" 1
95 catscip-shell system . . cat. > expected.json <<-EOF
96 {
97 "transfers": [
98 {
99 "name": "a.dat",
100 "oid": "$contents_oid",
101 "size": 1,
102 "actions": {
103 "download": {
104 "href": "$GITSERVER/storage/$contents_oid?r=$reponame",
105 "expires_at": "0001-01-01T00:00:00Z"
106 }
107 },
108 "path": "$(native_path_escaped "$(local_object_path "$contents_oid")")"
109 }
110 ]
111 }
112 EOF
113 diffscip-shell system . . diff. -u expected.json fetch-dry-run.json
114 diffscip-shell system . . diff. -u expected.json fetch.json
115
116 gitscip-shell system . . git. lfs fetch --json | teescip-shell system . . tee. fetch.json
117 catscip-shell system . . cat. > expected.json <<-EOF
118 {
119 "transfers": []
120 }
121 EOF
122 diffscip-shell system . . diff. -u expected.json fetch.json
123 )
124 end_test
125
126 begin_test "fetch --refetch"
127 (
128 set -e
129 cd clone
130 rmscip-shell system . . rm. -rf .git/lfs/objects
131
132 gitscip-shell system . . git. lfs fetch
133 assert_local_object "$contents_oid" 1
134
135 corrupt_local_object "$contents_oid"
136 refute_local_object "$contents_oid" 1
137
138 gitscip-shell system . . git. lfs fetch --refetch
139 assert_local_object "$contents_oid" 1
140
141 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
142 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
143 )
144 end_test
145
146 begin_test "fetch (shared repository)"
147 (
148 set -e
149 cd shared
150 rmscip-shell system . . rm. -rf .git/lfs/objects
151
152 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
153 grepscip-shell system . . grep. "Could not scan" fetch.log && exit 1
154 assert_local_object "$contents_oid" 1
155
156 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
157 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
158 )
159 end_test
160
161 begin_test "fetch with remote"
162 (
163 set -e
164 cd clone
165 rmscip-shell system . . rm. -rf .git/lfs/objects
166
167 gitscip-shell system . . git. lfs fetch origin
168 assert_local_object "$contents_oid" 1
169 refute_local_object "$b_oid" 1
170
171 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
172 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
173 )
174 end_test
175
176 begin_test "fetch with remote and branches"
177 (
178 set -e
179 cd clone
180
181 gitscip-shell system . . git. checkout newbranch
182 gitscip-shell system . . git. checkout main
183
184 rmscip-shell system . . rm. -rf .git/lfs/objects
185
186 gitscip-shell system . . git. lfs fetch origin main newbranch --dry-run 2>&1 | teescip-shell system . . tee. fetch.log
187 grepscip-shell system . . grep. "fetch $contents_oid => a\.dat" fetch.log
188 grepscip-shell system . . grep. "fetch $b_oid => b\.dat" fetch.log
189 refute_local_object "$contents_oid"
190 refute_local_object "$b_oid"
191
192 gitscip-shell system . . git. lfs fetch origin main newbranch
193 assert_local_object "$contents_oid" 1
194 assert_local_object "$b_oid" 1
195
196 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
197 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
198
199 gitscip-shell system . . git. lfs fetch origin main newbranch --dry-run | teescip-shell system . . tee. fetch.log
200 grepscip-shell system . . grep. "fetch .* => [ab]\.dat" fetch.log && exit 1 || truescip-shell system . . true.
201
202 rmscip-shell system . . rm. -rf .git/lfs/objects
203
204 printfscip-shell system . . printf. "main\nnewbranch\n" | gitscip-shell system . . git. lfs fetch origin --stdin --dry-run 2>&1 | teescip-shell system . . tee. fetch.log
205 grepscip-shell system . . grep. "fetch $contents_oid => a\.dat" fetch.log
206 grepscip-shell system . . grep. "fetch $b_oid => b\.dat" fetch.log
207 refute_local_object "$contents_oid"
208 refute_local_object "$b_oid"
209
210 printfscip-shell system . . printf. "main\nnewbranch\n" | gitscip-shell system . . git. lfs fetch origin --stdin
211 assert_local_object "$contents_oid" 1
212 assert_local_object "$b_oid" 1
213
214 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
215 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
216
217 gitscip-shell system . . git. lfs fetch origin main newbranch --dry-run | teescip-shell system . . tee. fetch.log
218 grepscip-shell system . . grep. "fetch .* => [ab]\.dat" fetch.log && exit 1 || truescip-shell system . . true.
219 )
220 end_test
221
222 begin_test "fetch --json with remote and branches"
223 (
224 set -e
225 cd clone
226
227 gitscip-shell system . . git. checkout newbranch
228 gitscip-shell system . . git. checkout main
229
230 rmscip-shell system . . rm. -rf .git/lfs/objects
231
232 gitscip-shell system . . git. lfs fetch origin main newbranch --json --dry-run | teescip-shell system . . tee. fetch-dry-run.json
233 refute_local_object "$contents_oid"
234 refute_local_object "$b_oid"
235
236 gitscip-shell system . . git. lfs fetch origin main newbranch --json | teescip-shell system . . tee. fetch.json
237 assert_local_object "$contents_oid" 1
238 assert_local_object "$b_oid" 1
239
240 # Check the JSON output, without enforcing order between a.dat and b.dat
241 expected_a='{
242 "name": "a.dat",
243 "oid": "'$contents_oid'",
244 "size": 1,
245 "actions": {
246 "download": {
247 "href": "'$GITSERVER'/storage/'$contents_oid'?r='$reponame'",
248 "expires_at": "0001-01-01T00:00:00Z"
249 }
250 },
251 "path": "'$(native_path_escaped "$(local_object_path "$contents_oid")")'"
252 }'
253 expected_b='{
254 "name": "b.dat",
255 "oid": "'$b_oid'",
256 "size": 1,
257 "actions": {
258 "download": {
259 "href": "'$GITSERVER'/storage/'$b_oid'?r='$reponame'",
260 "expires_at": "0001-01-01T00:00:00Z"
261 }
262 },
263 "path": "'$(native_path_escaped "$(local_object_path "$b_oid")")'"
264 }'
265 catscip-shell system . . cat. > expected-a-b.json <<-EOF
266 {
267 "transfers": [
268 $expected_a,
269 $expected_b
270 ]
271 }
272 EOF
273 catscip-shell system . . cat. > expected-b-a.json <<-EOF
274 {
275 "transfers": [
276 $expected_b,
277 $expected_a
278 ]
279 }
280 EOF
281 diffscip-shell system . . diff. -u expected-a-b.json fetch-dry-run.json || diffscip-shell system . . diff. -u expected-b-a.json fetch-dry-run.json || exit 1
282 diffscip-shell system . . diff. -u expected-a-b.json fetch.json || diffscip-shell system . . diff. -u expected-b-a.json fetch-dry-run.json || exit 1
283 )
284 end_test
285
286 begin_test "fetch --refetch with remote and branches"
287 (
288 set -e
289 cd clone
290
291 gitscip-shell system . . git. checkout newbranch
292 gitscip-shell system . . git. checkout main
293
294 rmscip-shell system . . rm. -rf .git/lfs/objects
295
296 gitscip-shell system . . git. lfs fetch origin main newbranch
297 assert_local_object "$contents_oid" 1
298 assert_local_object "$b_oid" 1
299
300 corrupt_local_object "$contents_oid"
301 corrupt_local_object "$b_oid"
302 refute_local_object "$contents_oid" 1
303 refute_local_object "$b_oid" 1
304
305 gitscip-shell system . . git. lfs fetch --refetch --json origin main newbranch | teescip-shell system . . tee. fetch.json
306 assert_local_object "$contents_oid" 1
307 assert_local_object "$b_oid" 1
308
309 # check that we did not fetch a.dat twice
310 [scip-shell system . . `[`. 1 -eq $(grepscip-shell system . . grep. -c '"name": "a.dat"' fetch.json) ]
311 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
312 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
313 )
314 end_test
315
316 begin_test "fetch with main commit sha1"
317 (
318 set -e
319 cd clone
320 rmscip-shell system . . rm. -rf .git/lfs/objects
321
322 main_sha1=$(gitscip-shell system . . git. rev-parse main)
323 gitscip-shell system . . git. lfs fetch origin "$main_sha1"
324 assert_local_object "$contents_oid" 1
325 refute_local_object "$b_oid" 1
326
327 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
328 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
329 )
330 end_test
331
332 begin_test "fetch with newbranch commit sha1"
333 (
334 set -e
335 cd clone
336 rmscip-shell system . . rm. -rf .git/lfs/objects
337
338 newbranch_sha1=$(gitscip-shell system . . git. rev-parse newbranch)
339 gitscip-shell system . . git. lfs fetch origin "$newbranch_sha1"
340 assert_local_object "$contents_oid" 1
341 assert_local_object "$b_oid" 1
342
343 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
344 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
345 )
346 end_test
347
348 begin_test "fetch with include filters in gitconfig"
349 (
350 set -e
351 cd clone
352 rmscip-shell system . . rm. -rf .git/lfs/objects
353
354 gitscip-shell system . . git. config "lfs.fetchinclude" "a*"
355 gitscip-shell system . . git. lfs fetch origin main newbranch
356 assert_local_object "$contents_oid" 1
357 refute_local_object "$b_oid"
358
359 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
360 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
361 )
362 end_test
363
364 begin_test "fetch with exclude filters in gitconfig"
365 (
366 set -e
367
368 cd clone
369 gitscip-shell system . . git. config --unset "lfs.fetchinclude"
370 rmscip-shell system . . rm. -rf .git/lfs/objects
371
372 gitscip-shell system . . git. config "lfs.fetchexclude" "a*"
373 gitscip-shell system . . git. lfs fetch origin main newbranch
374 refute_local_object "$contents_oid"
375 assert_local_object "$b_oid" 1
376
377 gitscip-shell system . . git. lfs fsck 2>&1 | teescip-shell system . . tee. fsck.log
378 grepscip-shell system . . grep. "Git LFS fsck OK" fsck.log
379 )
380 end_test
381
382 begin_test "fetch with include/exclude filters in gitconfig"
383 (
384 set -e
385 cd clone
386 rmscip-shell system . . rm. -rf .git/lfs/objects
387 gitscip-shell system . . git. config --unset "lfs.fetchexclude"
388
389 gitscip-shell system . . git. config "lfs.fetchinclude" "a*,b*"
390 gitscip-shell system . . git. config "lfs.fetchexclude" "c*,d*"
391 gitscip-shell system . . git. lfs fetch origin main newbranch
392 assert_local_object "$contents_oid" 1
393 assert_local_object "$b_oid" 1
394
395 rmscip-shell system . . rm. -rf .git/lfs/objects
396 gitscip-shell system . . git. config "lfs.fetchinclude" "c*,d*"
397 gitscip-shell system . . git. config "lfs.fetchexclude" "a*,b*"
398 gitscip-shell system . . git. lfs fetch origin main newbranch
399 refute_local_object "$contents_oid"
400 refute_local_object "$b_oid"
401 )
402 end_test
403
404 begin_test "fetch with include filter in cli"
405 (
406 set -e
407 cd clone
408 gitscip-shell system . . git. config --unset "lfs.fetchinclude"
409 gitscip-shell system . . git. config --unset "lfs.fetchexclude"
410 rmscip-shell system . . rm. -rf .git/lfs/objects
411
412 gitscip-shell system . . git. lfs fetch --include="a*" origin main newbranch
413 assert_local_object "$contents_oid" 1
414 refute_local_object "$b_oid"
415 )
416 end_test
417
418 begin_test "fetch with exclude filter in cli"
419 (
420 set -e
421 cd clone
422 rmscip-shell system . . rm. -rf .git/lfs/objects
423 gitscip-shell system . . git. lfs fetch --exclude="a*" origin main newbranch
424 refute_local_object "$contents_oid"
425 assert_local_object "$b_oid" 1
426 )
427 end_test
428
429 begin_test "fetch with include/exclude filters in cli"
430 (
431 set -e
432 cd clone
433 rmscip-shell system . . rm. -rf .git/lfs/objects
434 gitscip-shell system . . git. lfs fetch -I "a*,b*" -X "c*,d*" origin main newbranch
435 assert_local_object "$contents_oid" 1
436 assert_local_object "$b_oid" 1
437
438 rmscip-shell system . . rm. -rf .git/lfs/objects
439 gitscip-shell system . . git. lfs fetch --include="c*,d*" --exclude="a*,b*" origin main newbranch
440 refute_local_object "$contents_oid"
441 refute_local_object "$b_oid"
442 )
443 end_test
444
445 begin_test "fetch with include filter overriding exclude filter"
446 (
447 set -e
448 cd clone
449 rmscip-shell system . . rm. -rf .git/lfs/objects
450 gitscip-shell system . . git. config lfs.fetchexclude "b*"
451 gitscip-shell system . . git. lfs fetch -I "b.dat" -X "" origin main newbranch
452 assert_local_object "$b_oid" "1"
453 )
454 end_test
455
456 begin_test "fetch with missing object"
457 (
458 set -e
459 cd clone
460 gitscip-shell system . . git. config --unset lfs.fetchexclude
461 rmscip-shell system . . rm. -rf .git/lfs/objects
462
463 delete_server_object "$reponame" "$b_oid"
464 refute_server_object "$reponame" "$b_oid"
465
466 # should return non-zero, but should also download all the other valid files too
467 set +e
468 gitscip-shell system . . git. lfs fetch origin main newbranch
469 fetch_exit=$?
470 set -e
471 [scip-shell system . . `[`. "$fetch_exit" != "0" ]
472 assert_local_object "$contents_oid" 1
473 refute_local_object "$b_oid"
474 )
475 end_test
476
477 begin_test "fetch does not crash on empty key files"
478 (
479 set -e
480 cd clone
481 rmscip-shell system . . rm. -rf .git/lfs/objects
482
483 gitscip-shell system . . git. config --local http.sslKey /dev/nullscip-shell filesystem . . `/dev/null`.
484 gitscip-shell system . . git. config --local http.sslCert /dev/nullscip-shell filesystem . . `/dev/null`.
485
486 gitscip-shell system . . git. lfs fetch origin main 2>&1 | teescip-shell system . . tee. fetch.log
487 grepscip-shell system . . grep. "Error decoding PEM block" fetch.log
488 )
489 end_test
490
491 begin_test "fetch-all"
492 (
493 set -e
494
495 reponame="fetch-all"
496 setup_remote_repo "$reponame"
497
498 clone_repo "$reponame" "$reponame"
499
500 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
501 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
502
503 NUMFILES=12
504 # generate content we'll use
505 for ((a=0; a < NUMFILES ; a++))
506 do
507 content[$a]="filecontent$a"
508 oid[$a]=$(calc_oid "${content[$a]}")
509 done
510
511 echoscip-shell system . . echo. "[
512 {
513 \"CommitDate\":\"$(get_date -180d)\",
514 \"Files\":[
515 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
516 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
517 },
518 {
519 \"NewBranch\":\"branch1\",
520 \"CommitDate\":\"$(get_date -140d)\",
521 \"Files\":[
522 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
523 },
524 {
525 \"ParentBranches\":[\"main\"],
526 \"CommitDate\":\"$(get_date -100d)\",
527 \"Files\":[
528 {\"Filename\":\"file1.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
529 },
530 {
531 \"NewBranch\":\"remote_branch_only\",
532 \"CommitDate\":\"$(get_date -80d)\",
533 \"Files\":[
534 {\"Filename\":\"file2.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
535 },
536 {
537 \"ParentBranches\":[\"main\"],
538 \"CommitDate\":\"$(get_date -75d)\",
539 \"Files\":[
540 {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
541 },
542 {
543 \"NewBranch\":\"tag_only\",
544 \"Tags\":[\"tag1\"],
545 \"CommitDate\":\"$(get_date -70d)\",
546 \"Files\":[
547 {\"Filename\":\"file4.dat\",\"Size\":${#content[6]}, \"Data\":\"${content[6]}\"}]
548 },
549 {
550 \"ParentBranches\":[\"main\"],
551 \"CommitDate\":\"$(get_date -60d)\",
552 \"Files\":[
553 {\"Filename\":\"file1.dat\",\"Size\":${#content[7]}, \"Data\":\"${content[7]}\"}]
554 },
555 {
556 \"NewBranch\":\"branch3\",
557 \"CommitDate\":\"$(get_date -50d)\",
558 \"Files\":[
559 {\"Filename\":\"file4.dat\",\"Size\":${#content[8]}, \"Data\":\"${content[8]}\"}]
560 },
561 {
562 \"CommitDate\":\"$(get_date -40d)\",
563 \"ParentBranches\":[\"main\"],
564 \"Files\":[
565 {\"Filename\":\"file1.dat\",\"Size\":${#content[9]}, \"Data\":\"${content[9]}\"},
566 {\"Filename\":\"file2.dat\",\"Size\":${#content[10]}, \"Data\":\"${content[10]}\"}]
567 },
568 {
569 \"ParentBranches\":[\"main\"],
570 \"CommitDate\":\"$(get_date -30d)\",
571 \"Files\":[
572 {\"Filename\":\"file4.dat\",\"Size\":${#content[11]}, \"Data\":\"${content[11]}\"}]
573 }
574 ]" | lfstest-testutils addcommits
575
576 gitscip-shell system . . git. push origin main
577 gitscip-shell system . . git. push origin branch1
578 gitscip-shell system . . git. push origin branch3
579 gitscip-shell system . . git. push origin remote_branch_only
580 gitscip-shell system . . git. push origin tag_only
581 gitscip-shell system . . git. push origin tag1
582 for ((a=0; a < NUMFILES ; a++))
583 do
584 assert_server_object "$reponame" "${oid[$a]}"
585 done
586
587 # delete remote_branch_only and make sure that objects are downloaded even
588 # though not checked out to a local branch (full backup always)
589 gitscip-shell system . . git. branch -D remote_branch_only
590
591 # delete tag_only to make sure objects are downloaded when only reachable from tag
592 gitscip-shell system . . git. branch -D tag_only
593
594 rmscip-shell system . . rm. -rf .git/lfs/objects
595
596 gitscip-shell system . . git. lfs fetch --all origin
597 for ((a=0; a < NUMFILES ; a++))
598 do
599 assert_local_object "${oid[$a]}" "${#content[$a]}"
600 done
601
602 rmscip-shell system . . rm. -rf .git/lfs/objects
603
604 # fetch all objects reachable from the main branch only
605 gitscip-shell system . . git. lfs fetch --all origin main
606 for a in 0 1 3 5 7 9 10 11
607 do
608 assert_local_object "${oid[$a]}" "${#content[$a]}"
609 done
610 for a in 2 4 6 8
611 do
612 refute_local_object "${oid[$a]}"
613 done
614
615 rmscip-shell system . . rm. -rf .git/lfs/objects
616
617 # fetch all objects reachable from branch1 and tag1 only
618 gitscip-shell system . . git. lfs fetch --all origin branch1 tag1
619 for a in 0 1 2 3 5 6
620 do
621 assert_local_object "${oid[$a]}" "${#content[$a]}"
622 done
623 for a in 4 7 8 9 10 11
624 do
625 refute_local_object "${oid[$a]}"
626 done
627
628 # Make a bare clone of the repository
629 cd ..
630 gitscip-shell system . . git. clone --bare "$GITSERVER/$reponame" "$reponame-bare"
631 cd "$reponame-bare"
632
633 # Perform the same assertion as above, on the same data
634 gitscip-shell system . . git. lfs fetch --all origin
635 for ((a=0; a < NUMFILES ; a++))
636 do
637 assert_local_object "${oid[$a]}" "${#content[$a]}"
638 done
639
640 rmscip-shell system . . rm. -rf lfs/objects
641
642 # fetch all objects reachable from the main branch only
643 gitscip-shell system . . git. lfs fetch --all origin main
644 for a in 0 1 3 5 7 9 10 11
645 do
646 assert_local_object "${oid[$a]}" "${#content[$a]}"
647 done
648 for a in 2 4 6 8
649 do
650 refute_local_object "${oid[$a]}"
651 done
652
653 rmscip-shell system . . rm. -rf lfs/objects
654
655 echoscip-shell system . . echo. "main" | gitscip-shell system . . git. lfs fetch --all --stdin origin
656 for a in 0 1 3 5 7 9 10 11
657 do
658 assert_local_object "${oid[$a]}" "${#content[$a]}"
659 done
660 for a in 2 4 6 8
661 do
662 refute_local_object "${oid[$a]}"
663 done
664
665 rmscip-shell system . . rm. -rf lfs/objects
666
667 # fetch all objects reachable from branch1 and tag1 only
668 gitscip-shell system . . git. lfs fetch --all origin branch1 tag1
669 for a in 0 1 2 3 5 6
670 do
671 assert_local_object "${oid[$a]}" "${#content[$a]}"
672 done
673 for a in 4 7 8 9 10 11
674 do
675 refute_local_object "${oid[$a]}"
676 done
677
678 rmscip-shell system . . rm. -rf lfs/objects
679
680 printfscip-shell system . . printf. "branch1\ntag1\n\n" | gitscip-shell system . . git. lfs fetch --all --stdin origin
681 for a in 0 1 2 3 5 6
682 do
683 assert_local_object "${oid[$a]}" "${#content[$a]}"
684 done
685 for a in 4 7 8 9 10 11
686 do
687 refute_local_object "${oid[$a]}"
688 done
689
690 )
691 end_test
692
693 begin_test "fetch: outside git repository"
694 (
695 set +e
696 gitscip-shell system . . git. lfs fetch 2>&1 > fetch.log
697 res=$?
698
699 set -e
700 if [scip-shell system . . `[`. "$res" = "0" ]; then
701 echoscip-shell system . . echo. "Passes because $GIT_LFS_TEST_DIR is unset."
702 exit 0
703 fi
704 [scip-shell system . . `[`. "$res" = "128" ]
705 grepscip-shell system . . grep. "Not in a Git repository" fetch.log
706 )
707 end_test
708
709 begin_test "fetch with no origin remote"
710 (
711 set -e
712
713 reponame="fetch-no-remote"
714 setup_remote_repo "$reponame"
715
716 clone_repo "$reponame" no-remote-clone
717
718 clone_repo "$reponame" no-remote-repo
719
720 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
721 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
722
723 contents="a"
724 contents_oid=$(calc_oid "$contents")
725
726 printfscip-shell system . . printf. "%s" "$contents" > a.dat
727 gitscip-shell system . . git. add a.dat
728 gitscip-shell system . . git. add .gitattributes
729 gitscip-shell system . . git. commit -m "add a.dat" 2>&1 | teescip-shell system . . tee. commit.log
730 grepscip-shell system . . grep. "main (root-commit)" commit.log
731 grepscip-shell system . . grep. "2 files changed" commit.log
732 grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log
733 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
734
735 [scip-shell system . . `[`. "a" = "$(catscip-shell system . . cat. a.dat)" ]
736
737 assert_local_object "$contents_oid" 1
738
739 refute_server_object "$reponame" "$contents_oid"
740
741 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
742 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
743 grepscip-shell system . . grep. "main -> main" push.log
744
745
746 # change to the clone's working directory
747 cd ../no-remote-clone
748
749 # pull commits & lfs
750 gitscip-shell system . . git. pull origin main 2>&1
751 assert_local_object "$contents_oid" 1
752
753 # now checkout detached HEAD so we're not tracking anything on remote
754 gitscip-shell system . . git. checkout --detach
755
756 # delete lfs
757 rmscip-shell system . . rm. -rf .git/lfs
758
759 # rename remote from 'origin' to 'something'
760 gitscip-shell system . . git. remote rename origin something
761
762 # fetch should still pick this remote as in the case of no tracked remote,
763 # and no origin, but only 1 remote, should pick the only one as default
764 gitscip-shell system . . git. lfs fetch
765 assert_local_object "$contents_oid" 1
766 )
767 end_test
768
769 begin_test "fetch --prune"
770 (
771 set -e
772
773 reponame="fetch_prune"
774 setup_remote_repo "remote_$reponame"
775
776 clone_repo "remote_$reponame" "clone_$reponame"
777
778 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
779 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
780
781 content_head="HEAD content"
782 content_commit2="Content for commit 2 (prune)"
783 content_commit1="Content for commit 1 (prune)"
784 oid_head=$(calc_oid "$content_head")
785 oid_commit2=$(calc_oid "$content_commit2")
786 oid_commit1=$(calc_oid "$content_commit1")
787
788 echoscip-shell system . . echo. "[
789 {
790 \"CommitDate\":\"$(get_date -50d)\",
791 \"Files\":[
792 {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
793 },
794 {
795 \"CommitDate\":\"$(get_date -35d)\",
796 \"Files\":[
797 {\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}]
798 },
799 {
800 \"CommitDate\":\"$(get_date -25d)\",
801 \"Files\":[
802 {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
803 }
804 ]" | lfstest-testutils addcommits
805
806 # push all so no unpushed reason to not prune
807 gitscip-shell system . . git. push origin main
808
809 # set no recents so max ability to prune
810 gitscip-shell system . . git. config lfs.fetchrecentrefsdays 0
811 gitscip-shell system . . git. config lfs.fetchrecentcommitsdays 0
812
813 # delete HEAD object to prove that we still download something
814 # also prune at the same time which will remove anything other than HEAD
815 delete_local_object "$oid_head"
816 gitscip-shell system . . git. lfs fetch --prune
817 assert_local_object "$oid_head" "${#content_head}"
818 refute_local_object "$oid_commit1"
819 refute_local_object "$oid_commit2"
820 )
821 end_test
822
823 begin_test "fetch raw remote url"
824 (
825 set -e
826 mkdirscip-shell system . . mkdir. raw
827 cd raw
828 gitscip-shell system . . git. init
829 gitscip-shell system . . git. lfs install --local --skip-smudge
830
831 gitscip-shell system . . git. remote add origin "$GITSERVER/$reponame"
832 gitscip-shell system . . git. pull origin main
833
834 # LFS object not downloaded, pointer in working directory
835 refute_local_object "$contents_oid"
836 grepscip-shell system . . grep. "$content_oid" a.dat
837
838 gitscip-shell system . . git. lfs fetch "$GITSERVER/$reponame"
839
840 # LFS object downloaded, pointer still in working directory
841 assert_local_object "$contents_oid" 1
842 grepscip-shell system . . grep. "$content_oid" a.dat
843 )
844 end_test
845
846 begin_test "fetch with invalid ref"
847 (
848 set -e
849 cd repo
850
851 gitscip-shell system . . git. lfs fetch origin jibberish >fetch.log 2>&1 && exit 1
852 grepscip-shell system . . grep. "Invalid ref argument" fetch.log
853 )
854 end_test
855
856 begin_test "fetch with invalid remote"
857 (
858 set -e
859 cd repo
860 gitscip-shell system . . git. lfs fetch not-a-remote 2>&1 | teescip-shell system . . tee. fetch.log
861 grepscip-shell system . . grep. "Invalid remote name" fetch.log
862 )
863 end_test
864
865 begin_test "fetch fails when LFS directory has wrong permissions"
866 (
867 set -e
868
869 # Windows lacks POSIX permissions.
870 [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ] && exit 0
871
872 # Root is exempt from permissions.
873 [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -eq 0 ] && exit 0
874
875 cd shared
876 rmscip-shell system . . rm. -rf .git/lfs/objects
877 mkdirscip-shell system . . mkdir. .git/lfs/objects
878 chmodscip-shell system . . chmod. 400 .git/lfs/objects
879
880 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
881 grepscip-shell system . . grep. "error trying to create local storage directory" fetch.log
882 )
883 end_test