be222290d004e87eead1198351fcba846000fc87
[scm/test.git] / test / test-push.sh
1 #!/usr/bin/env bash
2
3 . "test/testlib.sh"
4
5 begin_test "push with good ref"
6 (
7   set -e
8   reponame="push-master-branch-required"
9   setup_remote_repo "$reponame"
10   clone_repo "$reponame" "$reponame"
11
12   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
13   git lfs track "*.dat"
14   echo "push a" > a.dat
15   git add .gitattributes a.dat
16   git commit -m "add a.dat"
17
18   git lfs push origin master
19 )
20 end_test
21
22 begin_test "push with tracked ref"
23 (
24   set -e
25   reponame="push-tracked-branch-required"
26   setup_remote_repo "$reponame"
27   clone_repo "$reponame" "$reponame"
28
29   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
30   git lfs track "*.dat"
31   echo "push a" > a.dat
32   git add .gitattributes a.dat
33   git commit -m "add a.dat"
34
35   git config push.default upstream
36   git config branch.master.merge refs/heads/tracked
37   git lfs push origin master
38 )
39 end_test
40
41 begin_test "push with bad ref"
42 (
43   set -e
44   reponame="push-other-branch-required"
45   setup_remote_repo "$reponame"
46   clone_repo "$reponame" "$reponame"
47
48   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
49   git lfs track "*.dat"
50   echo "push a" > a.dat
51   git add .gitattributes a.dat
52   git commit -m "add a.dat"
53
54   git lfs push origin master 2>&1 | tee push.log
55   if [ "0" -eq "${PIPESTATUS[0]}" ]; then
56     echo "expected command to fail"
57     exit 1
58   fi
59
60   grep 'batch response: Expected ref "refs/heads/other", got "refs/heads/master"' push.log
61 )
62 end_test
63
64 begin_test "push"
65 (
66   set -e
67
68   reponame="$(basename "$0" ".sh")"
69   setup_remote_repo "$reponame"
70   clone_repo "$reponame" repo
71
72   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
73
74   git lfs track "*.dat"
75   echo "push a" > a.dat
76   git add .gitattributes a.dat
77   git commit -m "add a.dat"
78
79   git lfs push --dry-run origin master 2>&1 | tee push.log
80   grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
81   [ $(grep -c "push" push.log) -eq 1 ]
82
83   git lfs push origin master 2>&1 | tee push.log
84   grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
85
86   git checkout -b push-b
87   echo "push b" > b.dat
88   git add b.dat
89   git commit -m "add b.dat"
90
91   git lfs push --dry-run origin push-b 2>&1 | tee push.log
92   grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
93   grep "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
94   [ $(grep -c "push" < push.log) -eq 2 ]
95
96   # simulate remote ref
97   mkdir -p .git/refs/remotes/origin
98   git rev-parse HEAD > .git/refs/remotes/origin/HEAD
99
100   git lfs push --dry-run origin push-b 2>&1 | tee push.log
101   [ $(grep -c "push" push.log) -eq 0 ]
102
103   rm -rf .git/refs/remotes
104
105   git lfs push origin push-b 2>&1 | tee push.log
106   grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
107 )
108 end_test
109
110 # sets up the tests for the next few push --all tests
111 push_all_setup() {
112   suffix="$1"
113   reponame="$(basename "$0" ".sh")-all"
114   content1="initial"
115   content2="update"
116   content3="branch"
117   content4="tagged"
118   content5="master"
119   extracontent="extra"
120   oid1=$(calc_oid "$content1")
121   oid2=$(calc_oid "$content2")
122   oid3=$(calc_oid "$content3")
123   oid4=$(calc_oid "$content4")
124   oid5=$(calc_oid "$content5")
125   extraoid=$(calc_oid "$extracontent")
126
127   # if the local repo exists, it has already been bootstrapped
128   [ -d "push-all" ] && exit 0
129
130   clone_repo "$reponame" "push-all"
131   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
132   git lfs track "*.dat"
133
134   echo "[
135   {
136     \"CommitDate\":\"$(get_date -6m)\",
137     \"Files\":[
138       {\"Filename\":\"file1.dat\",\"Size\":${#content1},\"Data\":\"$content1\"}
139     ]
140   },
141   {
142     \"CommitDate\":\"$(get_date -5m)\",
143     \"Files\":[
144       {\"Filename\":\"file1.dat\",\"Size\":${#content2},\"Data\":\"$content2\"}
145     ]
146   },
147   {
148     \"CommitDate\":\"$(get_date -4m)\",
149     \"NewBranch\":\"branch\",
150     \"Files\":[
151       {\"Filename\":\"file1.dat\",\"Size\":${#content3},\"Data\":\"$content3\"}
152     ]
153   },
154   {
155     \"CommitDate\":\"$(get_date -4m)\",
156     \"ParentBranches\":[\"master\"],
157     \"Tags\":[\"tag\"],
158     \"Files\":[
159       {\"Filename\":\"file1.dat\",\"Size\":${#content4},\"Data\":\"$content4\"}
160     ]
161   },
162   {
163     \"CommitDate\":\"$(get_date -2m)\",
164     \"Files\":[
165       {\"Filename\":\"file1.dat\",\"Size\":${#content5},\"Data\":\"$content5\"},
166       {\"Filename\":\"file2.dat\",\"Size\":${#extracontent},\"Data\":\"$extracontent\"}
167     ]
168   }
169   ]" | lfstest-testutils addcommits
170
171   git rm file2.dat
172   git commit -m "remove file2.dat"
173
174   # simulate remote ref
175   mkdir -p .git/refs/remotes/origin
176   git rev-parse HEAD > .git/refs/remotes/origin/HEAD
177
178   setup_alternate_remote "$reponame-$suffix"
179   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix").locksverify" true
180 }
181
182 begin_test "push --all (no ref args)"
183 (
184   set -e
185
186   push_all_setup "everything"
187
188   git lfs push --dry-run --all origin 2>&1 | tee push.log
189   grep "push $oid1 => file1.dat" push.log
190   grep "push $oid2 => file1.dat" push.log
191   grep "push $oid3 => file1.dat" push.log
192   grep "push $oid4 => file1.dat" push.log
193   grep "push $oid5 => file1.dat" push.log
194   grep "push $extraoid => file2.dat" push.log
195   [ $(grep -c "push" < push.log) -eq 6 ]
196
197   git push --all origin 2>&1 | tee push.log
198   [ $(grep -c "Uploading LFS objects: 100% (6/6), 36 B" push.log) -eq 1 ]
199   assert_server_object "$reponame-$suffix" "$oid1"
200   assert_server_object "$reponame-$suffix" "$oid2"
201   assert_server_object "$reponame-$suffix" "$oid3"
202   assert_server_object "$reponame-$suffix" "$oid4"
203   assert_server_object "$reponame-$suffix" "$oid5"
204   assert_server_object "$reponame-$suffix" "$extraoid"
205
206   echo "push while missing old objects locally"
207   setup_alternate_remote "$reponame-$suffix-2"
208   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
209
210   git lfs push --object-id origin $oid1
211   assert_server_object "$reponame-$suffix-2" "$oid1"
212   refute_server_object "$reponame-$suffix-2" "$oid2"
213   refute_server_object "$reponame-$suffix-2" "$oid3"
214   refute_server_object "$reponame-$suffix-2" "$oid4"
215   refute_server_object "$reponame-$suffix-2" "$oid5"
216   refute_server_object "$reponame-$suffix-2" "$extraoid"
217   rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
218
219   echo "dry run missing local object that exists on server"
220   git lfs push --dry-run --all origin 2>&1 | tee push.log
221   grep "push $oid1 => file1.dat" push.log
222   grep "push $oid2 => file1.dat" push.log
223   grep "push $oid3 => file1.dat" push.log
224   grep "push $oid4 => file1.dat" push.log
225   grep "push $oid5 => file1.dat" push.log
226   grep "push $extraoid => file2.dat" push.log
227   [ $(grep -c "push" push.log) -eq 6 ]
228
229   git push --all origin 2>&1 | tee push.log
230   grep "Uploading LFS objects: 100% (6/6), 36 B" push.log
231   assert_server_object "$reponame-$suffix-2" "$oid2"
232   assert_server_object "$reponame-$suffix-2" "$oid3"
233   assert_server_object "$reponame-$suffix-2" "$oid4"
234   assert_server_object "$reponame-$suffix-2" "$oid5"
235   assert_server_object "$reponame-$suffix-2" "$extraoid"
236 )
237 end_test
238
239 begin_test "push --all (1 ref arg)"
240 (
241   set -e
242
243   push_all_setup "ref"
244
245   git lfs push --dry-run --all origin branch 2>&1 | tee push.log
246   grep "push $oid1 => file1.dat" push.log
247   grep "push $oid2 => file1.dat" push.log
248   grep "push $oid3 => file1.dat" push.log
249   [ $(grep -c "push" < push.log) -eq 3 ]
250
251   git lfs push --all origin branch 2>&1 | tee push.log
252   grep "3 files" push.log
253   assert_server_object "$reponame-$suffix" "$oid1"
254   assert_server_object "$reponame-$suffix" "$oid2"
255   assert_server_object "$reponame-$suffix" "$oid3"
256   refute_server_object "$reponame-$suffix" "$oid4"     # in master and the tag
257   refute_server_object "$reponame-$suffix" "$oid5"
258   refute_server_object "$reponame-$suffix" "$extraoid"
259
260   echo "push while missing old objects locally"
261   setup_alternate_remote "$reponame-$suffix-2"
262   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
263   git lfs push --object-id origin $oid1
264   assert_server_object "$reponame-$suffix-2" "$oid1"
265   refute_server_object "$reponame-$suffix-2" "$oid2"
266   refute_server_object "$reponame-$suffix-2" "$oid3"
267   refute_server_object "$reponame-$suffix-2" "$oid4"
268   refute_server_object "$reponame-$suffix-2" "$oid5"
269   refute_server_object "$reponame-$suffix-2" "$extraoid"
270   rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
271
272   # dry run doesn't change
273   git lfs push --dry-run --all origin branch 2>&1 | tee push.log
274   grep "push $oid1 => file1.dat" push.log
275   grep "push $oid2 => file1.dat" push.log
276   grep "push $oid3 => file1.dat" push.log
277   [ $(grep -c "push" push.log) -eq 3 ]
278
279   git push --all origin branch 2>&1 | tee push.log
280   grep "5 files, 1 skipped" push.log # should be 5?
281   assert_server_object "$reponame-$suffix-2" "$oid2"
282   assert_server_object "$reponame-$suffix-2" "$oid3"
283   refute_server_object "$reponame-$suffix-2" "$oid4"
284   refute_server_object "$reponame-$suffix-2" "$oid5"
285   refute_server_object "$reponame-$suffix-2" "$extraoid"
286 )
287 end_test
288
289 begin_test "push --all (multiple ref args)"
290 (
291   set -e
292
293   push_all_setup "multiple-refs"
294
295   git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
296   grep "push $oid1 => file1.dat" push.log
297   grep "push $oid2 => file1.dat" push.log
298   grep "push $oid3 => file1.dat" push.log
299   grep "push $oid4 => file1.dat" push.log
300   [ $(grep -c "push" push.log) -eq 4 ]
301
302   git lfs push --all origin branch tag 2>&1 | tee push.log
303   grep "4 files" push.log
304   assert_server_object "$reponame-$suffix" "$oid1"
305   assert_server_object "$reponame-$suffix" "$oid2"
306   assert_server_object "$reponame-$suffix" "$oid3"
307   assert_server_object "$reponame-$suffix" "$oid4"
308   refute_server_object "$reponame-$suffix" "$oid5"     # only in master
309   refute_server_object "$reponame-$suffix" "$extraoid"
310
311   echo "push while missing old objects locally"
312   setup_alternate_remote "$reponame-$suffix-2"
313   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
314   git lfs push --object-id origin $oid1
315   assert_server_object "$reponame-$suffix-2" "$oid1"
316   refute_server_object "$reponame-$suffix-2" "$oid2"
317   refute_server_object "$reponame-$suffix-2" "$oid3"
318   refute_server_object "$reponame-$suffix-2" "$oid4"
319   refute_server_object "$reponame-$suffix-2" "$oid5"
320   refute_server_object "$reponame-$suffix-2" "$extraoid"
321   rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
322
323   # dry run doesn't change
324   git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
325   grep "push $oid1 => file1.dat" push.log
326   grep "push $oid2 => file1.dat" push.log
327   grep "push $oid3 => file1.dat" push.log
328   grep "push $oid4 => file1.dat" push.log
329   [ $(grep -c "push" push.log) -eq 3 ]
330
331   git push --all origin branch tag 2>&1 | tee push.log
332   grep "5 files, 1 skipped" push.log # should be 5?
333   assert_server_object "$reponame-$suffix-2" "$oid2"
334   assert_server_object "$reponame-$suffix-2" "$oid3"
335   assert_server_object "$reponame-$suffix-2" "$oid4"
336   refute_server_object "$reponame-$suffix-2" "$oid5"
337   refute_server_object "$reponame-$suffix-2" "$extraoid"
338 )
339 end_test
340
341 begin_test "push --all (ref with deleted files)"
342 (
343   set -e
344
345   push_all_setup "ref-with-deleted"
346
347   git lfs push --dry-run --all origin master 2>&1 | tee push.log
348   grep "push $oid1 => file1.dat" push.log
349   grep "push $oid2 => file1.dat" push.log
350   grep "push $oid4 => file1.dat" push.log
351   grep "push $oid5 => file1.dat" push.log
352   grep "push $extraoid => file2.dat" push.log
353   [ $(grep -c "push" push.log) -eq 5 ]
354
355   git lfs push --all origin master 2>&1 | tee push.log
356   grep "5 files" push.log
357   assert_server_object "$reponame-$suffix" "$oid1"
358   assert_server_object "$reponame-$suffix" "$oid2"
359   refute_server_object "$reponame-$suffix" "$oid3" # only in the branch
360   assert_server_object "$reponame-$suffix" "$oid4"
361   assert_server_object "$reponame-$suffix" "$oid5"
362   assert_server_object "$reponame-$suffix" "$extraoid"
363
364   echo "push while missing old objects locally"
365   setup_alternate_remote "$reponame-$suffix-2"
366   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
367   git lfs push --object-id origin $oid1
368   assert_server_object "$reponame-$suffix-2" "$oid1"
369   refute_server_object "$reponame-$suffix-2" "$oid2"
370   refute_server_object "$reponame-$suffix-2" "$oid3"
371   refute_server_object "$reponame-$suffix-2" "$oid4"
372   refute_server_object "$reponame-$suffix-2" "$oid5"
373   refute_server_object "$reponame-$suffix-2" "$extraoid"
374   rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
375
376   # dry run doesn't change
377   git lfs push --dry-run --all origin master 2>&1 | tee push.log
378   grep "push $oid1 => file1.dat" push.log
379   grep "push $oid2 => file1.dat" push.log
380   grep "push $oid4 => file1.dat" push.log
381   grep "push $oid5 => file1.dat" push.log
382   grep "push $extraoid => file2.dat" push.log
383   [ $(grep -c "push" push.log) -eq 5 ]
384
385   git push --all origin master 2>&1 | tee push.log
386   grep "5 files, 1 skipped" push.log # should be 5?
387   assert_server_object "$reponame-$suffix-2" "$oid2"
388   refute_server_object "$reponame-$suffix-2" "$oid3"
389   assert_server_object "$reponame-$suffix-2" "$oid4"
390   assert_server_object "$reponame-$suffix-2" "$oid5"
391   assert_server_object "$reponame-$suffix-2" "$extraoid"
392 )
393 end_test
394
395 begin_test "push object id(s)"
396 (
397   set -e
398
399   reponame="$(basename "$0" ".sh")"
400   setup_remote_repo "$reponame"
401   clone_repo "$reponame" repo2
402
403   git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
404
405   git lfs track "*.dat"
406   echo "push a" > a.dat
407   git add .gitattributes a.dat
408   git commit -m "add a.dat"
409
410   git lfs push --object-id origin \
411     4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
412     2>&1 | tee push.log
413   grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
414
415   echo "push b" > b.dat
416   git add b.dat
417   git commit -m "add b.dat"
418
419   git lfs push --object-id origin \
420     4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
421     82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 \
422     2>&1 | tee push.log
423   grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
424 )
425 end_test
426
427 begin_test "push modified files"
428 (
429   set -e
430
431   reponame="$(basename "$0" ".sh")-modified"
432   setup_remote_repo "$reponame"
433   clone_repo "$reponame" "$reponame"
434
435   git lfs track "*.dat"
436   # generate content we'll use
437   content1="filecontent1"
438   content2="filecontent2"
439   content3="filecontent3"
440   content4="filecontent4"
441   content5="filecontent5"
442   oid1=$(calc_oid "$content1")
443   oid2=$(calc_oid "$content2")
444   oid3=$(calc_oid "$content3")
445   oid4=$(calc_oid "$content4")
446   oid5=$(calc_oid "$content5")
447
448   echo "[
449   {
450     \"CommitDate\":\"$(get_date -6m)\",
451     \"Files\":[
452       {\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
453   },
454   {
455     \"CommitDate\":\"$(get_date -3m)\",
456     \"Files\":[
457       {\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"}]
458   },
459   {
460     \"CommitDate\":\"$(get_date -1m)\",
461     \"NewBranch\":\"other_branch\",
462     \"Files\":[
463       {\"Filename\":\"file1.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
464   },
465   {
466     \"CommitDate\":\"$(get_date -1m)\",
467     \"ParentBranches\":[\"master\"],
468     \"Files\":[
469       {\"Filename\":\"file1.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"},
470       {\"Filename\":\"file2.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
471   }
472   ]" | lfstest-testutils addcommits
473
474   git lfs push origin master
475   git lfs push origin other_branch
476   assert_server_object "$reponame" "$oid1"
477   assert_server_object "$reponame" "$oid2"
478   assert_server_object "$reponame" "$oid3"
479   assert_server_object "$reponame" "$oid4"
480   assert_server_object "$reponame" "$oid5"
481 )
482 end_test
483
484 begin_test "push with invalid remote"
485 (
486   set -e
487   cd repo
488   git lfs push not-a-remote 2>&1 | tee push.log
489   grep "Invalid remote name" push.log
490 )
491 end_test
492
493 begin_test "push ambiguous branch name"
494 (
495   set -e
496
497   reponame="$(basename "$0" ".sh")-ambiguous-branch"
498   setup_remote_repo "$reponame"
499   clone_repo "$reponame" "$reponame"
500
501
502   git lfs track "*.dat" 2>&1 | tee track.log
503   grep "Tracking \"\*.dat\"" track.log
504
505   NUMFILES=5
506   # generate content we'll use
507   for ((a=0; a < NUMFILES ; a++))
508   do
509     content[$a]="filecontent$a"
510     oid[$a]=$(calc_oid "${content[$a]}")
511   done
512
513   echo "[
514   {
515     \"CommitDate\":\"$(get_date -10d)\",
516     \"Files\":[
517       {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
518       {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
519   },
520   {
521     \"NewBranch\":\"ambiguous\",
522     \"CommitDate\":\"$(get_date -5d)\",
523     \"Files\":[
524       {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
525   },
526   {
527     \"CommitDate\":\"$(get_date -2d)\",
528     \"Files\":[
529       {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
530   },
531   {
532     \"ParentBranches\":[\"master\"],
533     \"CommitDate\":\"$(get_date -1d)\",
534     \"Files\":[
535       {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
536   }
537   ]" | lfstest-testutils addcommits
538
539   # create tag with same name as branch
540   git tag ambiguous
541
542   # lfs push master, should work
543   git lfs push origin master
544
545   # push ambiguous, does not fail since lfs scans git with sha, not ref name
546   git lfs push origin ambiguous
547 )
548 end_test
549
550 begin_test "push (retry with expired actions)"
551 (
552   set -e
553
554   reponame="push_retry_expired_action"
555   setup_remote_repo "$reponame"
556   clone_repo "$reponame" "$reponame"
557
558   git lfs track "*.dat"
559   contents="return-expired-action"
560   contents_oid="$(calc_oid "$contents")"
561   contents_size="$(printf "$contents" | wc -c | awk '{ print $1 }')"
562   printf "$contents" > a.dat
563   git add .gitattributes a.dat
564
565   git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
566   grep "master (root-commit)" commit.log
567   grep "2 files changed" commit.log
568   grep "create mode 100644 a.dat" commit.log
569   grep "create mode 100644 .gitattributes" commit.log
570
571   GIT_TRACE=1 git push origin master 2>&1 | tee push.log
572
573   expected="enqueue retry #1 for \"$contents_oid\" (size: $contents_size): LFS: tq: action \"upload\" expires at"
574
575   grep "$expected" push.log
576   grep "Uploading LFS objects: 100% (1/1), 21 B" push.log
577 )
578 end_test
579
580 begin_test "push to raw remote url"
581 (
582   set -e
583
584   setup_remote_repo "push-raw"
585   mkdir push-raw
586   cd push-raw
587   git init
588
589   git lfs track "*.dat"
590
591   contents="raw"
592   contents_oid=$(calc_oid "$contents")
593
594   printf "$contents" > raw.dat
595   git add raw.dat .gitattributes
596   git commit -m "add" 2>&1 | tee commit.log
597   grep "master (root-commit)" commit.log
598   grep "2 files changed" commit.log
599   grep "create mode 100644 raw.dat" commit.log
600   grep "create mode 100644 .gitattributes" commit.log
601
602   refute_server_object push-raw "$contents_oid"
603
604   git lfs push $GITSERVER/push-raw master
605
606   assert_server_object push-raw "$contents_oid"
607 )
608 end_test
609
610 begin_test "push (with invalid object size)"
611 (
612   set -e
613
614   reponame="push-invalid-object-size"
615   setup_remote_repo "$reponame"
616   clone_repo "$reponame" "$reponame"
617
618   git lfs track "*.dat"
619   contents="return-invalid-size"
620   printf "$contents" > a.dat
621
622   git add a.dat .gitattributes
623   git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
624   grep "master (root-commit)" commit.log
625   grep "2 files changed" commit.log
626   grep "create mode 100644 a.dat" commit.log
627   grep "create mode 100644 .gitattributes" commit.log
628
629   set +e
630   git push origin master 2>&1 2> push.log
631   res="$?"
632   set -e
633
634   grep "invalid size (got: -1)" push.log
635   [ "0" -eq "$(grep -c "panic" push.log)" ]
636   [ "0" -ne "$res" ]
637
638   refute_server_object "$reponame" "$(calc_oid "$contents")"
639 )
640 end_test
641
642 begin_test "push with deprecated _links"
643 (
644   set -e
645
646   reponame="$(basename "$0" ".sh")-deprecated"
647   setup_remote_repo "$reponame"
648   clone_repo "$reponame" "$reponame"
649
650   git lfs track "*.dat"
651   git add .gitattributes
652   git commit -m "initial commit"
653
654   contents="send-deprecated-links"
655   contents_oid="$(calc_oid "$contents")"
656   printf "$contents" > a.dat
657   git add a.dat
658   git commit -m "add a.dat"
659
660   git push origin master
661
662   assert_server_object "$reponame" "$contents_oid"
663 )
664
665 begin_test "push with missing objects (lfs.allowincompletepush=t)"
666 (
667   set -e
668
669   reponame="push-with-missing-objects"
670   setup_remote_repo "$reponame"
671   clone_repo "$reponame" "$reponame"
672
673   git lfs track "*.dat"
674   git add .gitattributes
675   git commit -m "initial commit"
676
677   present="present"
678   present_oid="$(calc_oid "$present")"
679   printf "$present" > present.dat
680
681   missing="missing"
682   missing_oid="$(calc_oid "$missing")"
683   printf "$missing" > missing.dat
684
685   git add missing.dat present.dat
686   git commit -m "add objects"
687
688   git rm missing.dat
689   git commit -m "remove missing"
690
691   # :fire: the "missing" object
692   missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
693   missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
694   missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
695   rm "$missing_oid_path"
696
697   git push origin master 2>&1 | tee push.log
698   if [ "0" -ne "${PIPESTATUS[0]}" ]; then
699     echo >&2 "fatal: expected \`git push origin master\` to succeed ..."
700     exit 1
701   fi
702
703   grep "LFS upload missing objects" push.log
704   grep "  (missing) missing.dat ($missing_oid)" push.log
705
706   assert_server_object "$reponame" "$present_oid"
707   refute_server_object "$reponame" "$missing_oid"
708 )
709 end_test
710
711 begin_test "push reject missing objects (lfs.allowincompletepush=f)"
712 (
713   set -e
714
715   reponame="push-reject-missing-objects"
716   setup_remote_repo "$reponame"
717   clone_repo "$reponame" "$reponame"
718
719   git lfs track "*.dat"
720   git add .gitattributes
721   git commit -m "initial commit"
722
723   present="present"
724   present_oid="$(calc_oid "$present")"
725   printf "$present" > present.dat
726
727   missing="missing"
728   missing_oid="$(calc_oid "$missing")"
729   printf "$missing" > missing.dat
730
731   git add missing.dat present.dat
732   git commit -m "add objects"
733
734   git rm missing.dat
735   git commit -m "remove missing"
736
737   # :fire: the "missing" object
738   missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
739   missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
740   missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
741   rm "$missing_oid_path"
742
743   git config "lfs.allowincompletepush" "false"
744
745   git push origin master 2>&1 | tee push.log
746   if [ "1" -ne "${PIPESTATUS[0]}" ]; then
747     echo >&2 "fatal: expected \`git push origin master\` to succeed ..."
748     exit 1
749   fi
750
751   grep "no such file or directory" push.log || # unix
752     grep "cannot find the file" push.log       # windows
753   grep "failed to push some refs" push.log
754
755   refute_server_object "$reponame" "$present_oid"
756   refute_server_object "$reponame" "$missing_oid"
757 )
758 end_test