Debian Codegraph @

t/t-standalone-file.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 do_upload_download_test () {
6 git lfs track "*.dat" 2>&1 | tee track.log
7 grep "Tracking \"\*.dat\"" track.log
8 git add .gitattributes
9 git commit -m "Tracking"
10
11 git checkout -b test
12
13 # set up a decent amount of data so that there's work for multiple concurrent adapters
14 echo "[
15 {
16 \"CommitDate\":\"$(get_date -10d)\",
17 \"Files\":[
18 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
19 {\"Filename\":\"file1.dat\",\"Size\":1024},
20 {\"Filename\":\"file2.dat\",\"Size\":750}]
21 },
22 {
23 \"CommitDate\":\"$(get_date -7d)\",
24 \"Files\":[
25 {\"Filename\":\"file1.dat\",\"Size\":1050},
26 {\"Filename\":\"file3.dat\",\"Size\":660},
27 {\"Filename\":\"file4.dat\",\"Size\":230}]
28 },
29 {
30 \"CommitDate\":\"$(get_date -5d)\",
31 \"Files\":[
32 {\"Filename\":\"file5.dat\",\"Size\":1200},
33 {\"Filename\":\"file6.dat\",\"Size\":300}]
34 },
35 {
36 \"CommitDate\":\"$(get_date -2d)\",
37 \"Files\":[
38 {\"Filename\":\"file3.dat\",\"Size\":120},
39 {\"Filename\":\"file5.dat\",\"Size\":450},
40 {\"Filename\":\"file7.dat\",\"Size\":520},
41 {\"Filename\":\"file8.dat\",\"Size\":2048}]
42 }
43 ]" | lfstest-testutils addcommits
44
45 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin test 2>&1 | tee pushcustom.log
46 # use PIPESTATUS otherwise we get exit code from tee
47 [ ${PIPESTATUS[0]} = "0" ]
48
49 ourobjects=$(cd .git && find lfs/objects -type f | sort)
50 theirobjects=$(cd $gitdir && find lfs/objects -type f | sort)
51
52 # Make sure the lock verification is not attempted.
53 grep "locks/verify$" pushcustom.log && false
54
55 grep "xfer: started custom adapter process" pushcustom.log
56 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
57 [ "$ourobjects" = "$theirobjects" ]
58
59 rm -rf .git/lfs/objects
60 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetchcustom.log
61 [ ${PIPESTATUS[0]} = "0" ]
62
63 objectlist=$(find .git/lfs/objects -type f)
64 [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
65 }
66
67 do_local_path_test () {
68 local reponame="$1"
69 local suffix="$2"
70
71 git lfs track "*.dat" 2>&1 | tee track.log
72 grep "Tracking \"\*.dat\"" track.log
73 git add .gitattributes
74 git commit -m "Tracking"
75
76 git checkout -b test
77
78 # set up a decent amount of data so that there's work for multiple concurrent adapters
79 echo "[
80 {
81 \"CommitDate\":\"$(get_date -10d)\",
82 \"Files\":[
83 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
84 {\"Filename\":\"file1.dat\",\"Size\":1024},
85 {\"Filename\":\"file2.dat\",\"Size\":750}]
86 },
87 {
88 \"CommitDate\":\"$(get_date -7d)\",
89 \"Files\":[
90 {\"Filename\":\"file1.dat\",\"Size\":1050},
91 {\"Filename\":\"file3.dat\",\"Size\":660},
92 {\"Filename\":\"file4.dat\",\"Size\":230}]
93 },
94 {
95 \"CommitDate\":\"$(get_date -5d)\",
96 \"Files\":[
97 {\"Filename\":\"file5.dat\",\"Size\":1200},
98 {\"Filename\":\"file6.dat\",\"Size\":300}]
99 },
100 {
101 \"CommitDate\":\"$(get_date -2d)\",
102 \"Files\":[
103 {\"Filename\":\"file3.dat\",\"Size\":120},
104 {\"Filename\":\"file5.dat\",\"Size\":450},
105 {\"Filename\":\"file7.dat\",\"Size\":520},
106 {\"Filename\":\"file8.dat\",\"Size\":2048}]
107 }
108 ]" | lfstest-testutils addcommits
109
110 testdir="$(pwd)"
111
112 cd "$TRASHDIR"
113
114 # Check a clone using an absolute Unix-style path.
115 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git clone "$testdir$suffix" "$reponame-repo1" 2>&1 | tee clonecustom.log
116 (cd "$reponame-repo1" && git lfs fsck)
117 grep "xfer: started custom adapter process" clonecustom.log
118
119 # Check a clone using a relative path.
120 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git clone "$reponame-repo1$suffix" "$reponame-repo2" 2>&1 | tee clonecustom.log
121 (cd "$reponame-repo2" && git lfs fsck)
122 grep "xfer: started custom adapter process" clonecustom.log
123
124 # Check a clone using an absolute native-style path.
125 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git clone "$(native_path "$testdir")$suffix" "$reponame-repo3" 2>&1 | tee clonecustom.log
126 (cd "$reponame-repo3" && git lfs fsck)
127 grep "xfer: started custom adapter process" clonecustom.log
128
129 }
130
131 begin_test "standalone-file-upload-download-bare"
132 (
133 set -e
134
135 # setup a git repo to be used as a local repo, not remote
136 reponame="standalone-file-upload-download-bare"
137 setup_remote_repo "$reponame"
138
139 git init --bare "$reponame-2.git"
140 gitdir="$(pwd)/$reponame-2.git"
141
142 # clone directly, not through lfstest-gitserver
143 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
144
145 git remote set-url origin "file://$(urlify "$gitdir")"
146
147 do_upload_download_test
148 )
149 end_test
150
151 begin_test "standalone-file-upload-download-non-bare"
152 (
153 set -e
154
155 # setup a git repo to be used as a local repo, not remote
156 reponame="standalone-file-upload-download-non-bare"
157 setup_remote_repo "$reponame"
158
159 git init "$reponame-2.git"
160 repo2="$(pwd)/$reponame-2.git"
161 gitdir="$(pwd)/$reponame-2.git/.git"
162
163 # clone directly, not through lfstest-gitserver
164 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
165
166 git remote set-url origin "file://$(urlify "$repo2")"
167
168 do_upload_download_test
169 )
170 end_test
171
172 begin_test "standalone-file-download-missing-file"
173 (
174 set -e
175
176 # setup a git repo to be used as a local repo, not remote
177 reponame="standalone-file-download-missing-file"
178 setup_remote_repo "$reponame"
179
180 otherrepo="$(pwd)/$reponame-2.git"
181 git init --bare "$otherrepo"
182
183 # clone directly, not through lfstest-gitserver
184 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
185
186 git remote set-url origin "file://$(urlify "$otherrepo")"
187
188 git lfs track "*.dat" 2>&1 | tee track.log
189 grep "Tracking \"\*.dat\"" track.log
190 git add .gitattributes
191 git commit -m "Tracking"
192
193 git checkout -b test
194
195 # set up a decent amount of data so that there's work for multiple concurrent adapters
196 echo "[
197 {
198 \"CommitDate\":\"$(get_date -10d)\",
199 \"Files\":[
200 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
201 {\"Filename\":\"file1.dat\",\"Size\":1024},
202 {\"Filename\":\"file2.dat\",\"Size\":750}]
203 },
204 {
205 \"CommitDate\":\"$(get_date -7d)\",
206 \"Files\":[
207 {\"Filename\":\"file1.dat\",\"Size\":1050},
208 {\"Filename\":\"file3.dat\",\"Size\":660},
209 {\"Filename\":\"file4.dat\",\"Size\":230}]
210 },
211 {
212 \"CommitDate\":\"$(get_date -5d)\",
213 \"Files\":[
214 {\"Filename\":\"file5.dat\",\"Size\":1200},
215 {\"Filename\":\"file6.dat\",\"Size\":300}]
216 },
217 {
218 \"CommitDate\":\"$(get_date -2d)\",
219 \"Files\":[
220 {\"Filename\":\"file3.dat\",\"Size\":120},
221 {\"Filename\":\"file5.dat\",\"Size\":450},
222 {\"Filename\":\"file7.dat\",\"Size\":520},
223 {\"Filename\":\"file8.dat\",\"Size\":2048}]
224 }
225 ]" | lfstest-testutils addcommits
226
227 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin test 2>&1 | tee pushcustom.log
228 # use PIPESTATUS otherwise we get exit code from tee
229 [ ${PIPESTATUS[0]} = "0" ]
230
231 # Make sure the lock verification is not attempted.
232 grep "locks/verify$" pushcustom.log && false
233
234 grep "xfer: started custom adapter process" pushcustom.log
235 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
236
237 # Delete an object from the remote side. Any object will do.
238 rm -f $(find "$otherrepo/lfs/objects" -type f | head -n1)
239
240 rm -rf .git/lfs/objects
241 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetchcustom.log
242 # Make sure we failed.
243 [ ${PIPESTATUS[0]} != "0" ]
244
245 # Make sure we downloaded the rest of the objects.
246 objectlist=$(find .git/lfs/objects -type f)
247 [ "$(echo "$objectlist" | wc -l)" -eq 11 ]
248 )
249 end_test
250
251 begin_test "standalone-file-clone"
252 (
253 set -e
254
255 # setup a git repo to be used as a local repo, not remote
256 reponame="standalone-file-clone"
257 setup_remote_repo "$reponame"
258
259 # clone directly, not through lfstest-gitserver
260 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
261
262 git lfs track "*.dat" 2>&1 | tee track.log
263 grep "Tracking \"\*.dat\"" track.log
264 git add .gitattributes
265 git commit -m "Tracking"
266
267 git checkout -b test
268
269 # set up a decent amount of data so that there's work for multiple concurrent adapters
270 echo "[
271 {
272 \"CommitDate\":\"$(get_date -10d)\",
273 \"Files\":[
274 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
275 {\"Filename\":\"file1.dat\",\"Size\":1024},
276 {\"Filename\":\"file2.dat\",\"Size\":750}]
277 },
278 {
279 \"CommitDate\":\"$(get_date -7d)\",
280 \"Files\":[
281 {\"Filename\":\"file1.dat\",\"Size\":1050},
282 {\"Filename\":\"file3.dat\",\"Size\":660},
283 {\"Filename\":\"file4.dat\",\"Size\":230}]
284 },
285 {
286 \"CommitDate\":\"$(get_date -5d)\",
287 \"Files\":[
288 {\"Filename\":\"file5.dat\",\"Size\":1200},
289 {\"Filename\":\"file6.dat\",\"Size\":300}]
290 },
291 {
292 \"CommitDate\":\"$(get_date -2d)\",
293 \"Files\":[
294 {\"Filename\":\"file3.dat\",\"Size\":120},
295 {\"Filename\":\"file5.dat\",\"Size\":450},
296 {\"Filename\":\"file7.dat\",\"Size\":520},
297 {\"Filename\":\"file8.dat\",\"Size\":2048}]
298 }
299 ]" | lfstest-testutils addcommits
300
301 testdir="$(pwd)"
302
303 cd "$TRASHDIR"
304
305 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git clone "file://$(urlify "$testdir")" repo3 2>&1 | tee clonecustom.log
306
307 grep "xfer: started custom adapter process" clonecustom.log
308 )
309 end_test
310
311 begin_test "standalone-file-local-path"
312 (
313 set -e
314
315 # setup a git repo to be used as a local repo, not remote
316 reponame="standalone-file-local-path"
317 setup_remote_repo "$reponame"
318
319 # clone directly, not through lfstest-gitserver
320 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
321
322 do_local_path_test "$reponame" ""
323 )
324 end_test
325
326 begin_test "standalone-file-local-path-trailing-slash"
327 (
328 set -e
329
330 # setup a git repo to be used as a local repo, not remote
331 reponame="standalone-file-local-path-trailing-slash"
332 setup_remote_repo "$reponame"
333
334 # clone directly, not through lfstest-gitserver
335 clone_repo_url "$REMOTEDIR/$reponame.git/" $reponame
336
337 do_local_path_test "$reponame" "$suffix"
338 )
339 end_test
340
341 begin_test "standalone-file-lfs.url file URL"
342 (
343 set -e
344
345 # setup a git repo to be used as a local repo, not remote
346 reponame="standalone-file-lfsurl"
347 setup_remote_repo "$reponame"
348
349 # clone directly, not through lfstest-gitserver
350 clone_repo_url "$REMOTEDIR/$reponame.git" $reponame
351
352 otherrepo="$(pwd)/$reponame-2.git"
353 git init --bare "$otherrepo"
354
355 wrongrepo="$(pwd)/$reponame-3.git"
356 git init --bare "$wrongrepo"
357
358 git remote set-url origin "file://$(urlify "$wrongrepo")"
359 git config lfs.url "file://$(urlify "$otherrepo")"
360
361 git lfs track "*.dat" 2>&1 | tee track.log
362 grep "Tracking \"\*.dat\"" track.log
363 git add .gitattributes
364 git commit -m "Tracking"
365
366 git checkout -b test
367
368 # set up a decent amount of data so that there's work for multiple concurrent adapters
369 echo "[
370 {
371 \"CommitDate\":\"$(get_date -10d)\",
372 \"Files\":[
373 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
374 {\"Filename\":\"file1.dat\",\"Size\":1024},
375 {\"Filename\":\"file2.dat\",\"Size\":750}]
376 },
377 {
378 \"CommitDate\":\"$(get_date -7d)\",
379 \"Files\":[
380 {\"Filename\":\"file1.dat\",\"Size\":1050},
381 {\"Filename\":\"file3.dat\",\"Size\":660},
382 {\"Filename\":\"file4.dat\",\"Size\":230}]
383 },
384 {
385 \"CommitDate\":\"$(get_date -5d)\",
386 \"Files\":[
387 {\"Filename\":\"file5.dat\",\"Size\":1200},
388 {\"Filename\":\"file6.dat\",\"Size\":300}]
389 },
390 {
391 \"CommitDate\":\"$(get_date -2d)\",
392 \"Files\":[
393 {\"Filename\":\"file3.dat\",\"Size\":120},
394 {\"Filename\":\"file5.dat\",\"Size\":450},
395 {\"Filename\":\"file7.dat\",\"Size\":520},
396 {\"Filename\":\"file8.dat\",\"Size\":2048}]
397 }
398 ]" | lfstest-testutils addcommits
399
400 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin test 2>&1 | tee pushcustom.log
401 # use PIPESTATUS otherwise we get exit code from tee
402 [ ${PIPESTATUS[0]} = "0" ]
403
404 # Make sure the lock verification is not attempted.
405 grep "locks/verify$" pushcustom.log && false
406
407 grep "xfer: started custom adapter process" pushcustom.log
408 grep "Uploading LFS objects: 100% (12/12)" pushcustom.log
409
410 # Make sure we didn't write to the wrong repo.
411 objectlist=$(find "$wrongrepo/lfs/objects" -type f || true)
412 [ -z "$objectlist" ]
413
414 # Make sure we uploaded the expected number of objects.
415 objectlist=$(find "$otherrepo/lfs/objects" -type f || true)
416 [ "$(echo "$objectlist" | wc -l)" -eq 12 ]
417 )
418 end_test
419
420 begin_test "standalone-file-lfs.url http URL"
421 (
422 set -e
423
424 reponame="standalone-file-lfsurl-http"
425 setup_remote_repo "$reponame"
426
427 # clone directly, not through lfstest-gitserver
428 clone_repo "$reponame" "$reponame"
429
430 wrongrepo="$(pwd)/$reponame-2.git"
431 git init --bare "$wrongrepo"
432
433 git remote set-url origin "file://$(urlify "$wrongrepo")"
434 git config lfs.url "$(repo_endpoint "$GITSERVER" "$reponame")"
435
436 git lfs track "*.dat" 2>&1 | tee track.log
437 grep "Tracking \"\*.dat\"" track.log
438 git add .gitattributes
439 git commit -m "Tracking"
440
441 git checkout -b test
442
443 # set up a decent amount of data so that there's work for multiple concurrent adapters
444 echo "[
445 {
446 \"CommitDate\":\"$(get_date -10d)\",
447 \"Files\":[
448 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
449 {\"Filename\":\"file1.dat\",\"Size\":1024},
450 {\"Filename\":\"file2.dat\",\"Size\":750}]
451 },
452 {
453 \"CommitDate\":\"$(get_date -7d)\",
454 \"Files\":[
455 {\"Filename\":\"file1.dat\",\"Size\":1050},
456 {\"Filename\":\"file3.dat\",\"Size\":660},
457 {\"Filename\":\"file4.dat\",\"Size\":230}]
458 },
459 {
460 \"CommitDate\":\"$(get_date -5d)\",
461 \"Files\":[
462 {\"Filename\":\"file5.dat\",\"Size\":1200},
463 {\"Filename\":\"file6.dat\",\"Size\":300}]
464 },
465 {
466 \"CommitDate\":\"$(get_date -2d)\",
467 \"Files\":[
468 {\"Filename\":\"file3.dat\",\"Size\":120},
469 {\"Filename\":\"file5.dat\",\"Size\":450},
470 {\"Filename\":\"file7.dat\",\"Size\":520},
471 {\"Filename\":\"file8.dat\",\"Size\":2048}]
472 }
473 ]" | lfstest-testutils addcommits
474
475 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin test 2>&1 | tee push.log
476 # use PIPESTATUS otherwise we get exit code from tee
477 [ ${PIPESTATUS[0]} = "0" ]
478
479 # We should not use the custom adapter process here.
480 grep "xfer: started custom adapter process" push.log && exit 1
481 grep -F "$GITSERVER/$reponame" push.log
482
483 # Make sure we didn't write to the wrong repo.
484 objectlist=$(find "$wrongrepo/lfs/objects" -type f || true)
485 [ -z "$objectlist" ]
486
487 rm -fr .git/lfs/objects
488
489 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs fetch --all 2>&1 | tee fetch.log
490 grep "xfer: started custom adapter process" fetch.log && exit 1
491 grep -F "$GITSERVER/$reponame" fetch.log
492
493 git lfs fsck
494 )
495 end_test
496
497 begin_test "standalone-file error"
498 (
499 set -e
500
501 reponame="standalone-file-error"
502 setup_remote_repo "$reponame"
503
504 # clone directly, not through lfstest-gitserver
505 clone_repo "$reponame" "$reponame"
506
507 otherrepo="$(pwd)/$reponame-2.git"
508 mkdir "$otherrepo"
509
510 git remote set-url origin "file://$(urlify "$otherrepo")"
511
512 git lfs track "*.dat" 2>&1 | tee track.log
513 grep "Tracking \"\*.dat\"" track.log
514 git add .gitattributes
515 git commit -m "Tracking"
516
517 git checkout -b test
518
519 # set up a decent amount of data so that there's work for multiple concurrent adapters
520 echo "[
521 {
522 \"CommitDate\":\"$(get_date -10d)\",
523 \"Files\":[
524 {\"Filename\":\"verify.dat\",\"Size\":18,\"Data\":\"send-verify-action\"},
525 {\"Filename\":\"file1.dat\",\"Size\":1024},
526 {\"Filename\":\"file2.dat\",\"Size\":750}]
527 },
528 {
529 \"CommitDate\":\"$(get_date -7d)\",
530 \"Files\":[
531 {\"Filename\":\"file1.dat\",\"Size\":1050},
532 {\"Filename\":\"file3.dat\",\"Size\":660},
533 {\"Filename\":\"file4.dat\",\"Size\":230}]
534 },
535 {
536 \"CommitDate\":\"$(get_date -5d)\",
537 \"Files\":[
538 {\"Filename\":\"file5.dat\",\"Size\":1200},
539 {\"Filename\":\"file6.dat\",\"Size\":300}]
540 },
541 {
542 \"CommitDate\":\"$(get_date -2d)\",
543 \"Files\":[
544 {\"Filename\":\"file3.dat\",\"Size\":120},
545 {\"Filename\":\"file5.dat\",\"Size\":450},
546 {\"Filename\":\"file7.dat\",\"Size\":520},
547 {\"Filename\":\"file8.dat\",\"Size\":2048}]
548 }
549 ]" | lfstest-testutils addcommits
550
551 if git push origin test 2>pusherror.log
552 then
553 exit 1
554 fi
555 cat pusherror.log
556 grep 'not.*a git repository' pusherror.log
557 )
558 end_test