3 . "$(dirname "$0")/testlib.sh"
5 # sets up the repos for the first few push tests. The passed argument is the
6 # name of the repo to setup. The resuling repo will have a local file tracked
7 # with LFS and committed, but not yet pushed to the remote
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
13 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
16 git add .gitattributes a.dat
17 git commit -m "add a.dat"
20 begin_test "push with good ref"
23 push_repo_setup "push-master-branch-required"
25 git lfs push origin master
29 begin_test "push with tracked ref"
33 push_repo_setup "push-tracked-branch-required"
35 git config push.default upstream
36 git config branch.master.merge refs/heads/tracked
37 git lfs push origin master
41 begin_test "push with bad ref"
44 push_repo_setup "push-other-branch-required"
46 git lfs push origin master 2>&1 | tee push.log
47 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
48 echo "expected command to fail"
52 grep 'batch response: Expected ref "refs/heads/other", got "refs/heads/master"' push.log
56 begin_test "push with given remote, configured pushRemote"
59 push_repo_setup "push-given-and-config"
61 git remote add bad-remote "invalid-url"
63 git config branch.master.pushRemote bad-remote
65 git lfs push --all origin
73 reponame="$(basename "$0" ".sh")"
74 setup_remote_repo "$reponame"
75 clone_repo "$reponame" repo
77 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
81 git add .gitattributes a.dat
82 git commit -m "add a.dat"
84 git lfs push --dry-run origin master 2>&1 | tee push.log
85 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
86 [ $(grep -c "push" push.log) -eq 1 ]
88 git lfs push origin master 2>&1 | tee push.log
89 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
91 git checkout -b push-b
94 git commit -m "add b.dat"
96 git lfs push --dry-run origin push-b 2>&1 | tee push.log
97 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
98 grep "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
99 [ $(grep -c "push" < push.log) -eq 2 ]
101 # simulate remote ref
102 mkdir -p .git/refs/remotes/origin
103 git rev-parse HEAD > .git/refs/remotes/origin/HEAD
105 git lfs push --dry-run origin push-b 2>&1 | tee push.log
106 [ $(grep -c "push" push.log) -eq 0 ]
108 rm -rf .git/refs/remotes
110 git lfs push origin push-b 2>&1 | tee push.log
111 grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
115 # sets up the tests for the next few push --all tests
118 reponame="$(basename "$0" ".sh")-all"
125 oid1=$(calc_oid "$content1")
126 oid2=$(calc_oid "$content2")
127 oid3=$(calc_oid "$content3")
128 oid4=$(calc_oid "$content4")
129 oid5=$(calc_oid "$content5")
130 extraoid=$(calc_oid "$extracontent")
132 # if the local repo exists, it has already been bootstrapped
133 [ -d "push-all" ] && exit 0
135 clone_repo "$reponame" "push-all"
136 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
137 git lfs track "*.dat"
141 \"CommitDate\":\"$(get_date -6m)\",
143 {\"Filename\":\"file1.dat\",\"Size\":${#content1},\"Data\":\"$content1\"}
147 \"CommitDate\":\"$(get_date -5m)\",
149 {\"Filename\":\"file1.dat\",\"Size\":${#content2},\"Data\":\"$content2\"}
153 \"CommitDate\":\"$(get_date -4m)\",
154 \"NewBranch\":\"branch\",
156 {\"Filename\":\"file1.dat\",\"Size\":${#content3},\"Data\":\"$content3\"}
160 \"CommitDate\":\"$(get_date -4m)\",
161 \"ParentBranches\":[\"master\"],
164 {\"Filename\":\"file1.dat\",\"Size\":${#content4},\"Data\":\"$content4\"}
168 \"CommitDate\":\"$(get_date -2m)\",
170 {\"Filename\":\"file1.dat\",\"Size\":${#content5},\"Data\":\"$content5\"},
171 {\"Filename\":\"file2.dat\",\"Size\":${#extracontent},\"Data\":\"$extracontent\"}
174 ]" | lfstest-testutils addcommits
177 git commit -m "remove file2.dat"
179 # simulate remote ref
180 mkdir -p .git/refs/remotes/origin
181 git rev-parse HEAD > .git/refs/remotes/origin/HEAD
183 setup_alternate_remote "$reponame-$suffix"
184 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix").locksverify" true
187 begin_test "push --all (no ref args)"
191 push_all_setup "everything"
193 git lfs push --dry-run --all origin 2>&1 | tee push.log
194 grep "push $oid1 => file1.dat" push.log
195 grep "push $oid2 => file1.dat" push.log
196 grep "push $oid3 => file1.dat" push.log
197 grep "push $oid4 => file1.dat" push.log
198 grep "push $oid5 => file1.dat" push.log
199 grep "push $extraoid => file2.dat" push.log
200 [ $(grep -c "push" < push.log) -eq 6 ]
202 git push --all origin 2>&1 | tee push.log
203 [ $(grep -c "Uploading LFS objects: 100% (6/6), 36 B" push.log) -eq 1 ]
204 assert_server_object "$reponame-$suffix" "$oid1"
205 assert_server_object "$reponame-$suffix" "$oid2"
206 assert_server_object "$reponame-$suffix" "$oid3"
207 assert_server_object "$reponame-$suffix" "$oid4"
208 assert_server_object "$reponame-$suffix" "$oid5"
209 assert_server_object "$reponame-$suffix" "$extraoid"
211 echo "push while missing old objects locally"
212 setup_alternate_remote "$reponame-$suffix-2"
213 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
215 git lfs push --object-id origin $oid1
216 assert_server_object "$reponame-$suffix-2" "$oid1"
217 refute_server_object "$reponame-$suffix-2" "$oid2"
218 refute_server_object "$reponame-$suffix-2" "$oid3"
219 refute_server_object "$reponame-$suffix-2" "$oid4"
220 refute_server_object "$reponame-$suffix-2" "$oid5"
221 refute_server_object "$reponame-$suffix-2" "$extraoid"
222 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
224 echo "dry run missing local object that exists on server"
225 git lfs push --dry-run --all origin 2>&1 | tee push.log
226 grep "push $oid1 => file1.dat" push.log
227 grep "push $oid2 => file1.dat" push.log
228 grep "push $oid3 => file1.dat" push.log
229 grep "push $oid4 => file1.dat" push.log
230 grep "push $oid5 => file1.dat" push.log
231 grep "push $extraoid => file2.dat" push.log
232 [ $(grep -c "push" push.log) -eq 6 ]
234 git push --all origin 2>&1 | tee push.log
235 grep "Uploading LFS objects: 100% (6/6), 36 B" push.log
236 assert_server_object "$reponame-$suffix-2" "$oid2"
237 assert_server_object "$reponame-$suffix-2" "$oid3"
238 assert_server_object "$reponame-$suffix-2" "$oid4"
239 assert_server_object "$reponame-$suffix-2" "$oid5"
240 assert_server_object "$reponame-$suffix-2" "$extraoid"
244 begin_test "push --all (1 ref arg)"
250 git lfs push --dry-run --all origin branch 2>&1 | tee push.log
251 grep "push $oid1 => file1.dat" push.log
252 grep "push $oid2 => file1.dat" push.log
253 grep "push $oid3 => file1.dat" push.log
254 [ $(grep -c "push" < push.log) -eq 3 ]
256 git lfs push --all origin branch 2>&1 | tee push.log
257 grep "3 files" push.log
258 assert_server_object "$reponame-$suffix" "$oid1"
259 assert_server_object "$reponame-$suffix" "$oid2"
260 assert_server_object "$reponame-$suffix" "$oid3"
261 refute_server_object "$reponame-$suffix" "$oid4" # in master and the tag
262 refute_server_object "$reponame-$suffix" "$oid5"
263 refute_server_object "$reponame-$suffix" "$extraoid"
265 echo "push while missing old objects locally"
266 setup_alternate_remote "$reponame-$suffix-2"
267 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
268 git lfs push --object-id origin $oid1
269 assert_server_object "$reponame-$suffix-2" "$oid1"
270 refute_server_object "$reponame-$suffix-2" "$oid2"
271 refute_server_object "$reponame-$suffix-2" "$oid3"
272 refute_server_object "$reponame-$suffix-2" "$oid4"
273 refute_server_object "$reponame-$suffix-2" "$oid5"
274 refute_server_object "$reponame-$suffix-2" "$extraoid"
275 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
277 # dry run doesn't change
278 git lfs push --dry-run --all origin branch 2>&1 | tee push.log
279 grep "push $oid1 => file1.dat" push.log
280 grep "push $oid2 => file1.dat" push.log
281 grep "push $oid3 => file1.dat" push.log
282 [ $(grep -c "push" push.log) -eq 3 ]
284 git push --all origin branch 2>&1 | tee push.log
285 grep "5 files, 1 skipped" push.log # should be 5?
286 assert_server_object "$reponame-$suffix-2" "$oid2"
287 assert_server_object "$reponame-$suffix-2" "$oid3"
288 refute_server_object "$reponame-$suffix-2" "$oid4"
289 refute_server_object "$reponame-$suffix-2" "$oid5"
290 refute_server_object "$reponame-$suffix-2" "$extraoid"
294 begin_test "push --all (multiple ref args)"
298 push_all_setup "multiple-refs"
300 git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
301 grep "push $oid1 => file1.dat" push.log
302 grep "push $oid2 => file1.dat" push.log
303 grep "push $oid3 => file1.dat" push.log
304 grep "push $oid4 => file1.dat" push.log
305 [ $(grep -c "push" push.log) -eq 4 ]
307 git lfs push --all origin branch tag 2>&1 | tee push.log
308 grep "4 files" push.log
309 assert_server_object "$reponame-$suffix" "$oid1"
310 assert_server_object "$reponame-$suffix" "$oid2"
311 assert_server_object "$reponame-$suffix" "$oid3"
312 assert_server_object "$reponame-$suffix" "$oid4"
313 refute_server_object "$reponame-$suffix" "$oid5" # only in master
314 refute_server_object "$reponame-$suffix" "$extraoid"
316 echo "push while missing old objects locally"
317 setup_alternate_remote "$reponame-$suffix-2"
318 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
319 git lfs push --object-id origin $oid1
320 assert_server_object "$reponame-$suffix-2" "$oid1"
321 refute_server_object "$reponame-$suffix-2" "$oid2"
322 refute_server_object "$reponame-$suffix-2" "$oid3"
323 refute_server_object "$reponame-$suffix-2" "$oid4"
324 refute_server_object "$reponame-$suffix-2" "$oid5"
325 refute_server_object "$reponame-$suffix-2" "$extraoid"
326 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
328 # dry run doesn't change
329 git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
330 grep "push $oid1 => file1.dat" push.log
331 grep "push $oid2 => file1.dat" push.log
332 grep "push $oid3 => file1.dat" push.log
333 grep "push $oid4 => file1.dat" push.log
334 [ $(grep -c "push" push.log) -eq 3 ]
336 git push --all origin branch tag 2>&1 | tee push.log
337 grep "5 files, 1 skipped" push.log # should be 5?
338 assert_server_object "$reponame-$suffix-2" "$oid2"
339 assert_server_object "$reponame-$suffix-2" "$oid3"
340 assert_server_object "$reponame-$suffix-2" "$oid4"
341 refute_server_object "$reponame-$suffix-2" "$oid5"
342 refute_server_object "$reponame-$suffix-2" "$extraoid"
346 begin_test "push --all (ref with deleted files)"
350 push_all_setup "ref-with-deleted"
352 git lfs push --dry-run --all origin master 2>&1 | tee push.log
353 grep "push $oid1 => file1.dat" push.log
354 grep "push $oid2 => file1.dat" push.log
355 grep "push $oid4 => file1.dat" push.log
356 grep "push $oid5 => file1.dat" push.log
357 grep "push $extraoid => file2.dat" push.log
358 [ $(grep -c "push" push.log) -eq 5 ]
360 git lfs push --all origin master 2>&1 | tee push.log
361 grep "5 files" push.log
362 assert_server_object "$reponame-$suffix" "$oid1"
363 assert_server_object "$reponame-$suffix" "$oid2"
364 refute_server_object "$reponame-$suffix" "$oid3" # only in the branch
365 assert_server_object "$reponame-$suffix" "$oid4"
366 assert_server_object "$reponame-$suffix" "$oid5"
367 assert_server_object "$reponame-$suffix" "$extraoid"
369 echo "push while missing old objects locally"
370 setup_alternate_remote "$reponame-$suffix-2"
371 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
372 git lfs push --object-id origin $oid1
373 assert_server_object "$reponame-$suffix-2" "$oid1"
374 refute_server_object "$reponame-$suffix-2" "$oid2"
375 refute_server_object "$reponame-$suffix-2" "$oid3"
376 refute_server_object "$reponame-$suffix-2" "$oid4"
377 refute_server_object "$reponame-$suffix-2" "$oid5"
378 refute_server_object "$reponame-$suffix-2" "$extraoid"
379 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
381 # dry run doesn't change
382 git lfs push --dry-run --all origin master 2>&1 | tee push.log
383 grep "push $oid1 => file1.dat" push.log
384 grep "push $oid2 => file1.dat" push.log
385 grep "push $oid4 => file1.dat" push.log
386 grep "push $oid5 => file1.dat" push.log
387 grep "push $extraoid => file2.dat" push.log
388 [ $(grep -c "push" push.log) -eq 5 ]
390 git push --all origin master 2>&1 | tee push.log
391 grep "5 files, 1 skipped" push.log # should be 5?
392 assert_server_object "$reponame-$suffix-2" "$oid2"
393 refute_server_object "$reponame-$suffix-2" "$oid3"
394 assert_server_object "$reponame-$suffix-2" "$oid4"
395 assert_server_object "$reponame-$suffix-2" "$oid5"
396 assert_server_object "$reponame-$suffix-2" "$extraoid"
400 begin_test "push object id(s)"
404 reponame="$(basename "$0" ".sh")"
405 setup_remote_repo "$reponame"
406 clone_repo "$reponame" repo2
408 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
410 git lfs track "*.dat"
411 echo "push a" > a.dat
412 git add .gitattributes a.dat
413 git commit -m "add a.dat"
415 git lfs push --object-id origin \
416 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
418 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
420 echo "push b" > b.dat
422 git commit -m "add b.dat"
424 git lfs push --object-id origin \
425 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
426 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 \
428 grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
432 begin_test "push modified files"
436 reponame="$(basename "$0" ".sh")-modified"
437 setup_remote_repo "$reponame"
438 clone_repo "$reponame" "$reponame"
440 git lfs track "*.dat"
441 # generate content we'll use
442 content1="filecontent1"
443 content2="filecontent2"
444 content3="filecontent3"
445 content4="filecontent4"
446 content5="filecontent5"
447 oid1=$(calc_oid "$content1")
448 oid2=$(calc_oid "$content2")
449 oid3=$(calc_oid "$content3")
450 oid4=$(calc_oid "$content4")
451 oid5=$(calc_oid "$content5")
455 \"CommitDate\":\"$(get_date -6m)\",
457 {\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
460 \"CommitDate\":\"$(get_date -3m)\",
462 {\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"}]
465 \"CommitDate\":\"$(get_date -1m)\",
466 \"NewBranch\":\"other_branch\",
468 {\"Filename\":\"file1.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
471 \"CommitDate\":\"$(get_date -1m)\",
472 \"ParentBranches\":[\"master\"],
474 {\"Filename\":\"file1.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"},
475 {\"Filename\":\"file2.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
477 ]" | lfstest-testutils addcommits
479 git lfs push origin master
480 git lfs push origin other_branch
481 assert_server_object "$reponame" "$oid1"
482 assert_server_object "$reponame" "$oid2"
483 assert_server_object "$reponame" "$oid3"
484 assert_server_object "$reponame" "$oid4"
485 assert_server_object "$reponame" "$oid5"
489 begin_test "push with invalid remote"
493 git lfs push not-a-remote 2>&1 | tee push.log
494 grep "Invalid remote name" push.log
498 begin_test "push ambiguous branch name"
502 reponame="$(basename "$0" ".sh")-ambiguous-branch"
503 setup_remote_repo "$reponame"
504 clone_repo "$reponame" "$reponame"
507 git lfs track "*.dat" 2>&1 | tee track.log
508 grep "Tracking \"\*.dat\"" track.log
511 # generate content we'll use
512 for ((a=0; a < NUMFILES ; a++))
514 content[$a]="filecontent$a"
515 oid[$a]=$(calc_oid "${content[$a]}")
520 \"CommitDate\":\"$(get_date -10d)\",
522 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
523 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
526 \"NewBranch\":\"ambiguous\",
527 \"CommitDate\":\"$(get_date -5d)\",
529 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
532 \"CommitDate\":\"$(get_date -2d)\",
534 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
537 \"ParentBranches\":[\"master\"],
538 \"CommitDate\":\"$(get_date -1d)\",
540 {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
542 ]" | lfstest-testutils addcommits
544 # create tag with same name as branch
547 # lfs push master, should work
548 git lfs push origin master
550 # push ambiguous, does not fail since lfs scans git with sha, not ref name
551 git lfs push origin ambiguous
555 begin_test "push (retry with expired actions)"
559 reponame="push_retry_expired_action"
560 setup_remote_repo "$reponame"
561 clone_repo "$reponame" "$reponame"
563 git lfs track "*.dat"
564 contents="return-expired-action"
565 contents_oid="$(calc_oid "$contents")"
566 contents_size="$(printf "$contents" | wc -c | awk '{ print $1 }')"
567 printf "$contents" > a.dat
568 git add .gitattributes a.dat
570 git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
571 grep "master (root-commit)" commit.log
572 grep "2 files changed" commit.log
573 grep "create mode 100644 a.dat" commit.log
574 grep "create mode 100644 .gitattributes" commit.log
576 GIT_TRACE=1 git push origin master 2>&1 | tee push.log
578 expected="enqueue retry #1 for \"$contents_oid\" (size: $contents_size): LFS: tq: action \"upload\" expires at"
580 grep "$expected" push.log
581 grep "Uploading LFS objects: 100% (1/1), 21 B" push.log
585 begin_test "push to raw remote url"
589 setup_remote_repo "push-raw"
594 git lfs track "*.dat"
597 contents_oid=$(calc_oid "$contents")
599 printf "$contents" > raw.dat
600 git add raw.dat .gitattributes
601 git commit -m "add" 2>&1 | tee commit.log
602 grep "master (root-commit)" commit.log
603 grep "2 files changed" commit.log
604 grep "create mode 100644 raw.dat" commit.log
605 grep "create mode 100644 .gitattributes" commit.log
607 refute_server_object push-raw "$contents_oid"
609 git lfs push $GITSERVER/push-raw master
611 assert_server_object push-raw "$contents_oid"
615 begin_test "push (with invalid object size)"
619 reponame="push-invalid-object-size"
620 setup_remote_repo "$reponame"
621 clone_repo "$reponame" "$reponame"
623 git lfs track "*.dat"
624 contents="return-invalid-size"
625 printf "$contents" > a.dat
627 git add a.dat .gitattributes
628 git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
629 grep "master (root-commit)" commit.log
630 grep "2 files changed" commit.log
631 grep "create mode 100644 a.dat" commit.log
632 grep "create mode 100644 .gitattributes" commit.log
635 git push origin master 2>&1 2> push.log
639 grep "invalid size (got: -1)" push.log
640 [ "0" -eq "$(grep -c "panic" push.log)" ]
643 refute_server_object "$reponame" "$(calc_oid "$contents")"
647 begin_test "push with deprecated _links"
651 reponame="$(basename "$0" ".sh")-deprecated"
652 setup_remote_repo "$reponame"
653 clone_repo "$reponame" "$reponame"
655 git lfs track "*.dat"
656 git add .gitattributes
657 git commit -m "initial commit"
659 contents="send-deprecated-links"
660 contents_oid="$(calc_oid "$contents")"
661 printf "$contents" > a.dat
663 git commit -m "add a.dat"
665 git push origin master
667 assert_server_object "$reponame" "$contents_oid"