Debian Codegraph @

t/t-pre-push.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "pre-push with good ref"
6 (
7 set -e
8 reponame="pre-push-main-branch-required"
9 setup_remote_repo "$reponame"
10 clone_repo "$reponame" "$reponame"
11
12 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
13 gitscip-shell system . . git. lfs track "*.dat"
14 echoscip-shell system . . echo. "hi" > a.dat
15 gitscip-shell system . . git. add .gitattributes a.dat
16 gitscip-shell system . . git. commit -m "add a.dat"
17
18 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
19
20 # for some reason, using 'tee' and $PIPESTATUS does not work here
21 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
22 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 > push.log
23
24 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
25 )
26 end_test
27
28 begin_test "pre-push with tracked ref"
29 (
30 set -e
31 reponame="pre-push-tracked-branch-required"
32 setup_remote_repo "$reponame"
33 clone_repo "$reponame" "$reponame"
34
35 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
36 gitscip-shell system . . git. lfs track "*.dat"
37 echoscip-shell system . . echo. "hi" > a.dat
38 gitscip-shell system . . git. add .gitattributes a.dat
39 gitscip-shell system . . git. commit -m "add a.dat"
40
41 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
42
43 # for some reason, using 'tee' and $PIPESTATUS does not work here
44 echoscip-shell system . . echo. "refs/heads/main main refs/heads/tracked 0000000000000000000000000000000000000000" |
45 gitscip-shell system . . git. lfs pre-push origin main 2>&1 > push.log
46
47 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
48 )
49 end_test
50
51 begin_test "pre-push with bad ref"
52 (
53 set -e
54 reponame="pre-push-other-branch-required"
55 setup_remote_repo "$reponame"
56 clone_repo "$reponame" "$reponame"
57
58 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
59 gitscip-shell system . . git. lfs track "*.dat"
60 echoscip-shell system . . echo. "hi" > a.dat
61 gitscip-shell system . . git. add .gitattributes a.dat
62 gitscip-shell system . . git. commit -m "add a.dat"
63
64 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
65
66 # for some reason, using 'tee' and $PIPESTATUS does not work here
67 set +e
68 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
69 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2> push.log
70 pushcode=$?
71 set -e
72
73 if [scip-shell system . . `[`. "0" -eq "$pushcode" ]; then
74 echoscip-shell system . . echo. "expected command to fail"
75 exit 1
76 fi
77
78 grepscip-shell system . . grep. 'Expected ref "refs/heads/other", got "refs/heads/main"' push.log
79
80 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
81 )
82 end_test
83
84 begin_test "pre-push"
85 (
86 set -e
87
88 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
89 setup_remote_repo "$reponame"
90
91 clone_repo "$reponame" repo
92 gitscip-shell system . . git. lfs track "*.dat"
93 gitscip-shell system . . git. add .gitattributes
94 gitscip-shell system . . git. commit -m "add git attributes"
95
96 gitscip-shell system . . git. config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
97
98 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
99 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" |
100 teescip-shell system . . tee. push.log
101 # no output if nothing to do
102 [scip-shell system . . `[`. "$(duscip-shell system . . du. -k push.log | cutscip-shell system . . cut. -f 1)" == "0" ]
103
104 gitscip-shell system . . git. lfs track "*.dat"
105 echoscip-shell system . . echo. "hi" > hi.dat
106 gitscip-shell system . . git. add hi.dat
107 gitscip-shell system . . git. commit -m "add hi.dat"
108 gitscip-shell system . . git. show
109
110 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
111
112 # push file to the git lfs server
113 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
114 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
115 teescip-shell system . . tee. push.log
116 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 3 B" push.log
117
118 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
119 )
120 end_test
121
122 begin_test "pre-push dry-run"
123 (
124 set -e
125
126 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-dry-run"
127 setup_remote_repo "$reponame"
128
129 clone_repo "$reponame" repo-dry-run
130 gitscip-shell system . . git. lfs track "*.dat"
131 gitscip-shell system . . git. add .gitattributes
132 gitscip-shell system . . git. commit -m "add git attributes"
133
134 gitscip-shell system . . git. config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
135
136 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
137 gitscip-shell system . . git. lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
138 teescip-shell system . . tee. push.log
139
140 [scip-shell system . . `[`. "" = "$(catscip-shell system . . cat. push.log)" ]
141
142 gitscip-shell system . . git. lfs track "*.dat"
143 echoscip-shell system . . echo. "dry" > hi.dat
144 gitscip-shell system . . git. add hi.dat
145 gitscip-shell system . . git. commit -m "add hi.dat"
146 gitscip-shell system . . git. show
147
148 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
149
150 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
151 gitscip-shell system . . git. lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
152 teescip-shell system . . tee. push.log
153 grepscip-shell system . . grep. "push 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b => hi.dat" push.log
154 catscip-shell system . . cat. push.log
155 [scip-shell system . . `[`. `wcscip-shell system . . wc. -l < push.log` = 1 ]
156
157 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
158 )
159 end_test
160
161 begin_test "pre-push skip-push"
162 (
163 set -e
164
165 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-skip-push"
166 setup_remote_repo "$reponame"
167
168 clone_repo "$reponame" repo-skip-push
169 gitscip-shell system . . git. lfs track "*.dat"
170 gitscip-shell system . . git. add .gitattributes
171 gitscip-shell system . . git. commit -m "add git attributes"
172
173 gitscip-shell system . . git. config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
174
175 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
176 GIT_LFS_SKIP_PUSH=true gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" |
177 teescip-shell system . . tee. push.log
178
179 [scip-shell system . . `[`. "" = "$(catscip-shell system . . cat. push.log)" ]
180
181 gitscip-shell system . . git. lfs track "*.dat"
182 echoscip-shell system . . echo. "dry" > hi.dat
183 gitscip-shell system . . git. add hi.dat
184 gitscip-shell system . . git. commit -m "add hi.dat"
185 gitscip-shell system . . git. show
186
187 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
188
189 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
190 GIT_LFS_SKIP_PUSH=true gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" |
191 teescip-shell system . . tee. push.log
192
193 [scip-shell system . . `[`. "" = "$(catscip-shell system . . cat. push.log)" ]
194
195 refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
196 )
197 end_test
198
199 begin_test "pre-push 307 redirects"
200 (
201 set -e
202
203 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
204 setup_remote_repo "$reponame"
205
206 clone_repo "$reponame" repo-307
207 gitscip-shell system . . git. lfs track "*.dat"
208 gitscip-shell system . . git. add .gitattributes
209 gitscip-shell system . . git. commit -m "add git attributes"
210
211 # relative redirect
212 gitscip-shell system . . git. config remote.origin.lfsurl "$GITSERVER/redirect307/rel/$reponame.git/info/lfs"
213
214 gitscip-shell system . . git. lfs track "*.dat"
215 echoscip-shell system . . echo. "hi" > hi.dat
216 gitscip-shell system . . git. add hi.dat
217 gitscip-shell system . . git. commit -m "add hi.dat"
218 gitscip-shell system . . git. show
219
220 # push file to the git lfs server
221 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
222 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" 2>&1 |
223 teescip-shell system . . tee. push.log
224 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 3 B" push.log
225
226 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
227
228 # absolute redirect
229 gitscip-shell system . . git. config remote.origin.lfsurl "$GITSERVER/redirect307/abs/$reponame.git/info/lfs"
230
231 echoscip-shell system . . echo. "hi" > hi2.dat
232 gitscip-shell system . . git. add hi2.dat
233 gitscip-shell system . . git. commit -m "add hi2.dat"
234 gitscip-shell system . . git. show
235
236 # push file to the git lfs server
237 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
238 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" 2>&1 |
239 teescip-shell system . . tee. push.log
240 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 3 B" push.log
241 )
242 end_test
243
244 begin_test "pre-push with existing object"
245 (
246 set -e
247
248 reponame="pre-push-existing-object"
249 setup_remote_repo "$reponame"
250 clone_repo "$reponame" "$reponame"
251
252 echoscip-shell system . . echo. "existing" > existing.dat
253 gitscip-shell system . . git. add existing.dat
254 gitscip-shell system . . git. commit -m "add existing dat"
255
256 gitscip-shell system . . git. lfs track "*.dat"
257 echoscip-shell system . . echo. "new" > new.dat
258 gitscip-shell system . . git. add new.dat
259 gitscip-shell system . . git. add .gitattributes
260 gitscip-shell system . . git. commit -m "add new file through git lfs"
261
262 # push file to the git lfs server
263 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
264 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
265 teescip-shell system . . tee. push.log
266 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 4 B" push.log
267
268 # now the file exists
269 assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
270 )
271 end_test
272
273 begin_test "pre-push with existing object (untracked)"
274 (
275 set -e
276
277 reponame="pre-push-existing-object-untracked"
278 setup_remote_repo "$reponame"
279 clone_repo "$reponame" "$reponame"
280
281 echoscip-shell system . . echo. "$(pointer "7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" 4)" > new.dat
282 gitscip-shell system . . git. add new.dat
283 gitscip-shell system . . git. commit -m "add new pointer"
284 mkdirscip-shell system . . mkdir. -p .git/lfs/objects/7a/a7
285 echoscip-shell system . . echo. "new" > .git/lfs/objects/7a/a7/7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
286
287 # push file to the git lfs server
288 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
289 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
290 teescip-shell system . . tee. push.log
291 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 4 B" push.log
292
293 # now the file exists
294 assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
295 )
296 end_test
297
298 begin_test "pre-push reject missing object"
299 (
300 set -e
301
302 reponame="pre-push-reject-missing-object"
303 setup_remote_repo "$reponame"
304 clone_repo "$reponame" "$reponame"
305
306 oid="7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c"
307
308 echoscip-shell system . . echo. "$(pointer "$oid" 4)" > new.dat
309 gitscip-shell system . . git. add new.dat
310 gitscip-shell system . . git. commit -m "add new pointer"
311
312 # assert that push fails
313 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
314 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
315 teescip-shell system . . tee. push.log
316
317 if [scip-shell system . . `[`. "2" -ne "${PIPESTATUS[1]}" ]; then
318 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to fail ..."
319 exit 1
320 fi
321
322 grepscip-shell system . . grep. "LFS upload failed:" push.log
323 grepscip-shell system . . grep. " (missing) new.dat ($oid)" push.log
324
325 refute_server_object "$reponame" "$oid"
326 )
327 end_test
328
329 begin_test "pre-push allow missing object (found on server)"
330 (
331 # should permit push if files missing locally but are on server, shouldn't
332 # require client to have every file (prune)
333 set -e
334
335 reponame="pre-push-allow-missing-object-found-on-server"
336 setup_remote_repo "$reponame"
337 clone_repo "$reponame" "$reponame"
338
339 contents="common data"
340 contents_oid=$(calc_oid "$contents")
341 gitscip-shell system . . git. lfs track "*.dat"
342 printfscip-shell system . . printf. "%s" "$contents" > common1.dat
343 gitscip-shell system . . git. add common1.dat
344 gitscip-shell system . . git. add .gitattributes
345 gitscip-shell system . . git. commit -m "add first file"
346
347 # push file to the git lfs server
348 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
349 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
350 teescip-shell system . . tee. push.log
351 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 11 B" push.log
352
353 # now the file exists
354 assert_server_object "$reponame" "$contents_oid"
355
356 # create another commit referencing same oid, then delete local data & push
357 printfscip-shell system . . printf. "%s" "$contents" > common2.dat
358 gitscip-shell system . . git. add common2.dat
359 gitscip-shell system . . git. commit -m "add second file, same content"
360 rmscip-shell system . . rm. -rf .git/lfs/objects
361 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
362 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
363 teescip-shell system . . tee. push.log
364
365 # make sure there were no errors reported
366 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c -i 'Error' push.log)" ]
367 )
368 end_test
369
370 begin_test "pre-push allow missing object (lfs.allowincompletepush true)"
371 (
372 set -e
373
374 reponame="pre-push-allow-missing-object"
375 setup_remote_repo "$reponame"
376 clone_repo "$reponame" "$reponame"
377
378 gitscip-shell system . . git. lfs track "*.dat"
379 gitscip-shell system . . git. add .gitattributes
380 gitscip-shell system . . git. commit -m "initial commit"
381
382 present="present"
383 present_oid="$(calc_oid "$present")"
384 printfscip-shell system . . printf. "%s" "$present" > present.dat
385
386 missing="missing"
387 missing_oid="$(calc_oid "$missing")"
388 printfscip-shell system . . printf. "%s" "$missing" > missing.dat
389
390 gitscip-shell system . . git. add present.dat missing.dat
391 gitscip-shell system . . git. commit -m "add objects"
392
393 delete_local_object "$missing_oid"
394
395 gitscip-shell system . . git. config lfs.allowincompletepush true
396
397 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
398 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
399 teescip-shell system . . tee. push.log
400
401 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[1]}" ]; then
402 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to succeed ..."
403 exit 1
404 fi
405
406 grepscip-shell system . . grep. "LFS upload missing objects" push.log
407 grepscip-shell system . . grep. " (missing) missing.dat ($missing_oid)" push.log
408
409 assert_server_object "$reponame" "$present_oid"
410 refute_server_object "$reponame" "$missing_oid"
411 )
412 end_test
413
414 begin_test "pre-push reject missing object (lfs.allowincompletepush default)"
415 (
416 set -e
417
418 reponame="pre-push-reject-missing-object-default"
419 setup_remote_repo "$reponame"
420 clone_repo "$reponame" "$reponame"
421
422 gitscip-shell system . . git. lfs track "*.dat"
423 gitscip-shell system . . git. add .gitattributes
424 gitscip-shell system . . git. commit -m "initial commit"
425
426 present="present"
427 present_oid="$(calc_oid "$present")"
428 printfscip-shell system . . printf. "%s" "$present" > present.dat
429
430 missing="missing"
431 missing_oid="$(calc_oid "$missing")"
432 printfscip-shell system . . printf. "%s" "$missing" > missing.dat
433
434 gitscip-shell system . . git. add present.dat missing.dat
435 gitscip-shell system . . git. commit -m "add objects"
436
437 delete_local_object "$missing_oid"
438
439 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
440 GIT_TRACE=1 gitscip-shell system . . git. lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
441 teescip-shell system . . tee. push.log
442
443 if [scip-shell system . . `[`. "2" -ne "${PIPESTATUS[1]}" ]; then
444 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs pre-push origin $GITSERVER/$reponame' to fail ..."
445 exit 1
446 fi
447
448 grepscip-shell system . . grep. "tq: stopping batched queue, object \"$missing_oid\" missing locally and on remote" push.log
449 grepscip-shell system . . grep. "LFS upload failed:" push.log
450 grepscip-shell system . . grep. " (missing) missing.dat ($missing_oid)" push.log
451
452 refute_server_object "$reponame" "$present_oid"
453 refute_server_object "$reponame" "$missing_oid"
454 )
455 end_test
456
457 begin_test "pre-push multiple branches"
458 (
459 set -e
460
461 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-multiple-branches"
462 setup_remote_repo "$reponame"
463 clone_repo "$reponame" "$reponame"
464
465
466 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
467 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
468
469 NUMFILES=6
470 # generate content we'll use
471 for ((a=0; a < NUMFILES ; a++))
472 do
473 content[$a]="filecontent$a"
474 oid[$a]=$(calc_oid "${content[$a]}")
475 done
476
477 echoscip-shell system . . echo. "[
478 {
479 \"CommitDate\":\"$(get_date -10d)\",
480 \"Files\":[
481 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
482 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
483 },
484 {
485 \"NewBranch\":\"branch1\",
486 \"CommitDate\":\"$(get_date -5d)\",
487 \"Files\":[
488 {\"Filename\":\"file2.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
489 },
490 {
491 \"ParentBranches\":[\"main\"],
492 \"NewBranch\":\"branch2\",
493 \"CommitDate\":\"$(get_date -5d)\",
494 \"Files\":[
495 {\"Filename\":\"file3.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
496 },
497 {
498 \"ParentBranches\":[\"main\"],
499 \"NewBranch\":\"branch3\",
500 \"CommitDate\":\"$(get_date -2d)\",
501 \"Files\":[
502 {\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
503 },
504 {
505 \"ParentBranches\":[\"main\"],
506 \"NewBranch\":\"branch4\",
507 \"CommitDate\":\"$(get_date -1d)\",
508 \"Files\":[
509 {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
510 }
511 ]" | lfstest-testutils addcommits
512
513 # make sure when called via git push all branches are updated
514 gitscip-shell system . . git. push origin main branch1 branch2 branch3 branch4
515 for ((a=0; a < NUMFILES ; a++))
516 do
517 assert_server_object "$reponame" "${oid[$a]}"
518 done
519
520 )
521 end_test
522
523 begin_test "pre-push with bad remote"
524 (
525 set -e
526
527 cd repo
528
529 echoscip-shell system . . echo. "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
530 gitscip-shell system . . git. lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 |
531 teescip-shell system . . tee. pre-push.log
532 grepscip-shell system . . grep. "Invalid remote name" pre-push.log
533 )
534 end_test
535
536 begin_test "pre-push unfetched deleted remote branch & server GC"
537 (
538 # point of this is to simulate the case where the local cache of the remote
539 # branch state contains a branch which has actually been deleted on the remote,
540 # the client just doesn't know yet (hasn't done 'git fetch origin --prune')
541 # If the server GC'd the objects that deleted branch contained, but they were
542 # referenced by a branch being pushed (earlier commit), push might assume it
543 # doesn't have to push it, but it does. Tests that we check the real remote refs
544 # before making an assumption about the diff we need to push
545 set -e
546
547 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-server-deleted-branch-gc"
548 setup_remote_repo "$reponame"
549 clone_repo "$reponame" "$reponame"
550
551
552 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
553 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
554
555 NUMFILES=4
556 # generate content we'll use
557 for ((a=0; a < NUMFILES ; a++))
558 do
559 content[$a]="filecontent$a"
560 oid[$a]=$(calc_oid "${content[$a]}")
561 done
562
563 echoscip-shell system . . echo. "[
564 {
565 \"CommitDate\":\"$(get_date -10d)\",
566 \"Files\":[
567 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
568 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
569 },
570 {
571 \"NewBranch\":\"branch-to-delete\",
572 \"CommitDate\":\"$(get_date -5d)\",
573 \"Files\":[
574 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
575 },
576 {
577 \"NewBranch\":\"branch-to-push-after\",
578 \"CommitDate\":\"$(get_date -2d)\",
579 \"Files\":[
580 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
581 }
582 ]" | lfstest-testutils addcommits
583
584 # push only the first 2 branches
585 gitscip-shell system . . git. push origin main branch-to-delete
586 for ((a=0; a < 3 ; a++))
587 do
588 assert_server_object "$reponame" "${oid[$a]}"
589 done
590 # confirm we haven't pushed the last one yet
591 refute_server_object "$reponame" "${oid[3]}"
592 # copy the cached remote ref for the branch we're going to delete remotely
593 cpscip-shell system . . cp. .git/refs/remotes/origin/branch-to-delete branch-to-delete.ref
594 # now delete the branch on the server
595 gitscip-shell system . . git. push origin --delete branch-to-delete
596 # remove the OID in it, as if GC'd
597 delete_server_object "$reponame" "${oid[2]}"
598 refute_server_object "$reponame" "${oid[2]}"
599 # Now put the cached remote ref back, as if someone else had deleted it but
600 # we hadn't done git fetch --prune yet
601 mvscip-shell system . . mv. branch-to-delete.ref .git/refs/remotes/origin/branch-to-delete
602 # Confirm that local cache of remote branch is back
603 gitscip-shell system . . git. branch -r 2>&1 | teescip-shell system . . tee. branch-r.log
604 grepscip-shell system . . grep. "origin/branch-to-delete" branch-r.log
605 # Now push later branch which should now need to re-push previous commits LFS too
606 gitscip-shell system . . git. push origin branch-to-push-after
607 # all objects should now be there even though cached remote branch claimed it already had file3.dat
608 for ((a=0; a < NUMFILES ; a++))
609 do
610 assert_server_object "$reponame" "${oid[$a]}"
611 done
612
613 )
614 end_test
615
616 begin_test "pre-push delete branch"
617 (
618 set -e
619
620 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-delete-branch"
621 setup_remote_repo "$reponame"
622 clone_repo "$reponame" "$reponame"
623
624
625 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
626 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
627
628 NUMFILES=4
629 # generate content we'll use
630 for ((a=0; a < NUMFILES ; a++))
631 do
632 content[$a]="filecontent$a"
633 oid[$a]=$(calc_oid "${content[$a]}")
634 done
635
636 echoscip-shell system . . echo. "[
637 {
638 \"CommitDate\":\"$(get_date -2d)\",
639 \"Files\":[
640 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
641 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
642 },
643 {
644 \"NewBranch\":\"branch-to-delete\",
645 \"CommitDate\":\"$(get_date -1d)\",
646 \"Files\":[
647 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
648 },
649 {
650 \"ParentBranches\":[\"main\"],
651 \"CommitDate\":\"$(get_date -0d)\",
652 \"Files\":[
653 {\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
654 }
655 ]" | lfstest-testutils addcommits
656
657 # push all branches
658 gitscip-shell system . . git. push origin main branch-to-delete
659 for ((a=0; a < NUMFILES ; a++))
660 do
661 assert_server_object "$reponame" "${oid[$a]}"
662 done
663
664 # deleting a branch with git push should not fail
665 # (requires correct special casing of "(delete) 0000000000.." in hook)
666 gitscip-shell system . . git. push origin --delete branch-to-delete
667 )
668 end_test
669
670 begin_test "pre-push with our lock"
671 (
672 set -e
673
674 reponame="pre_push_owned_locks"
675 setup_remote_repo "$reponame"
676 clone_repo "$reponame" "$reponame"
677
678 gitscip-shell system . . git. lfs track "*.dat"
679 gitscip-shell system . . git. add .gitattributes
680 gitscip-shell system . . git. commit -m "initial commit"
681
682 contents="locked contents"
683 printfscip-shell system . . printf. "%s" "$contents" > locked.dat
684 gitscip-shell system . . git. add locked.dat
685 gitscip-shell system . . git. commit -m "add locked.dat"
686
687 gitscip-shell system . . git. push origin main
688
689 gitscip-shell system . . git. lfs lock --json "locked.dat" | teescip-shell system . . tee. lock.log
690
691 id=$(assert_lock lock.log locked.dat)
692 assert_server_lock $id
693
694 printfscip-shell system . . printf. "authorized changes" >> locked.dat
695 gitscip-shell system . . git. add locked.dat
696 gitscip-shell system . . git. commit -m "add unauthorized changes"
697
698 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
699 grepscip-shell system . . grep. "Consider unlocking your own locked files" push.log
700 grepscip-shell system . . grep. "* locked.dat" push.log
701
702 assert_server_lock "$id"
703 )
704 end_test
705
706 begin_test "pre-push with their lock on lfs file"
707 (
708 set -e
709
710 reponame="pre_push_unowned_lock"
711 setup_remote_repo "$reponame"
712 clone_repo "$reponame" "$reponame"
713
714 gitscip-shell system . . git. lfs track "*.dat"
715 gitscip-shell system . . git. add .gitattributes
716 gitscip-shell system . . git. commit -m "initial commit"
717
718 contents="locked contents"
719
720 # any lock path with "theirs" is returned as "their" lock by /locks/verify
721 printfscip-shell system . . printf. "%s" "$contents" > locked_theirs.dat
722 gitscip-shell system . . git. add locked_theirs.dat
723 gitscip-shell system . . git. commit -m "add locked_theirs.dat"
724
725 gitscip-shell system . . git. push origin main
726
727 gitscip-shell system . . git. lfs lock --json "locked_theirs.dat" | teescip-shell system . . tee. lock.log
728 id=$(assert_lock lock.log locked_theirs.dat)
729 assert_server_lock $id
730
731 pushd "$TRASHDIR" >/dev/nullscip-shell filesystem . . `/dev/null`.
732 clone_repo "$reponame" "$reponame-assert"
733 gitscip-shell system . . git. config lfs.locksverify true
734
735 printfscip-shell system . . printf. "unauthorized changes" >> locked_theirs.dat
736 gitscip-shell system . . git. add locked_theirs.dat
737 # --no-verify is used to avoid the pre-commit hook which is not under test
738 gitscip-shell system . . git. commit --no-verify -m "add unauthorized changes"
739
740 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
741 res="${PIPESTATUS[0]}"
742 if [scip-shell system . . `[`. "0" -eq "$res" ]; then
743 echoscip-shell system . . echo. "push should fail"
744 exit 1
745 fi
746
747 grepscip-shell system . . grep. "Unable to push locked files" push.log
748 grepscip-shell system . . grep. "* locked_theirs.dat - Git LFS Tests" push.log
749
750 grepscip-shell system . . grep. "Cannot update locked files." push.log
751 refute_server_object "$reponame" "$(calc_oid_file locked_theirs.dat)"
752 popd >/dev/nullscip-shell filesystem . . `/dev/null`.
753 )
754 end_test
755
756 begin_test "pre-push with their lock on non-lfs lockable file"
757 (
758 set -e
759
760 reponame="pre_push_unowned_lock_not_lfs"
761 setup_remote_repo "$reponame"
762 clone_repo "$reponame" "$reponame"
763
764 echoscip-shell system . . echo. "*.dat lockable" > .gitattributes
765 gitscip-shell system . . git. add .gitattributes
766 gitscip-shell system . . git. commit -m "initial commit"
767
768 # any lock path with "theirs" is returned as "their" lock by /locks/verify
769 echoscip-shell system . . echo. "hi" > readme.txt
770 echoscip-shell system . . echo. "tiny" > tiny_locked_theirs.dat
771 gitscip-shell system . . git. help > large_locked_theirs.dat
772 gitscip-shell system . . git. add readme.txt tiny_locked_theirs.dat large_locked_theirs.dat
773 gitscip-shell system . . git. commit -m "add initial files"
774
775 gitscip-shell system . . git. push origin main
776
777 gitscip-shell system . . git. lfs lock --json "tiny_locked_theirs.dat" | teescip-shell system . . tee. lock.log
778 id=$(assert_lock lock.log tiny_locked_theirs.dat)
779 assert_server_lock $id
780
781 gitscip-shell system . . git. lfs lock --json "large_locked_theirs.dat" | teescip-shell system . . tee. lock.log
782 id=$(assert_lock lock.log large_locked_theirs.dat)
783 assert_server_lock $id
784
785 pushd "$TRASHDIR" >/dev/nullscip-shell filesystem . . `/dev/null`.
786 clone_repo "$reponame" "$reponame-assert"
787 gitscip-shell system . . git. config lfs.locksverify true
788
789 gitscip-shell system . . git. lfs update # manually add pre-push hook, since lfs clean hook is not used
790 echoscip-shell system . . echo. "other changes" >> readme.txt
791 echoscip-shell system . . echo. "unauthorized changes" >> large_locked_theirs.dat
792 echoscip-shell system . . echo. "unauthorized changes" >> tiny_locked_theirs.dat
793 # --no-verify is used to avoid the pre-commit hook which is not under test
794 gitscip-shell system . . git. commit --no-verify -am "add unauthorized changes"
795
796 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
797 res="${PIPESTATUS[0]}"
798 if [scip-shell system . . `[`. "0" -eq "$res" ]; then
799 echoscip-shell system . . echo. "push should fail"
800 exit 1
801 fi
802
803 grepscip-shell system . . grep. "Unable to push locked files" push.log
804 grepscip-shell system . . grep. "* large_locked_theirs.dat - Git LFS Tests" push.log
805 grepscip-shell system . . grep. "* tiny_locked_theirs.dat - Git LFS Tests" push.log
806 grepscip-shell system . . grep. "Cannot update locked files." push.log
807
808 refute_server_object "$reponame" "$(calc_oid_file large_locked_theirs.dat)"
809 refute_server_object "$reponame" "$(calc_oid_file tiny_locked_theirs.dat)"
810 popd >/dev/nullscip-shell filesystem . . `/dev/null`.
811 )
812 end_test
813
814 begin_test "pre-push locks verify 5xx with verification enabled"
815 (
816 set -e
817
818 reponame="lock-enabled-verify-5xx"
819 setup_remote_repo "$reponame"
820 clone_repo "$reponame" "$reponame"
821
822 endpoint="$(repo_endpoint $GITSERVER $reponame)"
823
824 contents="example"
825 contents_oid="$(calc_oid "$contents")"
826 printfscip-shell system . . printf. "%s" "$contents" > a.dat
827 gitscip-shell system . . git. lfs track "*.dat"
828 gitscip-shell system . . git. add .gitattributes a.dat
829 gitscip-shell system . . git. commit --message "initial commit"
830
831 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" true
832
833 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
834 grepscip-shell system . . grep. "\"origin\" does not support the Git LFS locking API" push.log
835 grepscip-shell system . . grep. "git config lfs.$endpoint.locksverify false" push.log
836
837 refute_server_object "$reponame" "$contents_oid"
838 )
839 end_test
840
841 begin_test "pre-push disable locks verify on exact url"
842 (
843 set -e
844
845 reponame="lock-disabled-verify-5xx"
846 setup_remote_repo "$reponame"
847 clone_repo "$reponame" "$reponame"
848
849 endpoint="$(repo_endpoint $GITSERVER $reponame)"
850
851 contents="example"
852 contents_oid="$(calc_oid "$contents")"
853 printfscip-shell system . . printf. "%s" "$contents" > a.dat
854 gitscip-shell system . . git. lfs track "*.dat"
855 gitscip-shell system . . git. add .gitattributes a.dat
856 gitscip-shell system . . git. commit --message "initial commit"
857
858 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
859
860 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
861 [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
862
863 assert_server_object "$reponame" "$contents_oid"
864 )
865 end_test
866
867 begin_test "pre-push disable locks verify on partial url"
868 (
869 set -e
870
871 reponame="lock-disabled-verify-5xx-partial"
872 setup_remote_repo "$reponame"
873 clone_repo "$reponame" "$reponame"
874
875 endpoint="$server/$repo"
876
877 contents="example"
878 contents_oid="$(calc_oid "$contents")"
879 printfscip-shell system . . printf. "%s" "$contents" > a.dat
880 gitscip-shell system . . git. lfs track "*.dat"
881 gitscip-shell system . . git. add .gitattributes a.dat
882 gitscip-shell system . . git. commit --message "initial commit"
883
884 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
885
886 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
887 [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
888
889 assert_server_object "$reponame" "$contents_oid"
890 )
891 end_test
892
893 begin_test "pre-push locks verify 403 with good ref"
894 (
895 set -e
896
897 reponame="lock-verify-main-branch-required"
898 setup_remote_repo "$reponame"
899 clone_repo "$reponame" "$reponame"
900
901 contents="example"
902 contents_oid="$(calc_oid "$contents")"
903 printfscip-shell system . . printf. "%s" "$contents" > a.dat
904 gitscip-shell system . . git. lfs track "*.dat"
905 gitscip-shell system . . git. add .gitattributes a.dat
906 gitscip-shell system . . git. commit --message "initial commit"
907
908 gitscip-shell system . . git. config "lfs.$GITSERVER/$reponame.git.locksverify" true
909 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
910
911 assert_server_object "$reponame" "$contents_oid" "refs/heads/main"
912 )
913 end_test
914
915 begin_test "pre-push locks verify 403 with good tracked ref"
916 (
917 set -e
918
919 reponame="lock-verify-tracked-branch-required"
920 setup_remote_repo "$reponame"
921 clone_repo "$reponame" "$reponame"
922
923 contents="example"
924 contents_oid="$(calc_oid "$contents")"
925 printfscip-shell system . . printf. "%s" "$contents" > a.dat
926 gitscip-shell system . . git. lfs track "*.dat"
927 gitscip-shell system . . git. add .gitattributes a.dat
928 gitscip-shell system . . git. commit --message "initial commit"
929
930 gitscip-shell system . . git. config push.default upstream
931 gitscip-shell system . . git. config branch.main.merge refs/heads/tracked
932 gitscip-shell system . . git. config branch.main.remote origin
933 gitscip-shell system . . git. config "lfs.$GITSERVER/$reponame.git.locksverify" true
934 gitscip-shell system . . git. push 2>&1 | teescip-shell system . . tee. push.log
935
936 assert_server_object "$reponame" "$contents_oid" "refs/heads/tracked"
937 )
938 end_test
939
940 begin_test "pre-push locks verify 403 with explicit ref"
941 (
942 set -e
943
944 reponame="lock-verify-explicit-branch-required"
945 setup_remote_repo "$reponame"
946 clone_repo "$reponame" "$reponame"
947
948 contents="example"
949 contents_oid="$(calc_oid "$contents")"
950 printfscip-shell system . . printf. "%s" "$contents" > a.dat
951 gitscip-shell system . . git. lfs track "*.dat"
952 gitscip-shell system . . git. add .gitattributes a.dat
953 gitscip-shell system . . git. commit --message "initial commit"
954
955 gitscip-shell system . . git. config "lfs.$GITSERVER/$reponame.git.locksverify" true
956 gitscip-shell system . . git. push origin main:explicit 2>&1 | teescip-shell system . . tee. push.log
957
958 assert_server_object "$reponame" "$contents_oid" "refs/heads/explicit"
959 )
960 end_test
961
962 begin_test "pre-push locks verify 403 with bad ref"
963 (
964 set -e
965
966 reponame="lock-verify-other-branch-required"
967 setup_remote_repo "$reponame"
968 clone_repo "$reponame" "$reponame"
969
970 contents="example"
971 contents_oid="$(calc_oid "$contents")"
972 printfscip-shell system . . printf. "%s" "$contents" > a.dat
973 gitscip-shell system . . git. lfs track "*.dat"
974 gitscip-shell system . . git. add .gitattributes a.dat
975 gitscip-shell system . . git. commit --message "initial commit"
976
977 gitscip-shell system . . git. config "lfs.$GITSERVER/$reponame.git.locksverify" true
978 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
979 grepscip-shell system . . grep. "failed to push some refs" push.log
980 refute_server_object "$reponame" "$contents_oid" "refs/heads/other"
981 )
982 end_test
983
984 begin_test "pre-push locks verify 5xx with verification unset"
985 (
986 set -e
987
988 reponame="lock-unset-verify-5xx"
989 setup_remote_repo "$reponame"
990 clone_repo "$reponame" "$reponame"
991
992 endpoint="$(repo_endpoint $GITSERVER $reponame)"
993
994 contents="example"
995 contents_oid="$(calc_oid "$contents")"
996 printfscip-shell system . . printf. "%s" "$contents" > a.dat
997 gitscip-shell system . . git. lfs track "*.dat"
998 gitscip-shell system . . git. add .gitattributes a.dat
999 gitscip-shell system . . git. commit --message "initial commit"
1000
1001 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1002
1003 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1004 grepscip-shell system . . grep. "\"origin\" does not support the Git LFS locking API" push.log
1005
1006 assert_server_object "$reponame" "$contents_oid"
1007 )
1008 end_test
1009
1010 begin_test "pre-push locks verify 501 with verification enabled"
1011 (
1012 set -e
1013
1014 reponame="lock-enabled-verify-501"
1015 setup_remote_repo "$reponame"
1016 clone_repo "$reponame" "$reponame"
1017
1018 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1019
1020 contents="example"
1021 contents_oid="$(calc_oid "$contents")"
1022 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1023 gitscip-shell system . . git. lfs track "*.dat"
1024 gitscip-shell system . . git. add .gitattributes a.dat
1025 gitscip-shell system . . git. commit --message "initial commit"
1026
1027 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" true
1028
1029 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1030
1031 assert_server_object "$reponame" "$contents_oid"
1032 [scip-shell system . . `[`. "false" = "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1033 )
1034 end_test
1035
1036
1037 begin_test "pre-push locks verify 501 with verification disabled"
1038 (
1039 set -e
1040
1041 reponame="lock-disabled-verify-501"
1042 setup_remote_repo "$reponame"
1043 clone_repo "$reponame" "$reponame"
1044
1045 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1046
1047 contents="example"
1048 contents_oid="$(calc_oid "$contents")"
1049 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1050 gitscip-shell system . . git. lfs track "*.dat"
1051 gitscip-shell system . . git. add .gitattributes a.dat
1052 gitscip-shell system . . git. commit --message "initial commit"
1053
1054 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
1055
1056 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1057
1058 assert_server_object "$reponame" "$contents_oid"
1059 [scip-shell system . . `[`. "false" = "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1060 )
1061 end_test
1062
1063 begin_test "pre-push locks verify 501 with verification unset"
1064 (
1065 set -e
1066
1067 reponame="lock-unset-verify-501"
1068 setup_remote_repo "$reponame"
1069 clone_repo "$reponame" "$reponame"
1070
1071 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1072
1073 contents="example"
1074 contents_oid="$(calc_oid "$contents")"
1075 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1076 gitscip-shell system . . git. lfs track "*.dat"
1077 gitscip-shell system . . git. add .gitattributes a.dat
1078 gitscip-shell system . . git. commit --message "initial commit"
1079
1080 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1081
1082 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1083
1084 assert_server_object "$reponame" "$contents_oid"
1085 [scip-shell system . . `[`. "false" = "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1086 )
1087 end_test
1088
1089 begin_test "pre-push locks verify 200"
1090 (
1091 set -e
1092
1093 reponame="lock-verify-200"
1094 setup_remote_repo "$reponame"
1095 clone_repo "$reponame" "$reponame"
1096
1097 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1098 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1099
1100 contents="example"
1101 contents_oid="$(calc_oid "$contents")"
1102 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1103 gitscip-shell system . . git. lfs track "*.dat"
1104 gitscip-shell system . . git. add .gitattributes a.dat
1105 gitscip-shell system . . git. commit --message "initial commit"
1106
1107 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1108
1109 grepscip-shell system . . grep. "Locking support detected on remote \"origin\"." push.log
1110 grepscip-shell system . . grep. "git config lfs.$endpoint.locksverify true" push.log
1111 assert_server_object "$reponame" "$contents_oid"
1112 )
1113 end_test
1114
1115 begin_test "pre-push locks verify 403 with verification enabled"
1116 (
1117 set -e
1118
1119 reponame="lock-enabled-verify-403"
1120 setup_remote_repo "$reponame"
1121 clone_repo "$reponame" "$reponame"
1122
1123 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1124
1125 contents="example"
1126 contents_oid="$(calc_oid "$contents")"
1127 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1128 gitscip-shell system . . git. lfs track "*.dat"
1129 gitscip-shell system . . git. add .gitattributes a.dat
1130 gitscip-shell system . . git. commit --message "initial commit"
1131
1132 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" true
1133
1134 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1135 grepscip-shell system . . grep. "error: Authentication error" push.log
1136
1137 refute_server_object "$reponame" "$contents_oid"
1138 [scip-shell system . . `[`. "true" = "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1139 )
1140 end_test
1141
1142 begin_test "pre-push locks verify 403 with verification disabled"
1143 (
1144 set -e
1145
1146 reponame="lock-disabled-verify-403"
1147 setup_remote_repo "$reponame"
1148 clone_repo "$reponame" "$reponame"
1149
1150 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1151
1152 contents="example"
1153 contents_oid="$(calc_oid "$contents")"
1154 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1155 gitscip-shell system . . git. lfs track "*.dat"
1156 gitscip-shell system . . git. add .gitattributes a.dat
1157 gitscip-shell system . . git. commit --message "initial commit"
1158
1159 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
1160
1161 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1162
1163 assert_server_object "$reponame" "$contents_oid"
1164 [scip-shell system . . `[`. "false" = "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1165 )
1166 end_test
1167
1168 begin_test "pre-push locks verify 403 with verification unset"
1169 (
1170 set -e
1171
1172 reponame="lock-unset-verify-403"
1173 setup_remote_repo "$reponame"
1174 clone_repo "$reponame" "$reponame"
1175
1176 endpoint="$(repo_endpoint $GITSERVER $reponame)"
1177
1178 contents="example"
1179 contents_oid="$(calc_oid "$contents")"
1180 printfscip-shell system . . printf. "%s" "$contents" > a.dat
1181 gitscip-shell system . . git. lfs track "*.dat"
1182 gitscip-shell system . . git. add .gitattributes a.dat
1183 gitscip-shell system . . git. commit --message "initial commit"
1184
1185 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1186
1187 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1188 grepscip-shell system . . grep. "warning: Authentication error" push.log
1189
1190 assert_server_object "$reponame" "$contents_oid"
1191 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. config "lfs.$endpoint.locksverify")" ]
1192 )
1193 end_test
1194
1195 begin_test "pre-push with pushDefault and explicit remote"
1196 (
1197 set -e
1198 reponame="pre-push-pushdefault-explicit"
1199 setup_remote_repo "$reponame"
1200 clone_repo "$reponame" "$reponame"
1201
1202 gitscip-shell system . . git. remote add wrong "$(repo_endpoint "$GITSERVER" "wrong-url")"
1203
1204 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
1205 gitscip-shell system . . git. config remote.pushDefault wrong
1206 gitscip-shell system . . git. lfs track "*.dat"
1207 echoscip-shell system . . echo. "hi" > a.dat
1208 gitscip-shell system . . git. add .gitattributes a.dat
1209 gitscip-shell system . . git. commit -m "add a.dat"
1210
1211 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
1212
1213 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
1214
1215 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
1216 grepscip-shell system . . grep. wrong-url push.log && exit 1
1217 truescip-shell system . . true.
1218 )
1219 end_test
1220
1221 begin_test "pre-push uses optimization if remote URL matches"
1222 (
1223 set -e
1224 reponame="pre-push-remote-url-optimization"
1225 setup_remote_repo "$reponame"
1226 clone_repo "$reponame" "$reponame"
1227
1228 endpoint=$(gitscip-shell system . . git. config remote.origin.url)
1229 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
1230 gitscip-shell system . . git. lfs track "*.dat"
1231 echoscip-shell system . . echo. "hi" > a.dat
1232 contents_oid="$(calc_oid_file "a.dat")"
1233 gitscip-shell system . . git. add .gitattributes a.dat
1234 gitscip-shell system . . git. commit -m "add a.dat"
1235
1236 refute_server_object "$reponame" $contents_oid "refs/heads/main"
1237
1238 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. push "$endpoint" main 2>&1 | teescip-shell system . . tee. push.log
1239 grepscip-shell system . . grep. 'rev-list.*--not --remotes=origin' push.log
1240 )
1241 end_test
1242
1243 begin_test "pre-push does not traverse Git objects server has"
1244 (
1245 set -e
1246 reponame="pre-push-traverse-server-objects"
1247 setup_remote_repo "$reponame"
1248 clone_repo "$reponame" "$reponame"
1249
1250 endpoint=$(gitscip-shell system . . git. config remote.origin.url)
1251 gitscip-shell system . . git. config "lfs.$endpoint.locksverify" false
1252 gitscip-shell system . . git. lfs track "*.dat"
1253 echoscip-shell system . . echo. "hi" > a.dat
1254 contents_oid="$(calc_oid_file "a.dat")"
1255 gitscip-shell system . . git. add .gitattributes a.dat
1256 gitscip-shell system . . git. commit -m "add a.dat"
1257
1258 refute_server_object "$reponame" $contents_oid "refs/heads/main"
1259
1260 # We use a different URL instead of a named remote or the remote URL so that
1261 # we can't make use of the optimization that ignores objects we already have
1262 # in remote tracking branches.
1263 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. push "$endpoint.git" main 2>&1 | teescip-shell system . . tee. push.log
1264
1265 assert_server_object "$reponame" $contents_oid "refs/heads/main"
1266
1267 echoscip-shell system . . echo. "hello" > b.dat
1268 contents2_oid="$(calc_oid_file "b.dat")"
1269 gitscip-shell system . . git. add .gitattributes b.dat
1270 gitscip-shell system . . git. commit -m "add b.dat"
1271
1272 refute_server_object "$reponame" $contents2_oid "refs/heads/main"
1273
1274 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 gitscip-shell system . . git. push "$endpoint.git" main 2>&1 | teescip-shell system . . tee. push.log
1275
1276 assert_server_object "$reponame" $contents2_oid "refs/heads/main"
1277
1278 # Verify that we haven't tried to push or query for the object we already
1279 # pushed before; i.e., we didn't see it because we ignored its Git object
1280 # during traversal.
1281 grepscip-shell system . . grep. $contents_oid push.log && exit 1
1282 truescip-shell system . . true.
1283 )
1284 end_test
1285
1286 begin_test "pre-push with force-pushed ref"
1287 (
1288 set -e
1289 reponame="pre-push-force-pushed-ref"
1290 setup_remote_repo "$reponame"
1291 clone_repo "$reponame" "$reponame"
1292
1293 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
1294 gitscip-shell system . . git. lfs track "*.dat"
1295 echoscip-shell system . . echo. "hi" > a.dat
1296 gitscip-shell system . . git. add .gitattributes a.dat
1297 gitscip-shell system . . git. commit -m "add a.dat"
1298 gitscip-shell system . . git. tag -a -m tagname tagname
1299
1300 refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
1301
1302 gitscip-shell system . . git. push origin main tagname
1303
1304 assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
1305
1306 # We pick a different message so that we get different object IDs even if both
1307 # commands run in the same second.
1308 gitscip-shell system . . git. tag -f -a -m tagname2 tagname
1309 # Prune the old tag object.
1310 gitscip-shell system . . git. reflog expire --all --expire=now
1311 gitscip-shell system . . git. gc --prune=now
1312 # Make sure we deal with us missing the object for the old value of the tag ref.
1313 gitscip-shell system . . git. push origin +tagname
1314 )
1315 end_test
1316
1317 begin_test "pre-push with local path"
1318 (
1319 set -e
1320 reponame="pre-push-local-path"
1321 setup_remote_repo "$reponame"
1322 clone_repo "$reponame" "$reponame-2"
1323 cd ..
1324 clone_repo "$reponame" "$reponame"
1325
1326 gitscip-shell system . . git. lfs track "*.dat"
1327 echoscip-shell system . . echo. "hi" > a.dat
1328 gitscip-shell system . . git. add .gitattributes a.dat
1329 gitscip-shell system . . git. commit -m "add a.dat"
1330
1331 # Push to the other repo.
1332 gitscip-shell system . . git. push "../$reponame-2" main:foo
1333
1334 # Push to . to make sure that works.
1335 gitscip-shell system . . git. push "." main:foo
1336
1337 gitscip-shell system . . git. lfs fsck
1338 cd "../$reponame-2"
1339 gitscip-shell system . . git. checkout foo
1340 gitscip-shell system . . git. lfs fsck
1341 )
1342 end_test