Debian Codegraph @

t/t-clone.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 ensure_git_version_isnt $VERSION_LOWER "2.2.0"
6
7 export CREDSDIR="$REMOTEDIR/creds-clone"
8 setup_creds
9
10 begin_test "clone"
11 (
12 set -e
13
14 reponame="$(basename "$0" ".sh")"
15 setup_remote_repo "$reponame"
16 clone_repo "$reponame" repo
17
18 git lfs track "*.dat" 2>&1 | tee track.log
19 grep "Tracking \"\*.dat\"" track.log
20 git add .gitattributes
21 git commit -m "Track *.dat"
22
23 # generate some test data & commits with random LFS data
24 echo "[
25 {
26 \"CommitDate\":\"$(get_date -10d)\",
27 \"Files\":[
28 {\"Filename\":\"file1.dat\",\"Size\":100},
29 {\"Filename\":\"file2.dat\",\"Size\":75}]
30 },
31 {
32 \"CommitDate\":\"$(get_date -7d)\",
33 \"Files\":[
34 {\"Filename\":\"file1.dat\",\"Size\":110},
35 {\"Filename\":\"file3.dat\",\"Size\":66},
36 {\"Filename\":\"file4.dat\",\"Size\":23}]
37 },
38 {
39 \"CommitDate\":\"$(get_date -10d)\",
40 \"Files\":[
41 {\"Filename\":\"file5.dat\",\"Size\":120},
42 {\"Filename\":\"file6.dat\",\"Size\":30}]
43 }
44 ]" | lfstest-testutils addcommits
45
46 git push origin main
47
48 # Now clone again, test specific clone dir
49 cd "$TRASHDIR"
50
51 newclonedir="testclone1"
52 git lfs clone "$GITSERVER/$reponame" "$newclonedir" 2>&1 | tee lfsclone.log
53 grep "Cloning into" lfsclone.log
54 grep "Downloading LFS objects:" lfsclone.log
55 # should be no filter errors
56 grep "filter" lfsclone.log && exit 1
57 grep "error" lfsclone.log && exit 1
58 # should be cloned into location as per arg
59 [ -d "$newclonedir" ]
60
61 # check a few file sizes to make sure pulled
62 pushd "$newclonedir"
63 [ $(wc -c < "file1.dat") -eq 110 ]
64 [ $(wc -c < "file2.dat") -eq 75 ]
65 [ $(wc -c < "file3.dat") -eq 66 ]
66 assert_hooks "$(dot_git_dir)"
67 [ ! -e "lfs" ]
68 assert_clean_status
69 popd
70
71 # Now check clone with implied dir
72 rm -rf "$reponame"
73 git lfs clone "$GITSERVER/$reponame" 2>&1 | tee lfsclone.log
74 grep "Cloning into" lfsclone.log
75 grep "Downloading LFS objects:" lfsclone.log
76 # should be no filter errors
77 grep "filter" lfsclone.log && exit 1
78 grep "error" lfsclone.log && exit 1
79 # clone location should be implied
80 [ -d "$reponame" ]
81
82 pushd "$reponame"
83 [ $(wc -c < "file1.dat") -eq 110 ]
84 [ $(wc -c < "file2.dat") -eq 75 ]
85 [ $(wc -c < "file3.dat") -eq 66 ]
86 assert_hooks "$(dot_git_dir)"
87 [ ! -e "lfs" ]
88 assert_clean_status
89 popd
90
91 # Now check clone with standard 'git clone' and smudge download
92 rm -rf "$reponame"
93 git clone "$GITSERVER/$reponame" 2>&1 | tee clone.log
94 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
95 echo >&2 "fatal: expected clone to succeed ..."
96 exit 1
97 fi
98 grep "Cloning into" clone.log
99 [ -d "$reponame" ]
100
101 pushd "$reponame"
102 [ $(wc -c < "file1.dat") -eq 110 ]
103 [ $(wc -c < "file2.dat") -eq 75 ]
104 [ $(wc -c < "file3.dat") -eq 66 ]
105 assert_hooks "$(dot_git_dir)"
106 [ ! -e "lfs" ]
107 [ "6" -eq "$(find "$(dot_git_dir)/lfs/objects" -type f | wc -l)" ]
108 assert_clean_status
109 popd
110 )
111 end_test
112
113 begin_test "cloneSSL"
114 (
115 set -e
116
117 if [ "$IS_WINDOWS" -eq 1 ]; then
118 git config --global "http.sslBackend" "openssl"
119 fi
120
121 reponame="test-cloneSSL"
122 setup_remote_repo "$reponame"
123 clone_repo_ssl "$reponame" "$reponame"
124
125 git lfs track "*.dat" 2>&1 | tee track.log
126 grep "Tracking \"\*.dat\"" track.log
127 git add .gitattributes
128 git commit -m "Track *.dat"
129
130 # generate some test data & commits with random LFS data
131 echo "[
132 {
133 \"CommitDate\":\"$(get_date -5d)\",
134 \"Files\":[
135 {\"Filename\":\"file1.dat\",\"Size\":100},
136 {\"Filename\":\"file2.dat\",\"Size\":75}]
137 },
138 {
139 \"CommitDate\":\"$(get_date -1d)\",
140 \"Files\":[
141 {\"Filename\":\"file3.dat\",\"Size\":30}]
142 }
143 ]" | lfstest-testutils addcommits
144
145 git push origin main
146
147 # Now SSL clone again with 'git lfs clone', test specific clone dir
148 cd "$TRASHDIR"
149
150 newclonedir="testcloneSSL1"
151 git lfs clone "$SSLGITSERVER/$reponame" "$newclonedir" 2>&1 | tee lfsclone.log
152 grep "Cloning into" lfsclone.log
153 grep "Downloading LFS objects:" lfsclone.log
154 # should be no filter errors
155 grep "filter" lfsclone.log && exit 1
156 grep "error" lfsclone.log && exit 1
157 # should be cloned into location as per arg
158 [ -d "$newclonedir" ]
159
160 # check a few file sizes to make sure pulled
161 pushd "$newclonedir"
162 [ $(wc -c < "file1.dat") -eq 100 ]
163 [ $(wc -c < "file2.dat") -eq 75 ]
164 [ $(wc -c < "file3.dat") -eq 30 ]
165 assert_hooks "$(dot_git_dir)"
166 [ ! -e "lfs" ]
167 assert_clean_status
168 popd
169
170 # Now check SSL clone with standard 'git clone' and smudge download
171 rm -rf "$reponame"
172 git clone "$SSLGITSERVER/$reponame" 2>&1 | tee clone.log
173 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
174 echo >&2 "fatal: expected clone to succeed ..."
175 exit 1
176 fi
177 grep "Cloning into" clone.log
178 [ -d "$reponame" ]
179
180 pushd "$reponame"
181 [ $(wc -c < "file1.dat") -eq 100 ]
182 [ $(wc -c < "file2.dat") -eq 75 ]
183 [ $(wc -c < "file3.dat") -eq 30 ]
184 assert_hooks "$(dot_git_dir)"
185 [ ! -e "lfs" ]
186 [ "3" -eq "$(find "$(dot_git_dir)/lfs/objects" -type f | wc -l)" ]
187 assert_clean_status
188 popd
189 )
190 end_test
191
192 begin_test "clone ClientCert"
193 (
194 set -e
195
196 if [ "$IS_WINDOWS" -eq 1 ]; then
197 git config --global "http.sslBackend" "openssl"
198 fi
199
200 # Note that the record files we create in the $CREDSDIR directory are not
201 # used until we set the "http.sslCertPasswordProtected" option to "true"
202 # and the "http.<url>.sslKey" option with the path to our TLS/SSL client
203 # certificate's encrypted private key file. (The PEM certificate file
204 # itself is not encrypted and does not contain the private key.)
205 #
206 # When these options are set, however, Git and Git LFS will independently
207 # invoke "git credential fill" to retrieve the passphrase for the
208 # encrypted private key. Because the "http.sslCertPasswordProtected"
209 # option is set, Git will query the credential helper, passing a
210 # "protocol=cert" line and a "path=<certfile>" line with the path
211 # from the "http.<url>.sslCert" option. Note that this path refers
212 # to our unencrypted certificate file; Git does not use the path to
213 # the encrypted private key file from the "http.<url>.sslKey" option
214 # in its query to the credential helper.
215 #
216 # Separately, the Git LFS client will detect that the private key file
217 # specified by the "http.<url>.sslKey" option is encrypted, and so will
218 # invoke "git credential fill" to retrieve its passphrase, passing a
219 # "protocol=cert" line and a "path=<keyfile>" line with the path
220 # from the "http.<url>.sslKey" option.
221 #
222 # In order to satisfy both requests, our git-credential-lfstest helper
223 # therefore needs two record files, both with the passphrase for the
224 # encrypted private key file. For Git, one is associated with the path
225 # to the certificate file, and for Git LFS, one is associated with the
226 # path to the key file.
227 write_creds_file "::pass" "$CREDSDIR/--$(echo "$LFS_CLIENT_CERT_FILE" | tr / -)"
228 write_creds_file "::pass" "$CREDSDIR/--$(echo "$LFS_CLIENT_KEY_FILE_ENCRYPTED" | tr / -)"
229
230 git config --global "http.$LFS_CLIENT_CERT_URL/.sslCert" "$LFS_CLIENT_CERT_FILE"
231 git config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "$LFS_CLIENT_KEY_FILE"
232
233 reponame="test-cloneClientCert"
234 setup_remote_repo "$reponame"
235 clone_repo_clientcert "$reponame" "$reponame"
236
237 git lfs track "*.dat" 2>&1 | tee track.log
238 grep "Tracking \"\*.dat\"" track.log
239 git add .gitattributes
240 git commit -m "Track *.dat"
241
242 # generate some test data & commits with random LFS data
243 echo "[
244 {
245 \"CommitDate\":\"$(get_date -5d)\",
246 \"Files\":[
247 {\"Filename\":\"file1.dat\",\"Size\":100},
248 {\"Filename\":\"file2.dat\",\"Size\":75}]
249 },
250 {
251 \"CommitDate\":\"$(get_date -1d)\",
252 \"Files\":[
253 {\"Filename\":\"file3.dat\",\"Size\":30}]
254 }
255 ]" | lfstest-testutils addcommits
256
257 git push origin main
258
259 # Now clone again with 'git lfs clone', test specific clone dir
260 # Test with both unencrypted and encrypted client certificate keys
261 cd "$TRASHDIR"
262
263 for enc in "false" "true"; do
264 if [ "$enc" = "true" ]; then
265 git config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "$LFS_CLIENT_KEY_FILE_ENCRYPTED"
266 git config --global "http.sslCertPasswordProtected" "$enc"
267 fi
268
269 newclonedir="${reponame}-${enc}"
270 git lfs clone "$CLIENTCERTGITSERVER/$reponame" "$newclonedir" 2>&1 | tee lfsclone.log
271 grep "Cloning into" lfsclone.log
272 grep "Downloading LFS objects:" lfsclone.log
273 # should be no filter errors
274 grep "filter" lfsclone.log && exit 1
275 grep "error" lfsclone.log && exit 1
276 # should be cloned into location as per arg
277 [ -d "$newclonedir" ]
278
279 # check a few file sizes to make sure pulled
280 pushd "$newclonedir"
281 [ $(wc -c < "file1.dat") -eq 100 ]
282 [ $(wc -c < "file2.dat") -eq 75 ]
283 [ $(wc -c < "file3.dat") -eq 30 ]
284 assert_hooks "$(dot_git_dir)"
285 [ ! -e "lfs" ]
286 assert_clean_status
287 popd
288
289 # Now check clone with standard 'git clone' and smudge download
290 rm -rf "$reponame"
291 git clone "$CLIENTCERTGITSERVER/$reponame" 2>&1 | tee clone.log
292 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
293 echo >&2 "fatal: expected clone to succeed ..."
294 exit 1
295 fi
296 grep "Cloning into" clone.log
297 [ -d "$reponame" ]
298
299 pushd "$reponame"
300 [ $(wc -c < "file1.dat") -eq 100 ]
301 [ $(wc -c < "file2.dat") -eq 75 ]
302 [ $(wc -c < "file3.dat") -eq 30 ]
303 assert_hooks "$(dot_git_dir)"
304 [ ! -e "lfs" ]
305 [ "3" -eq "$(find "$(dot_git_dir)/lfs/objects" -type f | wc -l)" ]
306 assert_clean_status
307 popd
308 done
309 )
310 end_test
311
312 begin_test "clone ClientCert with homedir certs"
313 (
314 set -e
315
316 if [ "$IS_WINDOWS" -eq 1 ]; then
317 git config --global "http.sslBackend" "openssl"
318 fi
319
320 cp "$LFS_CLIENT_CERT_FILE" "$HOME/lfs-client-cert-file"
321 cp "$LFS_CLIENT_KEY_FILE" "$HOME/lfs-client-key-file"
322 cp "$LFS_CLIENT_KEY_FILE_ENCRYPTED" "$HOME/lfs-client-key-file-encrypted"
323
324 # Note that the record files we create in the $CREDSDIR directory are not
325 # used until we set the "http.sslCertPasswordProtected" option to "true"
326 # and the "http.<url>.sslKey" option with the path to our TLS/SSL client
327 # certificate's encrypted private key file. (The PEM certificate file
328 # itself is not encrypted and does not contain the private key.)
329 #
330 # When these options are set, however, Git and Git LFS will independently
331 # invoke "git credential fill" to retrieve the passphrase for the
332 # encrypted private key. Because the "http.sslCertPasswordProtected"
333 # option is set, Git will query the credential helper, passing a
334 # "protocol=cert" line and a "path=<certfile>" line with the path
335 # from the "http.<url>.sslCert" option. Note that this path refers
336 # to our unencrypted certificate file; Git does not use the path to
337 # the encrypted private key file from the "http.<url>.sslKey" option
338 # in its query to the credential helper.
339 #
340 # Separately, the Git LFS client will detect that the private key file
341 # specified by the "http.<url>.sslKey" option is encrypted, and so will
342 # invoke "git credential fill" to retrieve its passphrase, passing a
343 # "protocol=cert" line and a "path=<keyfile>" line with the path
344 # from the "http.<url>.sslKey" option.
345 #
346 # In order to satisfy both requests, our git-credential-lfstest helper
347 # therefore needs two record files, both with the passphrase for the
348 # encrypted private key file. For Git, one is associated with the path
349 # to the certificate file, and for Git LFS, one is associated with the
350 # path to the key file.
351 if [ "$IS_WINDOWS" -eq 1 ]; then
352 # In our MSYS2 CI environment we have to convert the Unix-style path
353 # in $HOME, which starts with /tmp/, into a path of the form /a/...
354 # so that the credential record filename we create from it matches
355 # the one our git-credential-lfstest helper will construct from the
356 # "path" values it receives from Git and Git LFS.
357 homedir="$(cygpath -m "$HOME" | sed 's,^\([A-Z]\):,/\L\1,')"
358 else
359 homedir="$HOME"
360 fi
361 write_creds_file "::pass" "$CREDSDIR/--$(echo "$homedir/lfs-client-cert-file" | tr / -)"
362 write_creds_file "::pass" "$CREDSDIR/--$(echo "$homedir/lfs-client-key-file-encrypted" | tr / -)"
363
364 git config --global "http.$LFS_CLIENT_CERT_URL/.sslCert" "~/lfs-client-cert-file"
365 git config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "~/lfs-client-key-file"
366
367 reponame="test-cloneClientCert-homedir"
368 setup_remote_repo "$reponame"
369 clone_repo_clientcert "$reponame" "$reponame"
370
371 git lfs track "*.dat" 2>&1 | tee track.log
372 grep "Tracking \"\*.dat\"" track.log
373 git add .gitattributes
374 git commit -m "Track *.dat"
375
376 # generate some test data & commits with random LFS data
377 echo "[
378 {
379 \"CommitDate\":\"$(get_date -5d)\",
380 \"Files\":[
381 {\"Filename\":\"file1.dat\",\"Size\":100},
382 {\"Filename\":\"file2.dat\",\"Size\":75}]
383 },
384 {
385 \"CommitDate\":\"$(get_date -1d)\",
386 \"Files\":[
387 {\"Filename\":\"file3.dat\",\"Size\":30}]
388 }
389 ]" | lfstest-testutils addcommits
390
391 git push origin main
392
393 # Now clone again with 'git lfs clone', test specific clone dir
394 # Test with both unencrypted and encrypted client certificate keys
395 cd "$TRASHDIR"
396
397 for enc in "false" "true"; do
398 if [ "$enc" = "true" ]; then
399 git config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "~/lfs-client-key-file-encrypted"
400 git config --global "http.sslCertPasswordProtected" "$enc"
401 fi
402
403 newclonedir="${reponame}-${enc}"
404 git lfs clone "$CLIENTCERTGITSERVER/$reponame" "$newclonedir" 2>&1 | tee lfsclone.log
405 grep "Cloning into" lfsclone.log
406 grep "Downloading LFS objects:" lfsclone.log
407 # should be no filter errors
408 grep "filter" lfsclone.log && exit 1
409 grep "error" lfsclone.log && exit 1
410 # should be cloned into location as per arg
411 [ -d "$newclonedir" ]
412
413 # check a few file sizes to make sure pulled
414 pushd "$newclonedir"
415 [ $(wc -c < "file1.dat") -eq 100 ]
416 [ $(wc -c < "file2.dat") -eq 75 ]
417 [ $(wc -c < "file3.dat") -eq 30 ]
418 assert_hooks "$(dot_git_dir)"
419 [ ! -e "lfs" ]
420 assert_clean_status
421 popd
422
423 # Now check clone with standard 'git clone' and smudge download
424 rm -rf "$reponame"
425 git clone "$CLIENTCERTGITSERVER/$reponame" 2>&1 | tee clone.log
426 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
427 echo >&2 "fatal: expected clone to succeed ..."
428 exit 1
429 fi
430 grep "Cloning into" clone.log
431 [ -d "$reponame" ]
432
433 pushd "$reponame"
434 [ $(wc -c < "file1.dat") -eq 100 ]
435 [ $(wc -c < "file2.dat") -eq 75 ]
436 [ $(wc -c < "file3.dat") -eq 30 ]
437 assert_hooks "$(dot_git_dir)"
438 [ ! -e "lfs" ]
439 [ "3" -eq "$(find "$(dot_git_dir)/lfs/objects" -type f | wc -l)" ]
440 assert_clean_status
441 popd
442 done
443 )
444 end_test
445
446 begin_test "clone with flags"
447 (
448 set -e
449
450 reponame="$(basename "$0" ".sh")-flags"
451 setup_remote_repo "$reponame"
452 clone_repo "$reponame" "$reponame"
453
454 git lfs track "*.dat" 2>&1 | tee track.log
455 grep "Tracking \"\*.dat\"" track.log
456 git add .gitattributes
457 git commit -m "Track *.dat"
458
459 # generate some test data & commits with random LFS data
460 echo "[
461 {
462 \"CommitDate\":\"$(get_date -10d)\",
463 \"Files\":[
464 {\"Filename\":\"file1.dat\",\"Size\":100},
465 {\"Filename\":\"file2.dat\",\"Size\":75}]
466 },
467 {
468 \"CommitDate\":\"$(get_date -7d)\",
469 \"NewBranch\":\"branch2\",
470 \"Files\":[
471 {\"Filename\":\"fileonbranch2.dat\",\"Size\":66}]
472 },
473 {
474 \"CommitDate\":\"$(get_date -3d)\",
475 \"ParentBranches\":[\"main\"],
476 \"Files\":[
477 {\"Filename\":\"file3.dat\",\"Size\":120},
478 {\"Filename\":\"file4.dat\",\"Size\":30}]
479 }
480 ]" | lfstest-testutils addcommits
481
482 git push origin main branch2
483
484 # Now clone again, test specific clone dir
485 cd "$TRASHDIR"
486 mkdir "$TRASHDIR/templatedir"
487
488 newclonedir="testflagsclone1"
489 # many of these flags won't do anything but make sure they're not rejected
490 git lfs clone --template "$TRASHDIR/templatedir" --local --no-hardlinks --shared --verbose --progress --recursive "$GITSERVER/$reponame" "$newclonedir"
491 rm -rf "$newclonedir"
492
493 # specific test for --no-checkout
494 git lfs clone --quiet --no-checkout "$GITSERVER/$reponame" "$newclonedir"
495 if [ -e "$newclonedir/file1.dat" ]; then
496 exit 1
497 fi
498 rm -rf "$newclonedir"
499
500 # specific test for --branch and --origin
501 git lfs clone --branch branch2 --recurse-submodules --origin differentorigin "$GITSERVER/$reponame" "$newclonedir"
502 pushd "$newclonedir"
503 # this file is only on branch2
504 [ -e "fileonbranch2.dat" ]
505 # confirm remote is called differentorigin
506 git remote get-url differentorigin
507 assert_hooks "$(dot_git_dir)"
508 [ ! -e "lfs" ]
509 assert_clean_status
510 popd
511 rm -rf "$newclonedir"
512
513 # specific test for --separate-git-dir
514 gitdir="$TRASHDIR/separategitdir"
515 git lfs clone --separate-git-dir "$gitdir" "$GITSERVER/$reponame" "$newclonedir"
516 # .git should be a file not dir
517 if [ -d "$newclonedir/.git" ]; then
518 exit 1
519 fi
520 [ -e "$newclonedir/.git" ]
521 [ -d "$gitdir/objects" ]
522 assert_hooks "$gitdir"
523 pushd "$newclonedir"
524 [ ! -e "lfs" ]
525 assert_clean_status
526 popd
527 rm -rf "$newclonedir"
528 rm -rf "$gitdir"
529
530 # specific test for --bare
531 git lfs clone --bare "$GITSERVER/$reponame" "$newclonedir"
532 [ -d "$newclonedir/objects" ]
533 rm -rf "$newclonedir"
534
535 # short flags
536 git lfs clone -l -v -n -s -b branch2 "$GITSERVER/$reponame" "$newclonedir"
537 rm -rf "$newclonedir"
538 )
539 end_test
540
541 begin_test "clone (with include/exclude args)"
542 (
543 set -e
544
545 reponame="clone_include_exclude"
546 setup_remote_repo "$reponame"
547 clone_repo "$reponame" "$reponame"
548
549 git lfs track "*.dat" 2>&1 | tee track.log
550 grep "Tracking \"\*.dat\"" track.log
551
552 contents_a="a"
553 contents_a_oid=$(calc_oid "$contents_a")
554 printf "%s" "$contents_a" > "a.dat"
555 printf "%s" "$contents_a" > "a-dupe.dat"
556 printf "%s" "$contents_a" > "dupe-a.dat"
557
558 contents_b="b"
559 contents_b_oid=$(calc_oid "$contents_b")
560 printf "%s" "$contents_b" > "b.dat"
561
562 git add *.dat .gitattributes
563 git commit -m "add a.dat, b.dat" 2>&1 | tee commit.log
564 grep "main (root-commit)" commit.log
565 grep "5 files changed" commit.log
566 grep "create mode 100644 a.dat" commit.log
567 grep "create mode 100644 a-dupe.dat" commit.log
568 grep "create mode 100644 dupe-a.dat" commit.log
569 grep "create mode 100644 b.dat" commit.log
570 grep "create mode 100644 .gitattributes" commit.log
571
572 git push origin main 2>&1 | tee push.log
573 grep "main -> main" push.log
574 grep "Uploading LFS objects: 100% (2/2), 2 B" push.log
575
576 cd "$TRASHDIR"
577
578 local_reponame="clone_with_includes"
579 git lfs clone "$GITSERVER/$reponame" "$local_reponame" -I "a*.dat"
580 pushd "$local_reponame"
581 assert_local_object "$contents_a_oid" 1
582 refute_local_object "$contents_b_oid"
583 [ "a" = "$(cat a.dat)" ]
584 [ "a" = "$(cat a-dupe.dat)" ]
585 [ "$(pointer $contents_a_oid 1)" = "$(cat dupe-a.dat)" ]
586 [ "$(pointer $contents_b_oid 1)" = "$(cat b.dat)" ]
587 assert_hooks "$(dot_git_dir)"
588 [ ! -e "lfs" ]
589 assert_clean_status
590 popd
591
592 local_reponame="clone_with_excludes"
593 git lfs clone "$GITSERVER/$reponame" "$local_reponame" -I "b.dat" -X "a.dat"
594 pushd "$local_reponame"
595 assert_local_object "$contents_b_oid" 1
596 refute_local_object "$contents_a_oid"
597 [ "$(pointer $contents_a_oid 1)" = "$(cat a.dat)" ]
598 [ "b" = "$(cat b.dat)" ]
599 assert_hooks "$(dot_git_dir)"
600 [ ! -e "lfs" ]
601 assert_clean_status
602 popd
603 )
604 end_test
605
606 begin_test "clone (with .lfsconfig)"
607 (
608 set -e
609
610 reponame="clone_with_lfsconfig"
611 setup_remote_repo "$reponame"
612 clone_repo "$reponame" "$reponame"
613
614 git lfs track "*.dat" 2>&1 | tee track.log
615 grep "Tracking \"\*.dat\"" track.log
616
617 contents_a="a"
618 contents_a_oid=$(calc_oid "$contents_a")
619 printf "%s" "$contents_a" > "a.dat"
620
621 contents_b="b"
622 contents_b_oid=$(calc_oid "$contents_b")
623 printf "%s" "$contents_b" > "b.dat"
624
625 git add a.dat b.dat .gitattributes
626 git commit -m "add a.dat, b.dat" 2>&1 | tee commit.log
627 grep "main (root-commit)" commit.log
628 grep "3 files changed" commit.log
629 grep "create mode 100644 a.dat" commit.log
630 grep "create mode 100644 b.dat" commit.log
631 grep "create mode 100644 .gitattributes" commit.log
632
633 git config -f ".lfsconfig" "lfs.fetchinclude" "a*"
634 git add ".lfsconfig"
635 git commit -m "config lfs.fetchinclude a*" 2>&1 | tee commit.log
636 grep "main" commit.log
637 grep "1 file changed" commit.log
638 grep "create mode 100644 .lfsconfig" commit.log
639
640 git push origin main 2>&1 | tee push.log
641 grep "main -> main" push.log
642 grep "Uploading LFS objects: 100% (2/2), 2 B" push.log
643
644 pushd "$TRASHDIR"
645
646 echo "test: clone with lfs.fetchinclude in .lfsconfig"
647 local_reponame="clone_with_config_include"
648 set +x
649 git lfs clone "$GITSERVER/$reponame" "$local_reponame"
650 ok="$?"
651 set -x
652 if [ "0" -ne "$ok" ]; then
653 # TEMP: used to catch transient failure from above `clone` command, as in:
654 # https://github.com/git-lfs/git-lfs/pull/1782#issuecomment-267678319
655 echo >&2 "[!] \`git lfs clone $GITSERVER/$reponame $local_reponame\` failed"
656 git lfs logs last
657
658 exit 1
659 fi
660 pushd "$local_reponame"
661 assert_local_object "$contents_a_oid" 1
662 refute_local_object "$contents_b_oid"
663 assert_hooks "$(dot_git_dir)"
664 [ ! -e "lfs" ]
665 assert_clean_status
666 popd
667
668 echo "test: clone with lfs.fetchinclude in .lfsconfig, and args"
669 local_reponame="clone_with_config_include_and_args"
670 git lfs clone "$GITSERVER/$reponame" "$local_reponame" -I "b.dat"
671 pushd "$local_reponame"
672 refute_local_object "$contents_a_oid"
673 assert_local_object "$contents_b_oid" 1
674 assert_hooks "$(dot_git_dir)"
675 [ ! -e "lfs" ]
676 assert_clean_status
677 popd
678
679 popd
680
681 git config -f ".lfsconfig" "lfs.fetchinclude" "b*"
682 git config -f ".lfsconfig" "lfs.fetchexclude" "a*"
683 git add .lfsconfig
684 git commit -m "config lfs.fetchinclude a*" 2>&1 | tee commit.log
685 grep "main" commit.log
686 grep "1 file changed" commit.log
687 git push origin main 2>&1 | tee push.log
688 grep "main -> main" push.log
689
690 pushd "$TRASHDIR"
691
692 echo "test: clone with lfs.fetchexclude in .lfsconfig"
693 local_reponame="clone_with_config_exclude"
694 git lfs clone "$GITSERVER/$reponame" "$local_reponame"
695 pushd "$local_reponame"
696 cat ".lfsconfig"
697 assert_local_object "$contents_b_oid" 1
698 refute_local_object "$contents_a_oid"
699 assert_hooks "$(dot_git_dir)"
700 [ ! -e "lfs" ]
701 assert_clean_status
702 popd
703
704 echo "test: clone with lfs.fetchexclude in .lfsconfig, and args"
705 local_reponame="clone_with_config_exclude_and_args"
706 git lfs clone "$GITSERVER/$reponame" "$local_reponame" -I "a.dat" -X "b.dat"
707 pushd "$local_reponame"
708 assert_local_object "$contents_a_oid" 1
709 refute_local_object "$contents_b_oid"
710 assert_hooks "$(dot_git_dir)"
711 [ ! -e "lfs" ]
712 assert_clean_status
713 popd
714
715 popd
716 )
717 end_test
718
719 begin_test "clone (without clean filter)"
720 (
721 set -e
722
723 reponame="clone_with_clean"
724 setup_remote_repo "$reponame"
725 clone_repo "$reponame" "$reponame"
726
727 git lfs track "*.dat" 2>&1 | tee track.log
728 grep "Tracking \"\*.dat\"" track.log
729
730 contents_a="a"
731 contents_a_oid=$(calc_oid "$contents_a")
732 printf "%s" "$contents_a" > "a.dat"
733
734 git add *.dat .gitattributes
735 git commit -m "add a.dat, b.dat" 2>&1 | tee commit.log
736 grep "main (root-commit)" commit.log
737
738 git push origin main 2>&1 | tee push.log
739 grep "main -> main" push.log
740 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
741
742 cd "$TRASHDIR"
743
744 git lfs uninstall
745 git config --list > config.txt
746 grep "filter.lfs.clean" config.txt && {
747 echo "clean filter still configured:"
748 cat config.txt
749 exit 1
750 }
751
752 local_reponame="clone_without_clean"
753 git lfs clone "$GITSERVER/$reponame" "$local_reponame" -I "a*.dat" | tee clone.txt
754 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
755 echo >&2 "fatal: expected clone to succeed ..."
756 exit 1
757 fi
758 grep "Git LFS is not installed" clone.txt
759
760 cd "$local_reponame"
761 assert_local_object "$contents_a_oid" 1
762 [ "$(pointer $contents_a_oid 1)" = "$(cat a.dat)" ]
763 )
764 end_test
765
766 begin_test "clone with submodules"
767 (
768 set -e
769
770 # set up a doubly nested submodule, each with LFS content
771 reponame="submod-root"
772 submodname1="submod-level1"
773 submodname2="submod-level2"
774
775 setup_remote_repo "$reponame"
776 setup_remote_repo "$submodname1"
777 setup_remote_repo "$submodname2"
778
779 clone_repo "$submodname2" submod2
780 git lfs track "*.dat" 2>&1 | tee track.log
781 grep "Tracking \"\*.dat\"" track.log
782
783 contents_sub2="Inception. Now, before you bother telling me it's impossible..."
784 contents_sub2_oid=$(calc_oid "$contents_sub2")
785 printf "%s" "$contents_sub2" > "sub2.dat"
786 git add sub2.dat .gitattributes
787 git commit -m "Nested submodule level 2"
788 git push origin main
789
790 clone_repo "$submodname1" submod1
791 git lfs track "*.dat" 2>&1 | tee track.log
792 grep "Tracking \"\*.dat\"" track.log
793
794 contents_sub1="We're dreaming?"
795 contents_sub1_oid=$(calc_oid "$contents_sub1")
796 printf "%s" "$contents_sub1" > "sub1.dat"
797 # add submodule2 as submodule of submodule1
798 git submodule add "$GITSERVER/$submodname2" sub2
799 git submodule update
800 git add sub2 sub1.dat .gitattributes
801 git commit -m "Nested submodule level 1"
802 git push origin main
803
804 clone_repo "$reponame" rootrepo
805 git lfs track "*.dat" 2>&1 | tee track.log
806 grep "Tracking \"\*.dat\"" track.log
807
808 contents_root="Downwards is the only way forwards."
809 contents_root_oid=$(calc_oid "$contents_root")
810 printf "%s" "$contents_root" > "root.dat"
811 # add submodule1 as submodule of root
812 git submodule add "$GITSERVER/$submodname1" sub1
813 git submodule update
814 git add sub1 root.dat .gitattributes
815 git commit -m "Root repo"
816 git push origin main
817
818 pushd "$TRASHDIR"
819
820 local_reponame="submod-clone"
821 git lfs clone --recursive "$GITSERVER/$reponame" "$local_reponame"
822
823 # check everything is where it should be
824 cd $local_reponame
825 assert_hooks "$(dot_git_dir)"
826 [ ! -e "lfs" ]
827 assert_clean_status
828 # check LFS store and working copy
829 assert_local_object "$contents_root_oid" "${#contents_root}"
830 [ $(wc -c < "root.dat") -eq ${#contents_root} ]
831 # and so on for nested subs
832 cd sub1
833 assert_local_object "$contents_sub1_oid" "${#contents_sub1}"
834 [ $(wc -c < "sub1.dat") -eq ${#contents_sub1} ]
835 cd sub2
836 assert_local_object "$contents_sub2_oid" "${#contents_sub2}"
837 [ $(wc -c < "sub2.dat") -eq ${#contents_sub2} ]
838
839 popd
840 )
841 end_test
842
843 begin_test "clone in current directory"
844 (
845 set -e
846
847 reponame="clone_in_current_dir"
848 setup_remote_repo "$reponame"
849 clone_repo "$reponame" $reponame
850
851 git lfs track "*.dat" 2>&1 | tee track.log
852 grep "Tracking \"\*.dat\"" track.log
853
854 contents="contents"
855 contents_oid="$(calc_oid "$contents")"
856
857 printf "%s" "$contents" > a.dat
858
859 git add .gitattributes a.dat
860
861 git commit -m "initial commit" 2>&1 | tee commit.log
862 grep "main (root-commit)" commit.log
863 grep "2 files changed" commit.log
864 grep "create mode 100644 a.dat" commit.log
865 grep "create mode 100644 .gitattributes" commit.log
866
867 git push origin main 2>&1 | tee push.log
868
869 pushd $TRASHDIR
870 mkdir "$reponame-clone"
871 cd "$reponame-clone"
872
873 git lfs clone $GITSERVER/$reponame "."
874 git lfs fsck
875
876 assert_local_object "$contents_oid" 8
877 assert_hooks "$(dot_git_dir)"
878 [ ! -e "lfs" ]
879 assert_clean_status
880 popd
881 )
882 end_test
883
884 begin_test "clone empty repository"
885 (
886 set -e
887
888 reponame="clone_empty"
889 setup_remote_repo "$reponame"
890
891 cd "$TRASHDIR"
892 git lfs clone "$GITSERVER/$reponame" "$reponame" 2>&1 | tee clone.log
893 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
894 echo >&2 "fatal: expected clone to succeed ..."
895 exit 1
896 fi
897 )
898 end_test
899
900 begin_test "clone bare empty repository"
901 (
902 set -e
903
904 reponame="clone_bare_empty"
905 setup_remote_repo "$reponame"
906
907 cd "$TRASHDIR"
908 git lfs clone "$GITSERVER/$reponame" "$reponame" --bare 2>&1 | tee clone.log
909 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
910 echo >&2 "fatal: expected clone to succeed ..."
911 exit 1
912 fi
913 )
914 end_test
915
916 begin_test "clone (HTTP server/proxy require cookies)"
917 (
918 set -e
919
920 # golang net.http.Cookie ignores cookies with IP instead of domain/hostname
921 GITSERVER=$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')
922 cp "$CREDSDIR/127.0.0.1" "$CREDSDIR/localhost"
923 printf "localhost\tTRUE\t/\tFALSE\t2145916800\tCOOKIE_GITLFS\tsecret\n" >> "$REMOTEDIR/cookies.txt"
924 git config --global http.cookieFile "$REMOTEDIR/cookies.txt"
925
926 reponame="require-cookie-test"
927 setup_remote_repo "$reponame"
928 clone_repo "$reponame" "$reponame"
929
930 git lfs track "*.dat" 2>&1 | tee track.log
931 grep "Tracking \"\*.dat\"" track.log
932 git add .gitattributes
933 git commit -m "Track *.dat"
934
935 # generate some test data & commits with random LFS data
936 echo "[
937 {
938 \"CommitDate\":\"$(get_date -10d)\",
939 \"Files\":[
940 {\"Filename\":\"file1.dat\",\"Size\":100},
941 {\"Filename\":\"file2.dat\",\"Size\":75}]
942 },
943 {
944 \"CommitDate\":\"$(get_date -7d)\",
945 \"Files\":[
946 {\"Filename\":\"file1.dat\",\"Size\":110},
947 {\"Filename\":\"file3.dat\",\"Size\":66},
948 {\"Filename\":\"file4.dat\",\"Size\":23}]
949 },
950 {
951 \"CommitDate\":\"$(get_date -10d)\",
952 \"Files\":[
953 {\"Filename\":\"file5.dat\",\"Size\":120},
954 {\"Filename\":\"file6.dat\",\"Size\":30}]
955 }
956 ]" | lfstest-testutils addcommits
957
958 git push origin main
959
960 # Now clone again, test specific clone dir
961 cd "$TRASHDIR"
962
963 newclonedir="require-cookie-test1"
964 git lfs clone "$GITSERVER/$reponame" "$newclonedir" 2>&1 | tee lfsclone.log
965 grep "Cloning into" lfsclone.log
966 grep "Downloading LFS objects:" lfsclone.log
967 # should be no filter errors
968 grep "filter" lfsclone.log && exit 1
969 grep "error" lfsclone.log && exit 1
970 # should be cloned into location as per arg
971 [ -d "$newclonedir" ]
972
973 # check a few file sizes to make sure pulled
974 pushd "$newclonedir"
975 [ $(wc -c < "file1.dat") -eq 110 ]
976 [ $(wc -c < "file2.dat") -eq 75 ]
977 [ $(wc -c < "file3.dat") -eq 66 ]
978 assert_hooks "$(dot_git_dir)"
979 [ ! -e "lfs" ]
980 assert_clean_status
981 popd
982
983 # Now check clone with implied dir
984 rm -rf "$reponame"
985 git lfs clone "$GITSERVER/$reponame" 2>&1 | tee lfsclone.log
986 grep "Cloning into" lfsclone.log
987 grep "Downloading LFS objects:" lfsclone.log
988 # should be no filter errors
989 grep "filter" lfsclone.log && exit 1
990 grep "error" lfsclone.log && exit 1
991 # clone location should be implied
992 [ -d "$reponame" ]
993
994 pushd "$reponame"
995 [ $(wc -c < "file1.dat") -eq 110 ]
996 [ $(wc -c < "file2.dat") -eq 75 ]
997 [ $(wc -c < "file3.dat") -eq 66 ]
998 assert_hooks "$(dot_git_dir)"
999 [ ! -e "lfs" ]
1000 assert_clean_status
1001 popd
1002 )
1003 end_test