3 . "$(dirname "$0")/testlib.sh"
5 begin_test "pre-push with good ref"
8 reponame="pre-push-master-branch-required"
9 setup_remote_repo "$reponame"
10 clone_repo "$reponame" "$reponame"
12 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
15 git add .gitattributes a.dat
16 git commit -m "add a.dat"
18 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/master"
20 # for some reason, using 'tee' and $PIPESTATUS does not work here
21 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
22 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 > push.log
24 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/master"
28 begin_test "pre-push with tracked ref"
31 reponame="pre-push-tracked-branch-required"
32 setup_remote_repo "$reponame"
33 clone_repo "$reponame" "$reponame"
35 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
38 git add .gitattributes a.dat
39 git commit -m "add a.dat"
41 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
43 # for some reason, using 'tee' and $PIPESTATUS does not work here
44 echo "refs/heads/master master refs/heads/tracked 0000000000000000000000000000000000000000" |
45 git lfs pre-push origin master 2>&1 > push.log
47 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
51 begin_test "pre-push with bad ref"
54 reponame="pre-push-other-branch-required"
55 setup_remote_repo "$reponame"
56 clone_repo "$reponame" "$reponame"
58 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
61 git add .gitattributes a.dat
62 git commit -m "add a.dat"
64 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
66 # for some reason, using 'tee' and $PIPESTATUS does not work here
68 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
69 git lfs pre-push origin "$GITSERVER/$reponame" 2> push.log
73 if [ "0" -eq "$pushcode" ]; then
74 echo "expected command to fail"
78 grep 'Expected ref "refs/heads/other", got "refs/heads/master"' push.log
80 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
88 reponame="$(basename "$0" ".sh")"
89 setup_remote_repo "$reponame"
91 clone_repo "$reponame" repo
93 git add .gitattributes
94 git commit -m "add git attributes"
96 git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
98 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
99 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
101 # no output if nothing to do
102 [ "$(du -k push.log | cut -f 1)" == "0" ]
104 git lfs track "*.dat"
107 git commit -m "add hi.dat"
110 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
112 # push file to the git lfs server
113 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
114 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
116 grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
118 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
122 begin_test "pre-push dry-run"
126 reponame="$(basename "$0" ".sh")-dry-run"
127 setup_remote_repo "$reponame"
129 clone_repo "$reponame" repo-dry-run
130 git lfs track "*.dat"
131 git add .gitattributes
132 git commit -m "add git attributes"
134 git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
136 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
137 git lfs pre-push --dry-run origin "$GITSERVER/$reponame" 2>&1 |
140 [ "" = "$(cat push.log)" ]
142 git lfs track "*.dat"
145 git commit -m "add hi.dat"
148 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
150 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
151 git lfs pre-push --dry-run origin "$GITSERVER/$reponame" 2>&1 |
153 grep "push 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b => hi.dat" push.log
155 [ `wc -l < push.log` = 1 ]
157 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
161 begin_test "pre-push 307 redirects"
165 reponame="$(basename "$0" ".sh")"
166 setup_remote_repo "$reponame"
168 clone_repo "$reponame" repo-307
169 git lfs track "*.dat"
170 git add .gitattributes
171 git commit -m "add git attributes"
174 git config remote.origin.lfsurl "$GITSERVER/redirect307/rel/$reponame.git/info/lfs"
176 git lfs track "*.dat"
179 git commit -m "add hi.dat"
182 # push file to the git lfs server
183 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
184 git lfs pre-push origin "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" 2>&1 |
186 grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
188 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
191 git config remote.origin.lfsurl "$GITSERVER/redirect307/abs/$reponame.git/info/lfs"
195 git commit -m "add hi2.dat"
198 # push file to the git lfs server
199 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
200 git lfs pre-push origin "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" 2>&1 |
202 grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
206 begin_test "pre-push with existing file"
210 reponame="$(basename "$0" ".sh")-existing-file"
211 setup_remote_repo "$reponame"
213 clone_repo "$reponame" existing-file
214 echo "existing" > existing.dat
216 git commit -m "add existing dat"
218 git lfs track "*.dat"
221 git add .gitattributes
222 git commit -m "add new file through git lfs"
224 # push file to the git lfs server
225 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
226 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
228 grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
230 # now the file exists
231 assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
235 begin_test "pre-push with existing pointer"
239 reponame="$(basename "$0" ".sh")-existing-pointer"
240 setup_remote_repo "$reponame"
241 clone_repo "$reponame" existing-pointer
243 echo "$(pointer "7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" 4)" > new.dat
245 git commit -m "add new pointer"
246 mkdir -p .git/lfs/objects/7a/a7
247 echo "new" > .git/lfs/objects/7a/a7/7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
249 # push file to the git lfs server
250 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
251 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
253 grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
257 begin_test "pre-push with missing pointer not on server"
261 reponame="$(basename "$0" ".sh")-missing-pointer"
262 setup_remote_repo "$reponame"
263 clone_repo "$reponame" missing-pointer
265 oid="7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c"
267 echo "$(pointer "$oid" 4)" > new.dat
269 git commit -m "add new pointer"
271 # assert that push fails
273 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
274 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
278 grep " (missing) new.dat ($oid)" push.log
282 begin_test "pre-push with missing pointer which is on server"
284 # should permit push if files missing locally but are on server, shouldn't
285 # require client to have every file (prune)
288 reponame="$(basename "$0" ".sh")-missing-but-on-server"
289 setup_remote_repo "$reponame"
290 clone_repo "$reponame" missing-but-on-server
292 contents="common data"
293 contents_oid=$(calc_oid "$contents")
294 git lfs track "*.dat"
295 printf "$contents" > common1.dat
297 git add .gitattributes
298 git commit -m "add first file"
300 # push file to the git lfs server
301 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
302 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
304 grep "Uploading LFS objects: 100% (1/1), 11 B" push.log
306 # now the file exists
307 assert_server_object "$reponame" "$contents_oid"
309 # create another commit referencing same oid, then delete local data & push
310 printf "$contents" > common2.dat
312 git commit -m "add second file, same content"
313 rm -rf .git/lfs/objects
314 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
315 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
317 # make sure there were no errors reported
318 [ -z "$(grep -i 'Error' push.log)" ]
323 begin_test "pre-push with missing and present pointers (lfs.allowincompletepush true)"
327 reponame="pre-push-missing-and-present"
328 setup_remote_repo "$reponame"
329 clone_repo "$reponame" "$reponame"
331 git lfs track "*.dat"
332 git add .gitattributes
333 git commit -m "initial commit"
336 present_oid="$(calc_oid "$present")"
337 printf "$present" > present.dat
340 missing_oid="$(calc_oid "$missing")"
341 printf "$missing" > missing.dat
343 git add present.dat missing.dat
344 git commit -m "add present.dat and missing.dat"
347 git commit -m "remove missing"
349 # :fire: the "missing" object
350 missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
351 missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
352 missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
353 rm "$missing_oid_path"
355 git config lfs.allowincompletepush true
357 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
358 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
361 if [ "0" -ne "${PIPESTATUS[1]}" ]; then
362 echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to succeed..."
366 grep "LFS upload missing objects" push.log
367 grep " (missing) missing.dat ($missing_oid)" push.log
369 assert_server_object "$reponame" "$present_oid"
370 refute_server_object "$reponame" "$missing_oid"
374 begin_test "pre-push reject missing pointers (lfs.allowincompletepush default)"
378 reponame="pre-push-reject-missing-and-present"
379 setup_remote_repo "$reponame"
380 clone_repo "$reponame" "$reponame"
382 git lfs track "*.dat"
383 git add .gitattributes
384 git commit -m "initial commit"
387 present_oid="$(calc_oid "$present")"
388 printf "$present" > present.dat
391 missing_oid="$(calc_oid "$missing")"
392 printf "$missing" > missing.dat
394 git add present.dat missing.dat
395 git commit -m "add present.dat and missing.dat"
398 git commit -m "remove missing"
400 # :fire: the "missing" object
401 missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
402 missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
403 missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
404 rm "$missing_oid_path"
406 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
407 git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
410 if [ "2" -ne "${PIPESTATUS[1]}" ]; then
411 echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to fail..."
415 grep "no such file or directory" push.log || # unix
416 grep "cannot find the file" push.log # windows
418 refute_server_object "$reponame" "$present_oid"
419 refute_server_object "$reponame" "$missing_oid"
423 begin_test "pre-push multiple branches"
427 reponame="$(basename "$0" ".sh")-multiple-branches"
428 setup_remote_repo "$reponame"
429 clone_repo "$reponame" "$reponame"
432 git lfs track "*.dat" 2>&1 | tee track.log
433 grep "Tracking \"\*.dat\"" track.log
436 # generate content we'll use
437 for ((a=0; a < NUMFILES ; a++))
439 content[$a]="filecontent$a"
440 oid[$a]=$(calc_oid "${content[$a]}")
445 \"CommitDate\":\"$(get_date -10d)\",
447 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
448 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
451 \"NewBranch\":\"branch1\",
452 \"CommitDate\":\"$(get_date -5d)\",
454 {\"Filename\":\"file2.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
457 \"ParentBranches\":[\"master\"],
458 \"NewBranch\":\"branch2\",
459 \"CommitDate\":\"$(get_date -5d)\",
461 {\"Filename\":\"file3.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
464 \"ParentBranches\":[\"master\"],
465 \"NewBranch\":\"branch3\",
466 \"CommitDate\":\"$(get_date -2d)\",
468 {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
471 \"ParentBranches\":[\"master\"],
472 \"NewBranch\":\"branch4\",
473 \"CommitDate\":\"$(get_date -1d)\",
475 {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
477 ]" | lfstest-testutils addcommits
479 # make sure when called via git push all branches are updated
480 git push origin master branch1 branch2 branch3 branch4
481 for ((a=0; a < NUMFILES ; a++))
483 assert_server_object "$reponame" "${oid[$a]}"
489 begin_test "pre-push with bad remote"
495 echo "refs/heads/master master refs/heads/master 0000000000000000000000000000000000000000" |
496 git lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 |
498 grep "Invalid remote name" pre-push.log
502 begin_test "pre-push unfetched deleted remote branch & server GC"
504 # point of this is to simulate the case where the local cache of the remote
505 # branch state contains a branch which has actually been deleted on the remote,
506 # the client just doesn't know yet (hasn't done 'git fetch origin --prune')
507 # If the server GC'd the objects that deleted branch contained, but they were
508 # referenced by a branch being pushed (earlier commit), push might assume it
509 # doesn't have to push it, but it does. Tests that we check the real remote refs
510 # before making an assumption about the diff we need to push
513 reponame="$(basename "$0" ".sh")-server-deleted-branch-gc"
514 setup_remote_repo "$reponame"
515 clone_repo "$reponame" "$reponame"
518 git lfs track "*.dat" 2>&1 | tee track.log
519 grep "Tracking \"\*.dat\"" track.log
522 # generate content we'll use
523 for ((a=0; a < NUMFILES ; a++))
525 content[$a]="filecontent$a"
526 oid[$a]=$(calc_oid "${content[$a]}")
531 \"CommitDate\":\"$(get_date -10d)\",
533 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
534 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
537 \"NewBranch\":\"branch-to-delete\",
538 \"CommitDate\":\"$(get_date -5d)\",
540 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
543 \"NewBranch\":\"branch-to-push-after\",
544 \"CommitDate\":\"$(get_date -2d)\",
546 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
548 ]" | lfstest-testutils addcommits
550 # push only the first 2 branches
551 git push origin master branch-to-delete
552 for ((a=0; a < 3 ; a++))
554 assert_server_object "$reponame" "${oid[$a]}"
556 # confirm we haven't pushed the last one yet
557 refute_server_object "$reponame" "${oid[3]}"
558 # copy the cached remote ref for the branch we're going to delete remotely
559 cp .git/refs/remotes/origin/branch-to-delete branch-to-delete.ref
560 # now delete the branch on the server
561 git push origin --delete branch-to-delete
562 # remove the OID in it, as if GC'd
563 delete_server_object "$reponame" "${oid[2]}"
564 refute_server_object "$reponame" "${oid[2]}"
565 # Now put the cached remote ref back, as if someone else had deleted it but
566 # we hadn't done git fetch --prune yet
567 mv branch-to-delete.ref .git/refs/remotes/origin/branch-to-delete
568 # Confirm that local cache of remote branch is back
569 git branch -r 2>&1 | tee branch-r.log
570 grep "origin/branch-to-delete" branch-r.log
571 # Now push later branch which should now need to re-push previous commits LFS too
572 git push origin branch-to-push-after
573 # all objects should now be there even though cached remote branch claimed it already had file3.dat
574 for ((a=0; a < NUMFILES ; a++))
576 assert_server_object "$reponame" "${oid[$a]}"
582 begin_test "pre-push delete branch"
586 reponame="$(basename "$0" ".sh")-delete-branch"
587 setup_remote_repo "$reponame"
588 clone_repo "$reponame" "$reponame"
591 git lfs track "*.dat" 2>&1 | tee track.log
592 grep "Tracking \"\*.dat\"" track.log
595 # generate content we'll use
596 for ((a=0; a < NUMFILES ; a++))
598 content[$a]="filecontent$a"
599 oid[$a]=$(calc_oid "${content[$a]}")
604 \"CommitDate\":\"$(get_date -2d)\",
606 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
607 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
610 \"NewBranch\":\"branch-to-delete\",
611 \"CommitDate\":\"$(get_date -1d)\",
613 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
616 \"ParentBranches\":[\"master\"],
617 \"CommitDate\":\"$(get_date -0d)\",
619 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
621 ]" | lfstest-testutils addcommits
624 git push origin master branch-to-delete
625 for ((a=0; a < NUMFILES ; a++))
627 assert_server_object "$reponame" "${oid[$a]}"
630 # deleting a branch with git push should not fail
631 # (requires correct special casing of "(delete) 0000000000.." in hook)
632 git push origin --delete branch-to-delete
636 begin_test "pre-push with our lock"
640 reponame="pre_push_owned_locks"
641 setup_remote_repo "$reponame"
642 clone_repo "$reponame" "$reponame"
644 git lfs track "*.dat"
645 git add .gitattributes
646 git commit -m "initial commit"
648 contents="locked contents"
649 printf "$contents" > locked.dat
651 git commit -m "add locked.dat"
653 git push origin master
655 git lfs lock --json "locked.dat" | tee lock.log
657 id=$(assert_lock lock.log locked.dat)
658 assert_server_lock $id
660 printf "authorized changes" >> locked.dat
662 git commit -m "add unauthorized changes"
664 GIT_CURL_VERBOSE=1 git push origin master 2>&1 | tee push.log
665 grep "Consider unlocking your own locked files" push.log
666 grep "* locked.dat" push.log
668 assert_server_lock "$id"
672 begin_test "pre-push with their lock on lfs file"
676 reponame="pre_push_unowned_lock"
677 setup_remote_repo "$reponame"
678 clone_repo "$reponame" "$reponame"
680 git lfs track "*.dat"
681 git add .gitattributes
682 git commit -m "initial commit"
684 contents="locked contents"
686 # any lock path with "theirs" is returned as "their" lock by /locks/verify
687 printf "$contents" > locked_theirs.dat
688 git add locked_theirs.dat
689 git commit -m "add locked_theirs.dat"
691 git push origin master
693 git lfs lock --json "locked_theirs.dat" | tee lock.log
694 id=$(assert_lock lock.log locked_theirs.dat)
695 assert_server_lock $id
697 pushd "$TRASHDIR" >/dev/null
698 clone_repo "$reponame" "$reponame-assert"
699 git config lfs.locksverify true
701 printf "unauthorized changes" >> locked_theirs.dat
702 git add locked_theirs.dat
703 # --no-verify is used to avoid the pre-commit hook which is not under test
704 git commit --no-verify -m "add unauthorized changes"
706 git push origin master 2>&1 | tee push.log
707 res="${PIPESTATUS[0]}"
708 if [ "0" -eq "$res" ]; then
709 echo "push should fail"
713 grep "Unable to push locked files" push.log
714 grep "* locked_theirs.dat - Git LFS Tests" push.log
716 grep "ERROR: Cannot update locked files." push.log
717 refute_server_object "$reponame" "$(calc_oid_file locked_theirs.dat)"
722 begin_test "pre-push with their lock on non-lfs lockable file"
726 reponame="pre_push_unowned_lock_not_lfs"
727 setup_remote_repo "$reponame"
728 clone_repo "$reponame" "$reponame"
730 echo "*.dat lockable" > .gitattributes
731 git add .gitattributes
732 git commit -m "initial commit"
734 # any lock path with "theirs" is returned as "their" lock by /locks/verify
735 echo "hi" > readme.txt
736 echo "tiny" > tiny_locked_theirs.dat
737 git help > large_locked_theirs.dat
738 git add readme.txt tiny_locked_theirs.dat large_locked_theirs.dat
739 git commit -m "add initial files"
741 git push origin master
743 git lfs lock --json "tiny_locked_theirs.dat" | tee lock.log
744 id=$(assert_lock lock.log tiny_locked_theirs.dat)
745 assert_server_lock $id
747 git lfs lock --json "large_locked_theirs.dat" | tee lock.log
748 id=$(assert_lock lock.log large_locked_theirs.dat)
749 assert_server_lock $id
751 pushd "$TRASHDIR" >/dev/null
752 clone_repo "$reponame" "$reponame-assert"
753 git config lfs.locksverify true
755 git lfs update # manually add pre-push hook, since lfs clean hook is not used
756 echo "other changes" >> readme.txt
757 echo "unauthorized changes" >> large_locked_theirs.dat
758 echo "unauthorized changes" >> tiny_locked_theirs.dat
759 # --no-verify is used to avoid the pre-commit hook which is not under test
760 git commit --no-verify -am "add unauthorized changes"
762 git push origin master 2>&1 | tee push.log
763 res="${PIPESTATUS[0]}"
764 if [ "0" -eq "$res" ]; then
765 echo "push should fail"
769 grep "Unable to push locked files" push.log
770 grep "* large_locked_theirs.dat - Git LFS Tests" push.log
771 grep "* tiny_locked_theirs.dat - Git LFS Tests" push.log
772 grep "ERROR: Cannot update locked files." push.log
774 refute_server_object "$reponame" "$(calc_oid_file large_locked_theirs.dat)"
775 refute_server_object "$reponame" "$(calc_oid_file tiny_locked_theirs.dat)"
780 begin_test "pre-push locks verify 5xx with verification enabled"
784 reponame="lock-enabled-verify-5xx"
785 setup_remote_repo "$reponame"
786 clone_repo "$reponame" "$reponame"
788 endpoint="$(repo_endpoint $GITSERVER $reponame)"
791 contents_oid="$(calc_oid "$contents")"
792 printf "$contents" > a.dat
793 git lfs track "*.dat"
794 git add .gitattributes a.dat
795 git commit --message "initial commit"
797 git config "lfs.$endpoint.locksverify" true
799 git push origin master 2>&1 | tee push.log
800 grep "\"origin\" does not support the LFS locking API" push.log
801 grep "git config lfs.$endpoint.locksverify false" push.log
803 refute_server_object "$reponame" "$contents_oid"
807 begin_test "pre-push disable locks verify on exact url"
811 reponame="lock-disabled-verify-5xx"
812 setup_remote_repo "$reponame"
813 clone_repo "$reponame" "$reponame"
815 endpoint="$(repo_endpoint $GITSERVER $reponame)"
818 contents_oid="$(calc_oid "$contents")"
819 printf "$contents" > a.dat
820 git lfs track "*.dat"
821 git add .gitattributes a.dat
822 git commit --message "initial commit"
824 git config "lfs.$endpoint.locksverify" false
826 git push origin master 2>&1 | tee push.log
827 [ "0" -eq "$(grep -c "\"origin\" does not support the LFS locking API" push.log)" ]
829 assert_server_object "$reponame" "$contents_oid"
833 begin_test "pre-push disable locks verify on partial url"
837 reponame="lock-disabled-verify-5xx-partial"
838 setup_remote_repo "$reponame"
839 clone_repo "$reponame" "$reponame"
841 endpoint="$server/$repo"
844 contents_oid="$(calc_oid "$contents")"
845 printf "$contents" > a.dat
846 git lfs track "*.dat"
847 git add .gitattributes a.dat
848 git commit --message "initial commit"
850 git config "lfs.$endpoint.locksverify" false
852 git push origin master 2>&1 | tee push.log
853 [ "0" -eq "$(grep -c "\"origin\" does not support the LFS locking API" push.log)" ]
855 assert_server_object "$reponame" "$contents_oid"
859 begin_test "pre-push locks verify 403 with good ref"
863 reponame="lock-verify-master-branch-required"
864 setup_remote_repo "$reponame"
865 clone_repo "$reponame" "$reponame"
868 contents_oid="$(calc_oid "$contents")"
869 printf "$contents" > a.dat
870 git lfs track "*.dat"
871 git add .gitattributes a.dat
872 git commit --message "initial commit"
874 git config "lfs.$GITSERVER/$reponame.git.locksverify" true
875 git push origin master 2>&1 | tee push.log
877 assert_server_object "$reponame" "$contents_oid" "refs/heads/master"
881 begin_test "pre-push locks verify 403 with good tracked ref"
885 reponame="lock-verify-tracked-branch-required"
886 setup_remote_repo "$reponame"
887 clone_repo "$reponame" "$reponame"
890 contents_oid="$(calc_oid "$contents")"
891 printf "$contents" > a.dat
892 git lfs track "*.dat"
893 git add .gitattributes a.dat
894 git commit --message "initial commit"
896 git config push.default upstream
897 git config branch.master.merge refs/heads/tracked
898 git config "lfs.$GITSERVER/$reponame.git.locksverify" true
899 git push 2>&1 | tee push.log
901 assert_server_object "$reponame" "$contents_oid" "refs/heads/tracked"
905 begin_test "pre-push locks verify 403 with explicit ref"
909 reponame="lock-verify-explicit-branch-required"
910 setup_remote_repo "$reponame"
911 clone_repo "$reponame" "$reponame"
914 contents_oid="$(calc_oid "$contents")"
915 printf "$contents" > a.dat
916 git lfs track "*.dat"
917 git add .gitattributes a.dat
918 git commit --message "initial commit"
920 git config "lfs.$GITSERVER/$reponame.git.locksverify" true
921 git push origin master:explicit 2>&1 | tee push.log
923 assert_server_object "$reponame" "$contents_oid" "refs/heads/explicit"
927 begin_test "pre-push locks verify 403 with bad ref"
931 reponame="lock-verify-other-branch-required"
932 setup_remote_repo "$reponame"
933 clone_repo "$reponame" "$reponame"
936 contents_oid="$(calc_oid "$contents")"
937 printf "$contents" > a.dat
938 git lfs track "*.dat"
939 git add .gitattributes a.dat
940 git commit --message "initial commit"
942 git config "lfs.$GITSERVER/$reponame.git.locksverify" true
943 git push origin master 2>&1 | tee push.log
944 grep "failed to push some refs" push.log
945 refute_server_object "$reponame" "$contents_oid" "refs/heads/other"
949 begin_test "pre-push locks verify 5xx with verification unset"
953 reponame="lock-unset-verify-5xx"
954 setup_remote_repo "$reponame"
955 clone_repo "$reponame" "$reponame"
957 endpoint="$(repo_endpoint $GITSERVER $reponame)"
960 contents_oid="$(calc_oid "$contents")"
961 printf "$contents" > a.dat
962 git lfs track "*.dat"
963 git add .gitattributes a.dat
964 git commit --message "initial commit"
966 [ -z "$(git config "lfs.$endpoint.locksverify")" ]
968 git push origin master 2>&1 | tee push.log
969 grep "\"origin\" does not support the LFS locking API" push.log
971 assert_server_object "$reponame" "$contents_oid"
975 begin_test "pre-push locks verify 501 with verification enabled"
979 reponame="lock-enabled-verify-501"
980 setup_remote_repo "$reponame"
981 clone_repo "$reponame" "$reponame"
983 endpoint="$(repo_endpoint $GITSERVER $reponame)"
986 contents_oid="$(calc_oid "$contents")"
987 printf "$contents" > a.dat
988 git lfs track "*.dat"
989 git add .gitattributes a.dat
990 git commit --message "initial commit"
992 git config "lfs.$endpoint.locksverify" true
994 git push origin master 2>&1 | tee push.log
996 assert_server_object "$reponame" "$contents_oid"
997 [ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
1002 begin_test "pre-push locks verify 501 with verification disabled"
1006 reponame="lock-disabled-verify-501"
1007 setup_remote_repo "$reponame"
1008 clone_repo "$reponame" "$reponame"
1010 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1013 contents_oid="$(calc_oid "$contents")"
1014 printf "$contents" > a.dat
1015 git lfs track "*.dat"
1016 git add .gitattributes a.dat
1017 git commit --message "initial commit"
1019 git config "lfs.$endpoint.locksverify" false
1021 git push origin master 2>&1 | tee push.log
1023 assert_server_object "$reponame" "$contents_oid"
1024 [ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
1028 begin_test "pre-push locks verify 501 with verification unset"
1032 reponame="lock-unset-verify-501"
1033 setup_remote_repo "$reponame"
1034 clone_repo "$reponame" "$reponame"
1036 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1039 contents_oid="$(calc_oid "$contents")"
1040 printf "$contents" > a.dat
1041 git lfs track "*.dat"
1042 git add .gitattributes a.dat
1043 git commit --message "initial commit"
1045 [ -z "$(git config "lfs.$endpoint.locksverify")" ]
1047 git push origin master 2>&1 | tee push.log
1049 assert_server_object "$reponame" "$contents_oid"
1050 [ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
1054 begin_test "pre-push locks verify 200"
1058 reponame="lock-verify-200"
1059 setup_remote_repo "$reponame"
1060 clone_repo "$reponame" "$reponame"
1062 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1063 [ -z "$(git config "lfs.$endpoint.locksverify")" ]
1066 contents_oid="$(calc_oid "$contents")"
1067 printf "$contents" > a.dat
1068 git lfs track "*.dat"
1069 git add .gitattributes a.dat
1070 git commit --message "initial commit"
1072 git push origin master 2>&1 | tee push.log
1074 grep "Locking support detected on remote \"origin\"." push.log
1075 grep "git config lfs.$endpoint.locksverify true" push.log
1076 assert_server_object "$reponame" "$contents_oid"
1080 begin_test "pre-push locks verify 403 with verification enabled"
1084 reponame="lock-enabled-verify-403"
1085 setup_remote_repo "$reponame"
1086 clone_repo "$reponame" "$reponame"
1088 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1091 contents_oid="$(calc_oid "$contents")"
1092 printf "$contents" > a.dat
1093 git lfs track "*.dat"
1094 git add .gitattributes a.dat
1095 git commit --message "initial commit"
1097 git config "lfs.$endpoint.locksverify" true
1099 git push origin master 2>&1 | tee push.log
1100 grep "ERROR: Authentication error" push.log
1102 refute_server_object "$reponame" "$contents_oid"
1103 [ "true" = "$(git config "lfs.$endpoint.locksverify")" ]
1107 begin_test "pre-push locks verify 403 with verification disabled"
1111 reponame="lock-disabled-verify-403"
1112 setup_remote_repo "$reponame"
1113 clone_repo "$reponame" "$reponame"
1115 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1118 contents_oid="$(calc_oid "$contents")"
1119 printf "$contents" > a.dat
1120 git lfs track "*.dat"
1121 git add .gitattributes a.dat
1122 git commit --message "initial commit"
1124 git config "lfs.$endpoint.locksverify" false
1126 git push origin master 2>&1 | tee push.log
1128 assert_server_object "$reponame" "$contents_oid"
1129 [ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
1133 begin_test "pre-push locks verify 403 with verification unset"
1137 reponame="lock-unset-verify-403"
1138 setup_remote_repo "$reponame"
1139 clone_repo "$reponame" "$reponame"
1141 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1144 contents_oid="$(calc_oid "$contents")"
1145 printf "$contents" > a.dat
1146 git lfs track "*.dat"
1147 git add .gitattributes a.dat
1148 git commit --message "initial commit"
1150 [ -z "$(git config "lfs.$endpoint.locksverify")" ]
1152 git push origin master 2>&1 | tee push.log
1153 grep "WARNING: Authentication error" push.log
1155 assert_server_object "$reponame" "$contents_oid"
1156 [ -z "$(git config "lfs.$endpoint.locksverify")" ]