Debian Codegraph @

t/t-custom-transfers.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "custom-transfer-wrong-path"
6 (
7 set -e
8
9 # this repo name is the indicator to the server to support custom transfer
10 reponame="custom-transfer-wrong-path"
11 setup_remote_repo "$reponame"
12
13 clone_repo "$reponame" $reponame
14
15 # deliberately incorrect path
16 git config lfs.customtransfer.testcustom.path path-to-nothing
17
18 git lfs track "*.dat" 2>&1 | tee track.log
19 grep "Tracking \"\*.dat\"" track.log
20
21 contents="jksgdfljkgsdlkjafg lsjdgf alkjgsd lkfjag sldjkgf alkjsgdflkjagsd kljfg asdjgf kalsd"
22 contents_oid=$(calc_oid "$contents")
23
24 printf "%s" "$contents" > a.dat
25 git add a.dat
26 git add .gitattributes
27 git commit -m "add a.dat" 2>&1 | tee commit.log
28 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee pushcustom.log
29 # use PIPESTATUS otherwise we get exit code from tee
30 res=${PIPESTATUS[0]}
31 grep "xfer: adapter \"testcustom\" Begin()" pushcustom.log
32 grep "xfer: Aborting worker process" pushcustom.log
33 if [ "$res" = "0" ]; then
34 echo "Push should have failed because of an incorrect custom transfer path."
35 exit 1
36 fi
37
38 )
39 end_test
40
41 begin_test "custom-transfer-upload-download"
42 (
43 set -e
44
45 # this repo name is the indicator to the server to support custom transfer
46 reponame="custom-transfer-upload-download"
47 setup_remote_repo "$reponame"
48
49 clone_repo "$reponame" $reponame
50
51 # set up custom transfer adapter
52 git config lfs.customtransfer.testcustom.path lfstest-customadapter
53
54 git lfs track "*.dat" 2>&1 | tee track.log
55 grep "Tracking \"\*.dat\"" track.log
56 git add .gitattributes
57 git commit -m "Tracking"
58
59 # set up a decent amount of data so that there's work for multiple concurrent adapters
60 echo "[
61 {
62 \"CommitDate\":\"$(get_date -10d)\",
63 \"Files\":[
64 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
65 {\"Filename\":\"file1.dat\",\"Size\":1024},
66 {\"Filename\":\"file2.dat\",\"Size\":750}]
67 },
68 {
69 \"CommitDate\":\"$(get_date -7d)\",
70 \"Files\":[
71 {\"Filename\":\"file1.dat\",\"Size\":1050},
72 {\"Filename\":\"file3.dat\",\"Size\":660},
73 {\"Filename\":\"file4.dat\",\"Size\":230}]
74 },
75 {
76 \"CommitDate\":\"$(get_date -5d)\",
77 \"Files\":[
78 {\"Filename\":\"file5.dat\",\"Size\":1200},
79 {\"Filename\":\"file6.dat\",\"Size\":300}]
80 },
81 {
82 \"CommitDate\":\"$(get_date -2d)\",
83 \"Files\":[
84 {\"Filename\":\"file3.dat\",\"Size\":120},
85 {\"Filename\":\"file5.dat\",\"Size\":450},
86 {\"Filename\":\"file7.dat\",\"Size\":520},
87 {\"Filename\":\"file8.dat\",\"Size\":2048}]
88 }
89 ]" | lfstest-testutils addcommits
90
91 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee pushcustom.log
92 # use PIPESTATUS otherwise we get exit code from tee
93 [ ${PIPESTATUS[0]} = "0" ]
94
95 grep "xfer: started custom adapter process" pushcustom.log
96 grep "xfer\[lfstest-customadapter\]:" pushcustom.log
97 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
98
99 rm -rf .git/lfs/objects
100 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetchcustom.log
101 [ ${PIPESTATUS[0]} = "0" ]
102
103 grep "xfer: started custom adapter process" fetchcustom.log
104 grep "xfer\[lfstest-customadapter\]:" fetchcustom.log
105
106 grep "Terminating test custom adapter gracefully" fetchcustom.log
107
108 objectlist=`find .git/lfs/objects -type f`
109 [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
110 )
111 end_test
112
113 begin_test "custom-transfer-standalone"
114 (
115 set -e
116
117 # setup a git repo to be used as a local repo, not remote
118 reponame="custom-transfer-standalone"
119 setup_remote_repo "$reponame"
120
121 # clone directly, not through lfstest-gitserver
122 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
123
124 # set up custom transfer adapter to use a specific transfer agent
125 git config lfs.customtransfer.testcustom.path lfstest-standalonecustomadapter
126 git config lfs.customtransfer.testcustom.args "--arg1 '--arg2 --arg3' --arg4"
127 git config lfs.customtransfer.testcustom.concurrent false
128 git config lfs.standalonetransferagent testcustom
129 export TEST_STANDALONE_BACKUP_PATH="$(pwd)/test-custom-transfer-standalone-backup"
130 mkdir -p $TEST_STANDALONE_BACKUP_PATH
131 rm -rf $TEST_STANDALONE_BACKUP_PATH/*
132
133 git lfs track "*.dat" 2>&1 | tee track.log
134 grep "Tracking \"\*.dat\"" track.log
135 git add .gitattributes
136 git commit -m "Tracking"
137
138 # set up a decent amount of data so that there's work for multiple concurrent adapters
139 echo "[
140 {
141 \"CommitDate\":\"$(get_date -10d)\",
142 \"Files\":[
143 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
144 {\"Filename\":\"file1.dat\",\"Size\":1024},
145 {\"Filename\":\"file2.dat\",\"Size\":750}]
146 },
147 {
148 \"CommitDate\":\"$(get_date -7d)\",
149 \"Files\":[
150 {\"Filename\":\"file1.dat\",\"Size\":1050},
151 {\"Filename\":\"file3.dat\",\"Size\":660},
152 {\"Filename\":\"file4.dat\",\"Size\":230}]
153 },
154 {
155 \"CommitDate\":\"$(get_date -5d)\",
156 \"Files\":[
157 {\"Filename\":\"file5.dat\",\"Size\":1200},
158 {\"Filename\":\"file6.dat\",\"Size\":300}]
159 },
160 {
161 \"CommitDate\":\"$(get_date -2d)\",
162 \"Files\":[
163 {\"Filename\":\"file3.dat\",\"Size\":120},
164 {\"Filename\":\"file5.dat\",\"Size\":450},
165 {\"Filename\":\"file7.dat\",\"Size\":520},
166 {\"Filename\":\"file8.dat\",\"Size\":2048}]
167 }
168 ]" | lfstest-testutils addcommits
169
170 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee pushcustom.log
171 # use PIPESTATUS otherwise we get exit code from tee
172 [ ${PIPESTATUS[0]} = "0" ]
173
174 # Make sure the lock verification is not attempted.
175 grep "locks/verify$" pushcustom.log && false
176
177 grep "xfer: started custom adapter process" pushcustom.log
178 grep "xfer\[lfstest-standalonecustomadapter\]:" pushcustom.log
179 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
180
181 rm -rf .git/lfs/objects
182 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetchcustom.log
183 [ ${PIPESTATUS[0]} = "0" ]
184
185 grep "xfer: started custom adapter process" fetchcustom.log
186 grep "xfer\[lfstest-standalonecustomadapter\]:" fetchcustom.log
187
188 grep "Terminating test custom adapter gracefully" fetchcustom.log
189
190 # Test argument parsing.
191 grep 'Saw argument "--arg1"' fetchcustom.log
192 grep 'Saw argument "--arg2 --arg3"' fetchcustom.log
193 grep 'Saw argument "--arg4"' fetchcustom.log
194
195 objectlist=`find .git/lfs/objects -type f`
196 [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
197
198 git lfs fsck
199 )
200 end_test
201
202 begin_test "custom-transfer-standalone-urlmatch"
203 (
204 set -e
205
206 # setup a git repo to be used as a local repo, not remote
207 reponame="custom-transfer-standalone-urlmatch"
208 setup_remote_repo "$reponame"
209
210 # clone directly, not through lfstest-gitserver
211 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
212
213 # set up custom transfer adapter to use a specific transfer agent, using a URL prefix match
214 git config lfs.customtransfer.testcustom.path lfstest-standalonecustomadapter
215 git config lfs.customtransfer.testcustom.concurrent false
216 git config remote.origin.lfsurl https://git.example.com/example/path/to/repo
217 git config lfs.https://git.example.com/example/path/.standalonetransferagent testcustom
218 git config lfs.standalonetransferagent invalid-agent
219
220 # git config lfs.standalonetransferagent testcustom
221 export TEST_STANDALONE_BACKUP_PATH="$(pwd)/test-custom-transfer-standalone-urlmatch-backup"
222 mkdir -p $TEST_STANDALONE_BACKUP_PATH
223 rm -rf $TEST_STANDALONE_BACKUP_PATH/*
224
225 git lfs track "*.dat" 2>&1 | tee track.log
226 grep "Tracking \"\*.dat\"" track.log
227 git add .gitattributes
228 git commit -m "Tracking"
229
230 # set up a decent amount of data so that there's work for multiple concurrent adapters
231 echo "[
232 {
233 \"CommitDate\":\"$(get_date -10d)\",
234 \"Files\":[
235 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
236 {\"Filename\":\"file1.dat\",\"Size\":1024},
237 {\"Filename\":\"file2.dat\",\"Size\":750}]
238 },
239 {
240 \"CommitDate\":\"$(get_date -7d)\",
241 \"Files\":[
242 {\"Filename\":\"file1.dat\",\"Size\":1050},
243 {\"Filename\":\"file3.dat\",\"Size\":660},
244 {\"Filename\":\"file4.dat\",\"Size\":230}]
245 },
246 {
247 \"CommitDate\":\"$(get_date -5d)\",
248 \"Files\":[
249 {\"Filename\":\"file5.dat\",\"Size\":1200},
250 {\"Filename\":\"file6.dat\",\"Size\":300}]
251 },
252 {
253 \"CommitDate\":\"$(get_date -2d)\",
254 \"Files\":[
255 {\"Filename\":\"file3.dat\",\"Size\":120},
256 {\"Filename\":\"file5.dat\",\"Size\":450},
257 {\"Filename\":\"file7.dat\",\"Size\":520},
258 {\"Filename\":\"file8.dat\",\"Size\":2048}]
259 }
260 ]" | lfstest-testutils addcommits
261
262 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee pushcustom.log
263 # use PIPESTATUS otherwise we get exit code from tee
264 [ ${PIPESTATUS[0]} = "0" ]
265
266 # Make sure the lock verification is not attempted.
267 grep "locks/verify$" pushcustom.log && false
268
269 grep "xfer: started custom adapter process" pushcustom.log
270 grep "xfer\[lfstest-standalonecustomadapter\]:" pushcustom.log
271 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
272
273 rm -rf .git/lfs/objects
274 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetchcustom.log
275 [ ${PIPESTATUS[0]} = "0" ]
276
277 grep "xfer: started custom adapter process" fetchcustom.log
278 grep "xfer\[lfstest-standalonecustomadapter\]:" fetchcustom.log
279
280 grep "Terminating test custom adapter gracefully" fetchcustom.log
281
282 objectlist=`find .git/lfs/objects -type f`
283 [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
284
285 git lfs fsck
286 )
287 end_test
288
289 begin_test "standalone agent without custom group (file transfers allowed)"
290 (
291 set -e
292
293 reponame="custom-transfer-standalone-valid-file"
294 setup_remote_repo "$reponame"
295
296 # Clone directly, not through lfstest-gitserver.
297 clone_repo_url "$REMOTEDIR/$reponame.git" "$reponame"
298
299 # When the remote has a file:// URL, we permit the standalone transfer
300 # agent to be set to the internal "lfs-standalone-file" adapter without
301 # any "lfs.customtransfer.*" settings.
302 git config lfs.standaloneTransferAgent lfs-standalone-file
303
304 git lfs track "*.bin"
305
306 contents="a"
307 contents_oid="$(calc_oid "$contents")"
308 printf "%s" "$contents" >a.bin
309
310 git add .gitattributes a.bin
311 git commit -m "initial commit"
312
313 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
314 [ 0 -eq "${PIPESTATUS[0]}" ]
315
316 assert_remote_object "$reponame" "$contents_oid" "${#contents}"
317
318 rm -rf .git/lfs/objects
319
320 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
321 [ 0 -eq "${PIPESTATUS[0]}" ]
322
323 [ 0 -eq "$(grep -c "not a registered custom transfer adapter" pull.log)" ]
324
325 assert_local_object "$contents_oid" "${#contents}"
326 )
327 end_test
328
329 begin_test "standalone agent without custom group (file transfers disallowed)"
330 (
331 set -e
332
333 reponame="custom-transfer-standalone-invalid-file"
334 setup_remote_repo "$reponame"
335 clone_repo "$reponame" "$reponame"
336
337 git lfs track "*.bin"
338
339 contents="a"
340 contents_oid="$(calc_oid "$contents")"
341 printf "%s" "$contents" >a.bin
342
343 git add .gitattributes a.bin
344 git commit -m "initial commit"
345
346 git push origin main
347
348 # When the remote has an HTTP URL, we expect an error if the standalone
349 # transfer agent is set to the internal "lfs-standalone-file" adapter.
350 git config lfs.standaloneTransferAgent lfs-standalone-file
351
352 rm -rf .git/lfs/objects
353
354 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
355 [ 0 -ne "${PIPESTATUS[0]}" ]
356
357 grep "error initializing custom adapter \"lfs-standalone-file\"" pull.log
358 grep "error creating handler: no valid file:// URLs found" pull.log
359 grep "Failed to fetch some objects" pull.log
360
361 [ 0 -eq "$(grep -c "not a registered custom transfer adapter" pull.log)" ]
362
363 refute_local_object "$contents_oid"
364 )
365 end_test
366
367 begin_test "standalone agent without custom group ignored (basic transfers)"
368 (
369 set -e
370
371 reponame="custom-transfer-standalone-ignored-basic"
372 setup_remote_repo "$reponame"
373 clone_repo "$reponame" "$reponame"
374
375 # The standalone transfer agent should be ignored if it is set to the
376 # internal "basic" adapter, regardless of whether that adapter is
377 # actually used for HTTP requests to the Batch API.
378 git config lfs.standaloneTransferAgent basic
379
380 git lfs track "*.bin"
381
382 contents="a"
383 contents_oid="$(calc_oid "$contents")"
384 printf "%s" "$contents" >a.bin
385
386 git add .gitattributes a.bin
387 git commit -m "initial commit"
388
389 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
390 [ 0 -eq "${PIPESTATUS[0]}" ]
391
392 grep "standalone agent \"basic\" is not a registered custom transfer adapter; ignoring" push.log
393
394 assert_server_object "$reponame" "$contents_oid"
395
396 rm -rf .git/lfs/objects
397
398 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
399 [ 0 -eq "${PIPESTATUS[0]}" ]
400
401 grep "standalone agent \"basic\" is not a registered custom transfer adapter; ignoring" pull.log
402
403 assert_local_object "$contents_oid" "${#contents}"
404
405 # The standalone transfer agent should still be ignored even when
406 # a custom transfer adapter is registered with the same name as the
407 # internal "basic" adapter.
408 git config lfs.customTransfer.basic.path path-to-nothing
409
410 contents="b"
411 contents_oid="$(calc_oid "$contents")"
412 printf "%s" "$contents" >b.bin
413
414 git add b.bin
415 git commit -m "second commit"
416
417 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
418 [ 0 -eq "${PIPESTATUS[0]}" ]
419
420 grep "standalone agent \"basic\" is not a registered custom transfer adapter; ignoring" push.log
421 grep "custom upload transfer adapter \"basic\" ignored due to conflict with standard adapter" push.log
422 grep "custom download transfer adapter \"basic\" ignored due to conflict with standard adapter" push.log
423
424 assert_server_object "$reponame" "$contents_oid"
425
426 rm -rf .git/lfs/objects
427
428 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
429 [ 0 -eq "${PIPESTATUS[0]}" ]
430
431 grep "standalone agent \"basic\" is not a registered custom transfer adapter; ignoring" pull.log
432 grep "custom upload transfer adapter \"basic\" ignored due to conflict with standard adapter" pull.log
433 grep "custom download transfer adapter \"basic\" ignored due to conflict with standard adapter" pull.log
434
435 assert_local_object "$contents_oid" "${#contents}"
436 )
437 end_test
438
439 begin_test "standalone agent without custom group ignored (basic transfers not ssh)"
440 (
441 set -e
442
443 reponame="custom-transfer-standalone-ignored-basic-ssh"
444 setup_remote_repo "$reponame"
445 clone_repo "$reponame" "$reponame"
446
447 # The standalone transfer agent should be ignored if it is set to the
448 # internal "ssh" adapter, regardless of whether the internal "basic"
449 # adapter will actually be used for HTTP requests to the Batch API.
450 git config lfs.standaloneTransferAgent ssh
451
452 git lfs track "*.bin"
453
454 contents="a"
455 contents_oid="$(calc_oid "$contents")"
456 printf "%s" "$contents" >a.bin
457
458 git add .gitattributes a.bin
459 git commit -m "initial commit"
460
461 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
462 [ 0 -eq "${PIPESTATUS[0]}" ]
463
464 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" push.log
465
466 assert_server_object "$reponame" "$contents_oid"
467
468 rm -rf .git/lfs/objects
469
470 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
471 [ 0 -eq "${PIPESTATUS[0]}" ]
472
473 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" pull.log
474
475 assert_local_object "$contents_oid" "${#contents}"
476
477 # The standalone transfer agent should still be ignored even when
478 # a custom transfer adapter is registered with the same name as the
479 # internal "ssh" adapter.
480 git config lfs.customTransfer.ssh.path path-to-nothing
481
482 contents="b"
483 contents_oid="$(calc_oid "$contents")"
484 printf "%s" "$contents" >b.bin
485
486 git add b.bin
487 git commit -m "second commit"
488
489 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
490 [ 0 -eq "${PIPESTATUS[0]}" ]
491
492 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" push.log
493 grep "custom upload transfer adapter \"ssh\" ignored due to conflict with standard adapter" push.log
494 grep "custom download transfer adapter \"ssh\" ignored due to conflict with standard adapter" push.log
495
496 assert_server_object "$reponame" "$contents_oid"
497
498 rm -rf .git/lfs/objects
499
500 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
501 [ 0 -eq "${PIPESTATUS[0]}" ]
502
503 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" pull.log
504 grep "custom upload transfer adapter \"ssh\" ignored due to conflict with standard adapter" pull.log
505 grep "custom download transfer adapter \"ssh\" ignored due to conflict with standard adapter" pull.log
506
507 assert_local_object "$contents_oid" "${#contents}"
508 )
509 end_test
510
511 begin_test "standalone agent without custom group ignored (ssh transfers)"
512 (
513 set -e
514
515 setup_pure_ssh
516
517 reponame="custom-transfer-standalone-ignored-ssh"
518 setup_remote_repo "$reponame"
519 clone_repo "$reponame" "$reponame"
520
521 sshurl=$(ssh_remote "$reponame")
522 git config lfs.url "$sshurl"
523
524 # The standalone transfer agent should be ignored if it is set to the
525 # internal "ssh" adapter, regardless of whether that adapter is
526 # actually used for SSH requests to the Batch API.
527 git config lfs.standaloneTransferAgent ssh
528
529 git lfs track "*.bin"
530
531 contents="a"
532 contents_oid="$(calc_oid "$contents")"
533 printf "%s" "$contents" >a.bin
534
535 git add .gitattributes a.bin
536 git commit -m "initial commit"
537
538 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
539 [ 0 -eq "${PIPESTATUS[0]}" ]
540
541 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" push.log
542
543 assert_remote_object "$reponame" "$contents_oid" "${#contents}"
544
545 rm -rf .git/lfs/objects
546
547 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
548 [ 0 -eq "${PIPESTATUS[0]}" ]
549
550 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" pull.log
551
552 assert_local_object "$contents_oid" "${#contents}"
553
554 # The standalone transfer agent should still be ignored even when
555 # a custom transfer adapter is registered with the same name as the
556 # internal "ssh" adapter.
557 git config lfs.customTransfer.ssh.path path-to-nothing
558
559 contents="b"
560 contents_oid="$(calc_oid "$contents")"
561 printf "%s" "$contents" >b.bin
562
563 git add b.bin
564 git commit -m "second commit"
565
566 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
567 [ 0 -eq "${PIPESTATUS[0]}" ]
568
569 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" push.log
570 grep "custom upload transfer adapter \"ssh\" ignored due to conflict with standard adapter" push.log
571 grep "custom download transfer adapter \"ssh\" ignored due to conflict with standard adapter" push.log
572
573 assert_remote_object "$reponame" "$contents_oid" "${#contents}"
574
575 rm -rf .git/lfs/objects
576
577 GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log
578 [ 0 -eq "${PIPESTATUS[0]}" ]
579
580 grep "standalone agent \"ssh\" is not a registered custom transfer adapter; ignoring" pull.log
581 grep "custom upload transfer adapter \"ssh\" ignored due to conflict with standard adapter" pull.log
582 grep "custom download transfer adapter \"ssh\" ignored due to conflict with standard adapter" pull.log
583
584 assert_local_object "$contents_oid" "${#contents}"
585 )
586 end_test