Debian Codegraph @

t/t-push.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 # sets up the repos for the first few push tests. The passed argument is the
6 # name of the repo to setup. The resulting repo will have a local file tracked
7 # with LFS and committed, but not yet pushed to the remote
8 push_repo_setup() {
9 reponame="$1"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
12
13 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
14 git lfs track "*.dat"
15 echo "push a" > a.dat
16 git add .gitattributes a.dat
17 git commit -m "add a.dat"
18 }
19
20 begin_test "push with good ref"
21 (
22 set -e
23 push_repo_setup "push-main-branch-required"
24
25 git lfs push origin main
26 )
27 end_test
28
29 begin_test "push with tracked ref"
30 (
31 set -e
32
33 push_repo_setup "push-tracked-branch-required"
34
35 git config push.default upstream
36 git config branch.main.merge refs/heads/tracked
37 git lfs push origin main
38 )
39 end_test
40
41 begin_test "push with invalid ref"
42 (
43 set -e
44 push_repo_setup "push-invalid-branch-required"
45
46 git lfs push origin jibberish >push.log 2>&1 && exit 1
47 grep "Invalid ref argument" push.log
48 )
49 end_test
50
51 begin_test "push with bad ref"
52 (
53 set -e
54 push_repo_setup "push-other-branch-required"
55
56 git lfs push origin main 2>&1 | tee push.log
57 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
58 echo "expected command to fail"
59 exit 1
60 fi
61
62 grep 'batch response: Expected ref "refs/heads/other", got "refs/heads/main"' push.log
63 )
64 end_test
65
66 begin_test "push with nothing"
67 (
68 set -e
69 push_repo_setup "push-nothing"
70
71 git lfs push origin 2>&1 | tee push.log
72 grep "At least one ref must be supplied without --all" push.log
73 )
74 end_test
75
76 begin_test "push with given remote, configured pushRemote"
77 (
78 set -e
79 push_repo_setup "push-given-and-config"
80
81 git remote add bad-remote "invalid-url"
82
83 git config branch.main.pushRemote bad-remote
84
85 git lfs push --all origin
86 )
87 end_test
88
89 begin_test "push via stdin with extra arguments"
90 (
91 set -e
92
93 push_repo_setup "push-stdin-extra-args"
94
95 echo "main" | git lfs push origin --stdin --dry-run "another-ref" \
96 2>&1 | tee push.log
97 grep "Further command line arguments are ignored with --stdin" push.log
98 )
99
100 begin_test "push"
101 (
102 set -e
103
104 reponame="$(basename "$0" ".sh")"
105 setup_remote_repo "$reponame"
106 clone_repo "$reponame" repo
107
108 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
109
110 git lfs track "*.dat"
111 echo "push a" > a.dat
112 git add .gitattributes a.dat
113 git commit -m "add a.dat"
114
115 git lfs push --dry-run origin main 2>&1 | tee push.log
116 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
117 [ $(grep -c "^push " push.log) -eq 1 ]
118
119 git lfs push origin main 2>&1 | tee push.log
120 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
121
122 git checkout -b push-b
123 echo "push b" > b.dat
124 git add b.dat
125 git commit -m "add b.dat"
126
127 git lfs push --dry-run origin push-b 2>&1 | tee push.log
128 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
129 grep "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
130 [ $(grep -c "^push " < push.log) -eq 2 ]
131
132 printf "push-b\n\n" | git lfs push --dry-run origin --stdin 2>&1 | tee push.log
133 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
134 grep "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
135 [ $(grep -c "^push " < push.log) -eq 2 ]
136
137 # simulate remote ref
138 mkdir -p .git/refs/remotes/origin
139 git rev-parse HEAD > .git/refs/remotes/origin/HEAD
140
141 git lfs push --dry-run origin push-b 2>&1 | tee push.log
142 [ $(grep -c "^push " push.log) -eq 0 ]
143
144 rm -rf .git/refs/remotes
145
146 git lfs push origin push-b 2>&1 | tee push.log
147 grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
148 )
149 end_test
150
151 # helper used by the next few push --all tests to set up their repos
152 push_all_setup() {
153 suffix="$1"
154 reponame="$(basename "$0" ".sh")-all-$suffix"
155 content1="initial"
156 content2="update"
157 content3="branch"
158 content4="tagged"
159 content5="main"
160 extracontent="extra"
161 oid1=$(calc_oid "$content1")
162 oid2=$(calc_oid "$content2")
163 oid3=$(calc_oid "$content3")
164 oid4=$(calc_oid "$content4")
165 oid5=$(calc_oid "$content5")
166 extraoid=$(calc_oid "$extracontent")
167
168 clone_repo "$reponame" "push-all-$suffix"
169 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
170 git lfs track "*.dat"
171
172 echo "[
173 {
174 \"CommitDate\":\"$(get_date -6m)\",
175 \"Files\":[
176 {\"Filename\":\"file1.dat\",\"Size\":${#content1},\"Data\":\"$content1\"}
177 ]
178 },
179 {
180 \"CommitDate\":\"$(get_date -5m)\",
181 \"Files\":[
182 {\"Filename\":\"file1.dat\",\"Size\":${#content2},\"Data\":\"$content2\"}
183 ]
184 },
185 {
186 \"CommitDate\":\"$(get_date -4m)\",
187 \"NewBranch\":\"branch\",
188 \"Files\":[
189 {\"Filename\":\"file1.dat\",\"Size\":${#content3},\"Data\":\"$content3\"}
190 ]
191 },
192 {
193 \"CommitDate\":\"$(get_date -4m)\",
194 \"ParentBranches\":[\"main\"],
195 \"Tags\":[\"tag\"],
196 \"Files\":[
197 {\"Filename\":\"file1.dat\",\"Size\":${#content4},\"Data\":\"$content4\"}
198 ]
199 },
200 {
201 \"CommitDate\":\"$(get_date -2m)\",
202 \"Files\":[
203 {\"Filename\":\"file1.dat\",\"Size\":${#content5},\"Data\":\"$content5\"},
204 {\"Filename\":\"file2.dat\",\"Size\":${#extracontent},\"Data\":\"$extracontent\"}
205 ]
206 }
207 ]" | lfstest-testutils addcommits
208
209 git rm file2.dat
210 git commit -m "remove file2.dat"
211
212 # simulate remote ref
213 mkdir -p .git/refs/remotes/origin
214 git rev-parse HEAD > .git/refs/remotes/origin/HEAD
215
216 setup_alternate_remote "$reponame-$suffix"
217 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix").locksverify" true
218 }
219
220 begin_test "push --all (no ref args)"
221 (
222 set -e
223
224 push_all_setup "everything"
225
226 git lfs push --dry-run --all origin 2>&1 | tee push.log
227 grep "push $oid1 => file1.dat" push.log
228 grep "push $oid2 => file1.dat" push.log
229 grep "push $oid3 => file1.dat" push.log
230 grep "push $oid4 => file1.dat" push.log
231 grep "push $oid5 => file1.dat" push.log
232 grep "push $extraoid => file2.dat" push.log
233 [ $(grep -c "^push " < push.log) -eq 6 ]
234
235 git push --all origin 2>&1 | tee push.log
236 [ $(grep -c "Uploading LFS objects: 100% (6/6)" push.log) -eq 1 ]
237 assert_server_object "$reponame-$suffix" "$oid1"
238 assert_server_object "$reponame-$suffix" "$oid2"
239 assert_server_object "$reponame-$suffix" "$oid3"
240 assert_server_object "$reponame-$suffix" "$oid4"
241 assert_server_object "$reponame-$suffix" "$oid5"
242 assert_server_object "$reponame-$suffix" "$extraoid"
243
244 echo "push while missing old objects locally"
245 setup_alternate_remote "$reponame-$suffix-2"
246 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
247
248 git lfs push --object-id origin $oid1
249 assert_server_object "$reponame-$suffix-2" "$oid1"
250 refute_server_object "$reponame-$suffix-2" "$oid2"
251 refute_server_object "$reponame-$suffix-2" "$oid3"
252 refute_server_object "$reponame-$suffix-2" "$oid4"
253 refute_server_object "$reponame-$suffix-2" "$oid5"
254 refute_server_object "$reponame-$suffix-2" "$extraoid"
255 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
256
257 echo "dry run missing local object that exists on server"
258 git lfs push --dry-run --all origin 2>&1 | tee push.log
259 grep "push $oid1 => file1.dat" push.log
260 grep "push $oid2 => file1.dat" push.log
261 grep "push $oid3 => file1.dat" push.log
262 grep "push $oid4 => file1.dat" push.log
263 grep "push $oid5 => file1.dat" push.log
264 grep "push $extraoid => file2.dat" push.log
265 [ $(grep -c "^push " push.log) -eq 6 ]
266
267 git push --all origin 2>&1 | tee push.log
268 grep "Uploading LFS objects: 100% (6/6)" push.log
269 assert_server_object "$reponame-$suffix-2" "$oid2"
270 assert_server_object "$reponame-$suffix-2" "$oid3"
271 assert_server_object "$reponame-$suffix-2" "$oid4"
272 assert_server_object "$reponame-$suffix-2" "$oid5"
273 assert_server_object "$reponame-$suffix-2" "$extraoid"
274 )
275 end_test
276
277 begin_test "push --all (1 ref arg)"
278 (
279 set -e
280
281 push_all_setup "ref"
282
283 git lfs push --dry-run --all origin branch 2>&1 | tee push.log
284 grep "push $oid1 => file1.dat" push.log
285 grep "push $oid2 => file1.dat" push.log
286 grep "push $oid3 => file1.dat" push.log
287 [ $(grep -c "^push " < push.log) -eq 3 ]
288
289 git lfs push --all origin branch 2>&1 | tee push.log
290 [ $(grep -c "Uploading LFS objects: 100% (3/3)" push.log) -eq 1 ]
291 assert_server_object "$reponame-$suffix" "$oid1"
292 assert_server_object "$reponame-$suffix" "$oid2"
293 assert_server_object "$reponame-$suffix" "$oid3"
294 refute_server_object "$reponame-$suffix" "$oid4" # in main and the tag
295 refute_server_object "$reponame-$suffix" "$oid5"
296 refute_server_object "$reponame-$suffix" "$extraoid"
297
298 echo "push while missing old objects locally"
299 setup_alternate_remote "$reponame-$suffix-2"
300 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
301 git lfs push --object-id origin $oid1
302 assert_server_object "$reponame-$suffix-2" "$oid1"
303 refute_server_object "$reponame-$suffix-2" "$oid2"
304 refute_server_object "$reponame-$suffix-2" "$oid3"
305 refute_server_object "$reponame-$suffix-2" "$oid4"
306 refute_server_object "$reponame-$suffix-2" "$oid5"
307 refute_server_object "$reponame-$suffix-2" "$extraoid"
308 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
309
310 # dry run doesn't change
311 git lfs push --dry-run --all origin branch 2>&1 | tee push.log
312 grep "push $oid1 => file1.dat" push.log
313 grep "push $oid2 => file1.dat" push.log
314 grep "push $oid3 => file1.dat" push.log
315 [ $(grep -c "^push " push.log) -eq 3 ]
316
317 git push origin branch 2>&1 | tee push.log
318 [ $(grep -c "Uploading LFS objects: 100% (3/3)" push.log) -eq 1 ]
319 assert_server_object "$reponame-$suffix-2" "$oid2"
320 assert_server_object "$reponame-$suffix-2" "$oid3"
321 refute_server_object "$reponame-$suffix-2" "$oid4"
322 refute_server_object "$reponame-$suffix-2" "$oid5"
323 refute_server_object "$reponame-$suffix-2" "$extraoid"
324 )
325 end_test
326
327 begin_test "push --all (multiple ref args)"
328 (
329 set -e
330
331 push_all_setup "multiple-refs"
332
333 git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
334 grep "push $oid1 => file1.dat" push.log
335 grep "push $oid2 => file1.dat" push.log
336 grep "push $oid3 => file1.dat" push.log
337 grep "push $oid4 => file1.dat" push.log
338 [ $(grep -c "^push " push.log) -eq 4 ]
339
340 printf "branch\ntag" | git lfs push --dry-run --all origin --stdin 2>&1 | tee push.log
341 grep "push $oid1 => file1.dat" push.log
342 grep "push $oid2 => file1.dat" push.log
343 grep "push $oid3 => file1.dat" push.log
344 grep "push $oid4 => file1.dat" push.log
345 [ $(grep -c "^push " push.log) -eq 4 ]
346
347 git lfs push --all origin branch tag 2>&1 | tee push.log
348 [ $(grep -c "Uploading LFS objects: 100% (4/4)" push.log) -eq 1 ]
349 assert_server_object "$reponame-$suffix" "$oid1"
350 assert_server_object "$reponame-$suffix" "$oid2"
351 assert_server_object "$reponame-$suffix" "$oid3"
352 assert_server_object "$reponame-$suffix" "$oid4"
353 refute_server_object "$reponame-$suffix" "$oid5" # only in main
354 refute_server_object "$reponame-$suffix" "$extraoid"
355
356 echo "push while missing old objects locally"
357 setup_alternate_remote "$reponame-$suffix-2"
358 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
359 git lfs push --object-id origin $oid1
360 assert_server_object "$reponame-$suffix-2" "$oid1"
361 refute_server_object "$reponame-$suffix-2" "$oid2"
362 refute_server_object "$reponame-$suffix-2" "$oid3"
363 refute_server_object "$reponame-$suffix-2" "$oid4"
364 refute_server_object "$reponame-$suffix-2" "$oid5"
365 refute_server_object "$reponame-$suffix-2" "$extraoid"
366 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
367
368 # dry run doesn't change
369 git lfs push --dry-run --all origin branch tag 2>&1 | tee push.log
370 grep "push $oid1 => file1.dat" push.log
371 grep "push $oid2 => file1.dat" push.log
372 grep "push $oid3 => file1.dat" push.log
373 grep "push $oid4 => file1.dat" push.log
374 [ $(grep -c "^push " push.log) -eq 4 ]
375
376 git push origin branch refs/tags/tag 2>&1 | tee push.log
377 [ $(grep -c "Uploading LFS objects: 100% (4/4)" push.log) -eq 1 ]
378 assert_server_object "$reponame-$suffix-2" "$oid2"
379 assert_server_object "$reponame-$suffix-2" "$oid3"
380 assert_server_object "$reponame-$suffix-2" "$oid4"
381 refute_server_object "$reponame-$suffix-2" "$oid5"
382 refute_server_object "$reponame-$suffix-2" "$extraoid"
383 )
384 end_test
385
386 begin_test "push --all (ref with deleted files)"
387 (
388 set -e
389
390 push_all_setup "ref-with-deleted"
391
392 git lfs push --dry-run --all origin main 2>&1 | tee push.log
393 grep "push $oid1 => file1.dat" push.log
394 grep "push $oid2 => file1.dat" push.log
395 grep "push $oid4 => file1.dat" push.log
396 grep "push $oid5 => file1.dat" push.log
397 grep "push $extraoid => file2.dat" push.log
398 [ $(grep -c "^push " push.log) -eq 5 ]
399
400 git lfs push --all origin main 2>&1 | tee push.log
401 [ $(grep -c "Uploading LFS objects: 100% (5/5)" push.log) -eq 1 ]
402 assert_server_object "$reponame-$suffix" "$oid1"
403 assert_server_object "$reponame-$suffix" "$oid2"
404 refute_server_object "$reponame-$suffix" "$oid3" # only in the branch
405 assert_server_object "$reponame-$suffix" "$oid4"
406 assert_server_object "$reponame-$suffix" "$oid5"
407 assert_server_object "$reponame-$suffix" "$extraoid"
408
409 echo "push while missing old objects locally"
410 setup_alternate_remote "$reponame-$suffix-2"
411 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
412 git lfs push --object-id origin $oid1
413 assert_server_object "$reponame-$suffix-2" "$oid1"
414 refute_server_object "$reponame-$suffix-2" "$oid2"
415 refute_server_object "$reponame-$suffix-2" "$oid3"
416 refute_server_object "$reponame-$suffix-2" "$oid4"
417 refute_server_object "$reponame-$suffix-2" "$oid5"
418 refute_server_object "$reponame-$suffix-2" "$extraoid"
419 rm ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
420
421 # dry run doesn't change
422 git lfs push --dry-run --all origin main 2>&1 | tee push.log
423 grep "push $oid1 => file1.dat" push.log
424 grep "push $oid2 => file1.dat" push.log
425 grep "push $oid4 => file1.dat" push.log
426 grep "push $oid5 => file1.dat" push.log
427 grep "push $extraoid => file2.dat" push.log
428 [ $(grep -c "^push " push.log) -eq 5 ]
429
430 git push origin main 2>&1 | tee push.log
431 [ $(grep -c "Uploading LFS objects: 100% (5/5)" push.log) -eq 1 ]
432 assert_server_object "$reponame-$suffix-2" "$oid2"
433 refute_server_object "$reponame-$suffix-2" "$oid3"
434 assert_server_object "$reponame-$suffix-2" "$oid4"
435 assert_server_object "$reponame-$suffix-2" "$oid5"
436 assert_server_object "$reponame-$suffix-2" "$extraoid"
437 )
438 end_test
439
440 begin_test "push object id(s)"
441 (
442 set -e
443
444 reponame="$(basename "$0" ".sh")"
445 setup_remote_repo "$reponame"
446 clone_repo "$reponame" repo2
447
448 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
449
450 git lfs track "*.dat"
451 echo "push a" > a.dat
452 git add .gitattributes a.dat
453 git commit -m "add a.dat"
454
455 git lfs push --object-id origin --dry-run 2>&1 | tee push.log
456 grep "At least one object ID must be supplied with --object-id" push.log
457
458 git lfs push --object-id origin \
459 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
460 2>&1 | tee push.log
461 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
462
463 echo "push b" > b.dat
464 git add b.dat
465 git commit -m "add b.dat"
466
467 git lfs push --object-id origin \
468 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
469 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 \
470 2>&1 | tee push.log
471 grep "Uploading LFS objects: 100% (2/2), 14 B" push.log
472 )
473 end_test
474
475 begin_test "push object id(s) via stdin"
476 (
477 set -e
478
479 reponame="$(basename "$0" ".sh")"
480 setup_remote_repo "$reponame"
481 clone_repo "$reponame" repo3
482
483 git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
484
485 git lfs track "*.dat"
486 echo "push a" > a.dat
487 git add .gitattributes a.dat
488 git commit -m "add a.dat"
489
490 git lfs push --object-id origin --stdin --dry-run </dev/null 2>&1 | tee push.log
491 grep "At least one object ID must be supplied with --object-id" push.log && exit 1
492
493 echo "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340" | \
494 git lfs push --object-id origin --stdin --dry-run "c0ffee" \
495 2>&1 | tee push.log
496 grep "Further command line arguments are ignored with --stdin" push.log
497
498 echo "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340" | \
499 git lfs push --object-id origin --stdin --dry-run \
500 2>&1 | tee push.log
501 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 =>" push.log
502
503 echo "push b" > b.dat
504 git add b.dat
505 git commit -m "add b.dat"
506
507 printf "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340\n82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7\n\n" | \
508 git lfs push --object-id origin --stdin --dry-run \
509 2>&1 | tee push.log
510 grep "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 =>" push.log
511 grep "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 =>" push.log
512 )
513 end_test
514
515 begin_test "push modified files"
516 (
517 set -e
518
519 reponame="$(basename "$0" ".sh")-modified"
520 setup_remote_repo "$reponame"
521 clone_repo "$reponame" "$reponame"
522
523 git lfs track "*.dat"
524 # generate content we'll use
525 content1="filecontent1"
526 content2="filecontent2"
527 content3="filecontent3"
528 content4="filecontent4"
529 content5="filecontent5"
530 oid1=$(calc_oid "$content1")
531 oid2=$(calc_oid "$content2")
532 oid3=$(calc_oid "$content3")
533 oid4=$(calc_oid "$content4")
534 oid5=$(calc_oid "$content5")
535
536 echo "[
537 {
538 \"CommitDate\":\"$(get_date -6m)\",
539 \"Files\":[
540 {\"Filename\":\"file1.dat\",\"Size\":${#content1}, \"Data\":\"$content1\"}]
541 },
542 {
543 \"CommitDate\":\"$(get_date -3m)\",
544 \"Files\":[
545 {\"Filename\":\"file1.dat\",\"Size\":${#content2}, \"Data\":\"$content2\"}]
546 },
547 {
548 \"CommitDate\":\"$(get_date -1m)\",
549 \"NewBranch\":\"other_branch\",
550 \"Files\":[
551 {\"Filename\":\"file1.dat\",\"Size\":${#content5}, \"Data\":\"$content5\"}]
552 },
553 {
554 \"CommitDate\":\"$(get_date -1m)\",
555 \"ParentBranches\":[\"main\"],
556 \"Files\":[
557 {\"Filename\":\"file1.dat\",\"Size\":${#content3}, \"Data\":\"$content3\"},
558 {\"Filename\":\"file2.dat\",\"Size\":${#content4}, \"Data\":\"$content4\"}]
559 }
560 ]" | lfstest-testutils addcommits
561
562 git lfs push origin main
563 git lfs push origin other_branch
564 assert_server_object "$reponame" "$oid1"
565 assert_server_object "$reponame" "$oid2"
566 assert_server_object "$reponame" "$oid3"
567 assert_server_object "$reponame" "$oid4"
568 assert_server_object "$reponame" "$oid5"
569 )
570 end_test
571
572 begin_test "push with invalid remote"
573 (
574 set -e
575 cd repo
576 git lfs push not-a-remote 2>&1 | tee push.log
577 grep "Invalid remote name" push.log
578 )
579 end_test
580
581 begin_test "push ambiguous branch name"
582 (
583 set -e
584
585 reponame="$(basename "$0" ".sh")-ambiguous-branch"
586 setup_remote_repo "$reponame"
587 clone_repo "$reponame" "$reponame"
588
589
590 git lfs track "*.dat" 2>&1 | tee track.log
591 grep "Tracking \"\*.dat\"" track.log
592
593 NUMFILES=5
594 # generate content we'll use
595 for ((a=0; a < NUMFILES ; a++))
596 do
597 content[$a]="filecontent$a"
598 oid[$a]=$(calc_oid "${content[$a]}")
599 done
600
601 echo "[
602 {
603 \"CommitDate\":\"$(get_date -10d)\",
604 \"Files\":[
605 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
606 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
607 },
608 {
609 \"NewBranch\":\"ambiguous\",
610 \"CommitDate\":\"$(get_date -5d)\",
611 \"Files\":[
612 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
613 },
614 {
615 \"CommitDate\":\"$(get_date -2d)\",
616 \"Files\":[
617 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
618 },
619 {
620 \"ParentBranches\":[\"main\"],
621 \"CommitDate\":\"$(get_date -1d)\",
622 \"Files\":[
623 {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
624 }
625 ]" | lfstest-testutils addcommits
626
627 # create tag with same name as branch
628 git tag ambiguous
629
630 # lfs push main, should work
631 git lfs push origin main
632
633 # push ambiguous, does not fail since lfs scans git with sha, not ref name
634 git lfs push origin ambiguous
635 )
636 end_test
637
638 begin_test "push (retry with expired actions)"
639 (
640 set -e
641
642 reponame="push_retry_expired_action"
643 setup_remote_repo "$reponame"
644 clone_repo "$reponame" "$reponame"
645
646 git lfs track "*.dat"
647 contents="return-expired-action"
648 contents_oid="$(calc_oid "$contents")"
649 contents_size="$(printf "%s" "$contents" | wc -c | awk '{ print $1 }')"
650 printf "%s" "$contents" > a.dat
651 git add .gitattributes a.dat
652
653 git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
654 grep "main (root-commit)" commit.log
655 grep "2 files changed" commit.log
656 grep "create mode 100644 a.dat" commit.log
657 grep "create mode 100644 .gitattributes" commit.log
658
659 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
660
661 expected="enqueue retry #1 after 0.25s for \"$contents_oid\" (size: $contents_size): LFS: action \"upload\" expires at"
662
663 grep "$expected" push.log
664 grep "Uploading LFS objects: 100% (1/1), 21 B" push.log
665 )
666 end_test
667
668 begin_test "push to raw remote url"
669 (
670 set -e
671
672 setup_remote_repo "push-raw"
673 mkdir push-raw
674 cd push-raw
675 git init
676
677 git lfs track "*.dat"
678
679 contents="raw"
680 contents_oid=$(calc_oid "$contents")
681
682 printf "%s" "$contents" > raw.dat
683 git add raw.dat .gitattributes
684 git commit -m "add" 2>&1 | tee commit.log
685 grep "main (root-commit)" commit.log
686 grep "2 files changed" commit.log
687 grep "create mode 100644 raw.dat" commit.log
688 grep "create mode 100644 .gitattributes" commit.log
689
690 refute_server_object push-raw "$contents_oid"
691
692 git lfs push $GITSERVER/push-raw main
693
694 assert_server_object push-raw "$contents_oid"
695 )
696 end_test
697
698 begin_test "push (with invalid object size)"
699 (
700 set -e
701
702 reponame="push-invalid-object-size"
703 setup_remote_repo "$reponame"
704 clone_repo "$reponame" "$reponame"
705
706 git lfs track "*.dat"
707 contents="return-invalid-size"
708 printf "%s" "$contents" > a.dat
709
710 git add a.dat .gitattributes
711 git commit -m "add a.dat, .gitattributes" 2>&1 | tee commit.log
712 grep "main (root-commit)" commit.log
713 grep "2 files changed" commit.log
714 grep "create mode 100644 a.dat" commit.log
715 grep "create mode 100644 .gitattributes" commit.log
716
717 set +e
718 git push origin main 2>&1 2> push.log
719 res="$?"
720 set -e
721
722 grep "invalid size (got: -1)" push.log
723 [ "0" -eq "$(grep -c "panic" push.log)" ]
724 [ "0" -ne "$res" ]
725
726 refute_server_object "$reponame" "$(calc_oid "$contents")"
727 )
728 end_test
729
730 begin_test "push with deprecated _links"
731 (
732 set -e
733
734 reponame="$(basename "$0" ".sh")-deprecated"
735 setup_remote_repo "$reponame"
736 clone_repo "$reponame" "$reponame"
737
738 git lfs track "*.dat"
739 git add .gitattributes
740 git commit -m "initial commit"
741
742 contents="send-deprecated-links"
743 contents_oid="$(calc_oid "$contents")"
744 printf "%s" "$contents" > a.dat
745 git add a.dat
746 git commit -m "add a.dat"
747
748 git push origin main
749
750 assert_server_object "$reponame" "$contents_oid"
751 )
752 end_test
753
754 begin_test "push with invalid pushInsteadof"
755 (
756 set -e
757
758 push_repo_setup "push-invalid-pushinsteadof"
759
760 # set pushInsteadOf to rewrite the href of uploading LFS object.
761 git config url."$GITSERVER/storage/invalid".pushInsteadOf "$GITSERVER/storage/"
762 # Enable href rewriting explicitly.
763 git config lfs.transfer.enablehrefrewrite true
764
765 set +e
766 git lfs push origin main > push.log 2>&1
767 res=$?
768
769 set -e
770 [ "$res" = "2" ]
771
772 # check rewritten href is used to upload LFS object.
773 grep "LFS: Authorization error: $GITSERVER/storage/invalid" push.log
774
775 # lfs-push succeed after unsetting enableHrefRewrite config
776 git config --unset lfs.transfer.enablehrefrewrite
777 git lfs push origin main
778 )
779 end_test
780
781 begin_test 'push with data the server already has'
782 (
783 set -e
784
785 reponame="push-server-data"
786 setup_remote_repo "$reponame"
787 clone_repo "$reponame" "$reponame"
788
789 git lfs track "*.dat"
790 git add .gitattributes
791 git commit -m "initial commit"
792
793 contents="abc123"
794 contents_oid="$(calc_oid "$contents")"
795 printf "%s" "$contents" > a.dat
796 git add a.dat
797 git commit -m "add a.dat"
798
799 git push origin main
800
801 assert_server_object "$reponame" "$contents_oid"
802
803 git checkout -b side
804
805 # Use a different file name for the second file; otherwise, this test
806 # unexpectedly passes with the old code, since we fail to notice that the
807 # object we run through the clean filter is not the object we wanted.
808 contents2="def456"
809 contents2_oid="$(calc_oid "$contents2")"
810 printf "%s" "$contents2" > b.dat
811 git add b.dat
812 git commit -m "add b.dat"
813
814 # We remove the original object. The server already has this.
815 delete_local_object "$contents_oid"
816
817 # We use the URL so that we cannot take advantage of the existing "origin/*"
818 # refs that we know the server must have. We will traverse the entire history
819 # for this push, and we should not fail because the server already has the
820 # object we deleted above.
821 git push "$(git config remote.origin.url)" side
822
823 assert_server_object "$reponame" "$contents2_oid"
824 )
825 end_test
826
827 begin_test 'push with multiple refs and data the server already has'
828 (
829 set -e
830
831 reponame="push-multi-ref-server-data"
832 setup_remote_repo "$reponame"
833 clone_repo "$reponame" "$reponame"
834
835 git lfs track "*.dat"
836 git add .gitattributes
837 git commit -m "initial commit"
838
839 contents="abc123"
840 contents_oid="$(calc_oid "$contents")"
841 printf "%s" "$contents" > a.dat
842 git add a.dat
843 git commit -m "add a.dat"
844
845 git push origin main
846
847 assert_server_object "$reponame" "$contents_oid"
848
849 contents2="def456"
850 contents2_oid="$(calc_oid "$contents2")"
851 printf "%s" "$contents2" > b.dat
852 git add b.dat
853 git commit -m "add b.dat"
854
855 # Create a tag. Normally this would cause the entire history to be traversed
856 # since it's a new ref, but we no longer do that since we're pushing multiple
857 # refs.
858 git tag -m v1.0.0 -a v1.0.0
859
860 # We remove the original object. The server already has this.
861 delete_local_object "$contents_oid"
862
863 # We use the URL so that we cannot take advantage of the existing "origin/*"
864 # refs that we know the server must have.
865 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 \
866 git push "$(git config remote.origin.url)" main v1.0.0 2>&1 | tee push.log
867
868 # We should not find a batch request for the object which is in the earlier
869 # version of main, since we know the remote side has it.
870 [ 0 -eq "$(grep -c "$contents_oid" push.log)" ]
871
872 # Yet we should have pushed the new object successfully.
873 assert_server_object "$reponame" "$contents2_oid"
874 )
875 end_test
876
877 begin_test 'push with multiple tag refs'
878 (
879 set -e
880
881 reponame="push-multi-ref-tags"
882 setup_remote_repo "$reponame"
883 clone_repo "$reponame" "$reponame"
884
885 git lfs track "*.dat"
886 git add .gitattributes
887 git commit -m "initial commit"
888
889 contents="abc123"
890 contents_oid="$(calc_oid "$contents")"
891 printf "%s" "$contents" > a.dat
892 git add a.dat
893 git commit -m "add a.dat"
894
895 git tag v1.0.0
896
897 git push origin main v1.0.0
898
899 assert_server_object "$reponame" "$contents_oid"
900
901 contents2="def456"
902 contents2_oid="$(calc_oid "$contents2")"
903 printf "%s" "$contents2" > b.dat
904 git add b.dat
905 git commit -m "add b.dat"
906
907 git tag v1.0.1
908
909 git lfs push origin v1.0.1
910
911 assert_server_object "$reponame" "$contents2_oid"
912 )
913 end_test
914
915 begin_test "push custom reference"
916 (
917 set -e
918
919 reponame="push-custom-reference"
920 setup_remote_repo "$reponame"
921 clone_repo "$reponame" "$reponame"
922
923 git lfs track "*.dat"
924 # generate content we'll use
925 content="filecontent"
926 oid=$(calc_oid "$content")
927
928 echo "[
929 {
930 \"CommitDate\":\"$(get_date -6m)\",
931 \"Files\":[
932 {\"Filename\":\"file.dat\",\"Size\":${#content}, \"Data\":\"$content\"}]
933 }
934 ]" | lfstest-testutils addcommits
935
936 # Create and try pushing a reference in a nonstandard namespace, that is,
937 # outside of refs/heads, refs/tags, and refs/remotes.
938 git update-ref refs/custom/remote/heads/main refs/heads/main
939
940 git lfs push origin refs/custom/remote/heads/main
941 assert_server_object "$reponame" "$oid"
942 )
943 end_test
944
945 begin_test "push --object-id (invalid value)"
946 (
947 set -e
948
949 push_all_setup "push-invalid-oid"
950
951 git lfs push --object-id origin '' 2>&1 | tee push.log
952 git lfs push --object-id origin "${oid1:0:3}" 2>&1 | tee -a push.log
953
954 [ "$(grep -c 'too short object ID' push.log)" -eq 2 ]
955 )
956 end_test