Debian Codegraph @

t/t-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 # 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup().() {
9 reponame="$1"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
12
13 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
14 gitscip-shell system . . git. lfs track "*.dat"
15 echoscip-shell system . . echo. "push a" > a.dat
16 gitscip-shell system . . git. add .gitattributes a.dat
17 gitscip-shell system . . git. commit -m "add a.dat"
18 }
19
20 begin_test "push with good ref"
21 (
22 set -e
23 push_repo_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-main-branch-required"
24
25 gitscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-tracked-branch-required"
34
35 gitscip-shell system . . git. config push.default upstream
36 gitscip-shell system . . git. config branch.main.merge refs/heads/tracked
37 gitscip-shell system . . git. lfs push origin main
38 )
39 end_test
40
41 begin_test "push with invalid ref"
42 (
43 set -e
44 push_repo_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-invalid-branch-required"
45
46 gitscip-shell system . . git. lfs push origin jibberish >push.log 2>&1 && exit 1
47 grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-other-branch-required"
55
56 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
57 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
58 echoscip-shell system . . echo. "expected command to fail"
59 exit 1
60 fi
61
62 grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-nothing"
70
71 gitscip-shell system . . git. lfs push origin 2>&1 | teescip-shell system . . tee. push.log
72 grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-given-and-config"
80
81 gitscip-shell system . . git. remote add bad-remote "invalid-url"
82
83 gitscip-shell system . . git. config branch.main.pushRemote bad-remote
84
85 gitscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-stdin-extra-args"
94
95 echoscip-shell system . . echo. "main" | gitscip-shell system . . git. lfs push origin --stdin --dry-run "another-ref" \
96 2>&1 | teescip-shell system . . tee. push.log
97 grepscip-shell system . . grep. "Further command line arguments are ignored with --stdin" push.log
98 )
99
100 begin_test "push"
101 (
102 set -e
103
104 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
105 setup_remote_repo "$reponame"
106 clone_repo "$reponame" repo
107
108 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
109
110 gitscip-shell system . . git. lfs track "*.dat"
111 echoscip-shell system . . echo. "push a" > a.dat
112 gitscip-shell system . . git. add .gitattributes a.dat
113 gitscip-shell system . . git. commit -m "add a.dat"
114
115 gitscip-shell system . . git. lfs push --dry-run origin main 2>&1 | teescip-shell system . . tee. push.log
116 grepscip-shell system . . grep. "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
117 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 1 ]
118
119 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
120 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 7 B" push.log
121
122 gitscip-shell system . . git. checkout -b push-b
123 echoscip-shell system . . echo. "push b" > b.dat
124 gitscip-shell system . . git. add b.dat
125 gitscip-shell system . . git. commit -m "add b.dat"
126
127 gitscip-shell system . . git. lfs push --dry-run origin push-b 2>&1 | teescip-shell system . . tee. push.log
128 grepscip-shell system . . grep. "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
129 grepscip-shell system . . grep. "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
130 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " < push.log) -eq 2 ]
131
132 printfscip-shell system . . printf. "push-b\n\n" | gitscip-shell system . . git. lfs push --dry-run origin --stdin 2>&1 | teescip-shell system . . tee. push.log
133 grepscip-shell system . . grep. "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 => a.dat" push.log
134 grepscip-shell system . . grep. "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 => b.dat" push.log
135 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " < push.log) -eq 2 ]
136
137 # simulate remote ref
138 mkdirscip-shell system . . mkdir. -p .git/refs/remotes/origin
139 gitscip-shell system . . git. rev-parse HEAD > .git/refs/remotes/origin/HEAD
140
141 gitscip-shell system . . git. lfs push --dry-run origin push-b 2>&1 | teescip-shell system . . tee. push.log
142 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 0 ]
143
144 rmscip-shell system . . rm. -rf .git/refs/remotes
145
146 gitscip-shell system . . git. lfs push origin push-b 2>&1 | teescip-shell system . . tee. push.log
147 grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup().() {
153 suffix="$1"
154 reponame="$(basenamescip-shell system . . 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 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
170 gitscip-shell system . . git. lfs track "*.dat"
171
172 echoscip-shell system . . 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 gitscip-shell system . . git. rm file2.dat
210 gitscip-shell system . . git. commit -m "remove file2.dat"
211
212 # simulate remote ref
213 mkdirscip-shell system . . mkdir. -p .git/refs/remotes/origin
214 gitscip-shell system . . git. rev-parse HEAD > .git/refs/remotes/origin/HEAD
215
216 setup_alternate_remote "$reponame-$suffix"
217 gitscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup(). "everything"
225
226 gitscip-shell system . . git. lfs push --dry-run --all origin 2>&1 | teescip-shell system . . tee. push.log
227 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
228 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
229 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
230 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
231 grepscip-shell system . . grep. "push $oid5 => file1.dat" push.log
232 grepscip-shell system . . grep. "push $extraoid => file2.dat" push.log
233 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " < push.log) -eq 6 ]
234
235 gitscip-shell system . . git. push --all origin 2>&1 | teescip-shell system . . tee. push.log
236 [scip-shell system . . `[`. $(grepscip-shell system . . 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 echoscip-shell system . . echo. "push while missing old objects locally"
245 setup_alternate_remote "$reponame-$suffix-2"
246 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
247
248 gitscip-shell system . . 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 rmscip-shell system . . rm. ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
256
257 echoscip-shell system . . echo. "dry run missing local object that exists on server"
258 gitscip-shell system . . git. lfs push --dry-run --all origin 2>&1 | teescip-shell system . . tee. push.log
259 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
260 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
261 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
262 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
263 grepscip-shell system . . grep. "push $oid5 => file1.dat" push.log
264 grepscip-shell system . . grep. "push $extraoid => file2.dat" push.log
265 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 6 ]
266
267 gitscip-shell system . . git. push --all origin 2>&1 | teescip-shell system . . tee. push.log
268 grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup(). "ref"
282
283 gitscip-shell system . . git. lfs push --dry-run --all origin branch 2>&1 | teescip-shell system . . tee. push.log
284 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
285 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
286 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
287 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " < push.log) -eq 3 ]
288
289 gitscip-shell system . . git. lfs push --all origin branch 2>&1 | teescip-shell system . . tee. push.log
290 [scip-shell system . . `[`. $(grepscip-shell system . . 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 echoscip-shell system . . echo. "push while missing old objects locally"
299 setup_alternate_remote "$reponame-$suffix-2"
300 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
301 gitscip-shell system . . 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 rmscip-shell system . . rm. ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
309
310 # dry run doesn't change
311 gitscip-shell system . . git. lfs push --dry-run --all origin branch 2>&1 | teescip-shell system . . tee. push.log
312 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
313 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
314 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
315 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 3 ]
316
317 gitscip-shell system . . git. push origin branch 2>&1 | teescip-shell system . . tee. push.log
318 [scip-shell system . . `[`. $(grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup(). "multiple-refs"
332
333 gitscip-shell system . . git. lfs push --dry-run --all origin branch tag 2>&1 | teescip-shell system . . tee. push.log
334 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
335 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
336 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
337 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
338 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 4 ]
339
340 printfscip-shell system . . printf. "branch\ntag" | gitscip-shell system . . git. lfs push --dry-run --all origin --stdin 2>&1 | teescip-shell system . . tee. push.log
341 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
342 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
343 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
344 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
345 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 4 ]
346
347 gitscip-shell system . . git. lfs push --all origin branch tag 2>&1 | teescip-shell system . . tee. push.log
348 [scip-shell system . . `[`. $(grepscip-shell system . . 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 echoscip-shell system . . echo. "push while missing old objects locally"
357 setup_alternate_remote "$reponame-$suffix-2"
358 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
359 gitscip-shell system . . 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 rmscip-shell system . . rm. ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
367
368 # dry run doesn't change
369 gitscip-shell system . . git. lfs push --dry-run --all origin branch tag 2>&1 | teescip-shell system . . tee. push.log
370 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
371 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
372 grepscip-shell system . . grep. "push $oid3 => file1.dat" push.log
373 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
374 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 4 ]
375
376 gitscip-shell system . . git. push origin branch refs/tags/tag 2>&1 | teescip-shell system . . tee. push.log
377 [scip-shell system . . `[`. $(grepscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup(). "ref-with-deleted"
391
392 gitscip-shell system . . git. lfs push --dry-run --all origin main 2>&1 | teescip-shell system . . tee. push.log
393 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
394 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
395 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
396 grepscip-shell system . . grep. "push $oid5 => file1.dat" push.log
397 grepscip-shell system . . grep. "push $extraoid => file2.dat" push.log
398 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 5 ]
399
400 gitscip-shell system . . git. lfs push --all origin main 2>&1 | teescip-shell system . . tee. push.log
401 [scip-shell system . . `[`. $(grepscip-shell system . . 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 echoscip-shell system . . echo. "push while missing old objects locally"
410 setup_alternate_remote "$reponame-$suffix-2"
411 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame-$suffix-2").locksverify" true
412 gitscip-shell system . . 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 rmscip-shell system . . rm. ".git/lfs/objects/${oid1:0:2}/${oid1:2:2}/$oid1"
420
421 # dry run doesn't change
422 gitscip-shell system . . git. lfs push --dry-run --all origin main 2>&1 | teescip-shell system . . tee. push.log
423 grepscip-shell system . . grep. "push $oid1 => file1.dat" push.log
424 grepscip-shell system . . grep. "push $oid2 => file1.dat" push.log
425 grepscip-shell system . . grep. "push $oid4 => file1.dat" push.log
426 grepscip-shell system . . grep. "push $oid5 => file1.dat" push.log
427 grepscip-shell system . . grep. "push $extraoid => file2.dat" push.log
428 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "^push " push.log) -eq 5 ]
429
430 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
431 [scip-shell system . . `[`. $(grepscip-shell system . . 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="$(basenamescip-shell system . . basename. "$0" ".sh")"
445 setup_remote_repo "$reponame"
446 clone_repo "$reponame" repo2
447
448 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
449
450 gitscip-shell system . . git. lfs track "*.dat"
451 echoscip-shell system . . echo. "push a" > a.dat
452 gitscip-shell system . . git. add .gitattributes a.dat
453 gitscip-shell system . . git. commit -m "add a.dat"
454
455 gitscip-shell system . . git. lfs push --object-id origin --dry-run 2>&1 | teescip-shell system . . tee. push.log
456 grepscip-shell system . . grep. "At least one object ID must be supplied with --object-id" push.log
457
458 gitscip-shell system . . git. lfs push --object-id origin \
459 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
460 2>&1 | teescip-shell system . . tee. push.log
461 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 7 B" push.log
462
463 echoscip-shell system . . echo. "push b" > b.dat
464 gitscip-shell system . . git. add b.dat
465 gitscip-shell system . . git. commit -m "add b.dat"
466
467 gitscip-shell system . . git. lfs push --object-id origin \
468 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 \
469 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 \
470 2>&1 | teescip-shell system . . tee. push.log
471 grepscip-shell system . . 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="$(basenamescip-shell system . . basename. "$0" ".sh")"
480 setup_remote_repo "$reponame"
481 clone_repo "$reponame" repo3
482
483 gitscip-shell system . . git. config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" true
484
485 gitscip-shell system . . git. lfs track "*.dat"
486 echoscip-shell system . . echo. "push a" > a.dat
487 gitscip-shell system . . git. add .gitattributes a.dat
488 gitscip-shell system . . git. commit -m "add a.dat"
489
490 gitscip-shell system . . git. lfs push --object-id origin --stdin --dry-run </dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 | teescip-shell system . . tee. push.log
491 grepscip-shell system . . grep. "At least one object ID must be supplied with --object-id" push.log && exit 1
492
493 echoscip-shell system . . echo. "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340" | \
494 git lfs push --object-id origin --stdin --dry-run "c0ffee" \
495 2>&1 | teescip-shell system . . tee. push.log
496 grepscip-shell system . . grep. "Further command line arguments are ignored with --stdin" push.log
497
498 echoscip-shell system . . echo. "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340" | \
499 git lfs push --object-id origin --stdin --dry-run \
500 2>&1 | teescip-shell system . . tee. push.log
501 grepscip-shell system . . grep. "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 =>" push.log
502
503 echoscip-shell system . . echo. "push b" > b.dat
504 gitscip-shell system . . git. add b.dat
505 gitscip-shell system . . git. commit -m "add b.dat"
506
507 printfscip-shell system . . printf. "4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340\n82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7\n\n" | \
508 git lfs push --object-id origin --stdin --dry-run \
509 2>&1 | teescip-shell system . . tee. push.log
510 grepscip-shell system . . grep. "push 4c48d2a6991c9895bcddcf027e1e4907280bcf21975492b1afbade396d6a3340 =>" push.log
511 grepscip-shell system . . grep. "push 82be50ad35070a4ef3467a0a650c52d5b637035e7ad02c36652e59d01ba282b7 =>" push.log
512 )
513 end_test
514
515 begin_test "push modified files"
516 (
517 set -e
518
519 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-modified"
520 setup_remote_repo "$reponame"
521 clone_repo "$reponame" "$reponame"
522
523 gitscip-shell system . . 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 echoscip-shell system . . 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 gitscip-shell system . . git. lfs push origin main
563 gitscip-shell system . . 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 gitscip-shell system . . git. lfs push not-a-remote 2>&1 | teescip-shell system . . tee. push.log
577 grepscip-shell system . . 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="$(basenamescip-shell system . . basename. "$0" ".sh")-ambiguous-branch"
586 setup_remote_repo "$reponame"
587 clone_repo "$reponame" "$reponame"
588
589
590 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
591 grepscip-shell system . . 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 echoscip-shell system . . 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 gitscip-shell system . . git. tag ambiguous
629
630 # lfs push main, should work
631 gitscip-shell system . . git. lfs push origin main
632
633 # push ambiguous, does not fail since lfs scans git with sha, not ref name
634 gitscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
647 contents="return-expired-action"
648 contents_oid="$(calc_oid "$contents")"
649 contents_size="$(printfscip-shell system . . printf. "%s" "$contents" | wcscip-shell system . . wc. -c | awkscip-shell system . . awk. '{ print $1 }')"
650 printfscip-shell system . . printf. "%s" "$contents" > a.dat
651 gitscip-shell system . . git. add .gitattributes a.dat
652
653 gitscip-shell system . . git. commit -m "add a.dat, .gitattributes" 2>&1 | teescip-shell system . . tee. commit.log
654 grepscip-shell system . . grep. "main (root-commit)" commit.log
655 grepscip-shell system . . grep. "2 files changed" commit.log
656 grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log
657 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
658
659 GIT_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . 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 grepscip-shell system . . grep. "$expected" push.log
664 grepscip-shell system . . 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 mkdirscip-shell system . . mkdir. push-raw
674 cd push-raw
675 gitscip-shell system . . git. init
676
677 gitscip-shell system . . git. lfs track "*.dat"
678
679 contents="raw"
680 contents_oid=$(calc_oid "$contents")
681
682 printfscip-shell system . . printf. "%s" "$contents" > raw.dat
683 gitscip-shell system . . git. add raw.dat .gitattributes
684 gitscip-shell system . . git. commit -m "add" 2>&1 | teescip-shell system . . tee. commit.log
685 grepscip-shell system . . grep. "main (root-commit)" commit.log
686 grepscip-shell system . . grep. "2 files changed" commit.log
687 grepscip-shell system . . grep. "create mode 100644 raw.dat" commit.log
688 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
689
690 refute_server_object push-raw "$contents_oid"
691
692 gitscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
707 contents="return-invalid-size"
708 printfscip-shell system . . printf. "%s" "$contents" > a.dat
709
710 gitscip-shell system . . git. add a.dat .gitattributes
711 gitscip-shell system . . git. commit -m "add a.dat, .gitattributes" 2>&1 | teescip-shell system . . tee. commit.log
712 grepscip-shell system . . grep. "main (root-commit)" commit.log
713 grepscip-shell system . . grep. "2 files changed" commit.log
714 grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log
715 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
716
717 set +e
718 gitscip-shell system . . git. push origin main 2>&1 2> push.log
719 res="$?"
720 set -e
721
722 grepscip-shell system . . grep. "invalid size (got: -1)" push.log
723 [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "panic" push.log)" ]
724 [scip-shell system . . `[`. "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="$(basenamescip-shell system . . basename. "$0" ".sh")-deprecated"
735 setup_remote_repo "$reponame"
736 clone_repo "$reponame" "$reponame"
737
738 gitscip-shell system . . git. lfs track "*.dat"
739 gitscip-shell system . . git. add .gitattributes
740 gitscip-shell system . . git. commit -m "initial commit"
741
742 contents="send-deprecated-links"
743 contents_oid="$(calc_oid "$contents")"
744 printfscip-shell system . . printf. "%s" "$contents" > a.dat
745 gitscip-shell system . . git. add a.dat
746 gitscip-shell system . . git. commit -m "add a.dat"
747
748 gitscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_repo_setup(). "push-invalid-pushinsteadof"
759
760 # set pushInsteadOf to rewrite the href of uploading LFS object.
761 gitscip-shell system . . git. config url."$GITSERVER/storage/invalid".pushInsteadOf "$GITSERVER/storage/"
762 # Enable href rewriting explicitly.
763 gitscip-shell system . . git. config lfs.transfer.enablehrefrewrite true
764
765 set +e
766 gitscip-shell system . . git. lfs push origin main > push.log 2>&1
767 res=$?
768
769 set -e
770 [scip-shell system . . `[`. "$res" = "2" ]
771
772 # check rewritten href is used to upload LFS object.
773 grepscip-shell system . . grep. "LFS: Authorization error: $GITSERVER/storage/invalid" push.log
774
775 # lfs-push succeed after unsetting enableHrefRewrite config
776 gitscip-shell system . . git. config --unset lfs.transfer.enablehrefrewrite
777 gitscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
790 gitscip-shell system . . git. add .gitattributes
791 gitscip-shell system . . git. commit -m "initial commit"
792
793 contents="abc123"
794 contents_oid="$(calc_oid "$contents")"
795 printfscip-shell system . . printf. "%s" "$contents" > a.dat
796 gitscip-shell system . . git. add a.dat
797 gitscip-shell system . . git. commit -m "add a.dat"
798
799 gitscip-shell system . . git. push origin main
800
801 assert_server_object "$reponame" "$contents_oid"
802
803 gitscip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents2" > b.dat
811 gitscip-shell system . . git. add b.dat
812 gitscip-shell system . . 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 gitscip-shell system . . git. push "$(gitscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
836 gitscip-shell system . . git. add .gitattributes
837 gitscip-shell system . . git. commit -m "initial commit"
838
839 contents="abc123"
840 contents_oid="$(calc_oid "$contents")"
841 printfscip-shell system . . printf. "%s" "$contents" > a.dat
842 gitscip-shell system . . git. add a.dat
843 gitscip-shell system . . git. commit -m "add a.dat"
844
845 gitscip-shell system . . git. push origin main
846
847 assert_server_object "$reponame" "$contents_oid"
848
849 contents2="def456"
850 contents2_oid="$(calc_oid "$contents2")"
851 printfscip-shell system . . printf. "%s" "$contents2" > b.dat
852 gitscip-shell system . . git. add b.dat
853 gitscip-shell system . . 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 gitscip-shell system . . 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 "$(gitscip-shell system . . git. config remote.origin.url)" main v1.0.0 2>&1 | teescip-shell system . . 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 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
886 gitscip-shell system . . git. add .gitattributes
887 gitscip-shell system . . git. commit -m "initial commit"
888
889 contents="abc123"
890 contents_oid="$(calc_oid "$contents")"
891 printfscip-shell system . . printf. "%s" "$contents" > a.dat
892 gitscip-shell system . . git. add a.dat
893 gitscip-shell system . . git. commit -m "add a.dat"
894
895 gitscip-shell system . . git. tag v1.0.0
896
897 gitscip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents2" > b.dat
904 gitscip-shell system . . git. add b.dat
905 gitscip-shell system . . git. commit -m "add b.dat"
906
907 gitscip-shell system . . git. tag v1.0.1
908
909 gitscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat"
924 # generate content we'll use
925 content="filecontent"
926 oid=$(calc_oid "$content")
927
928 echoscip-shell system . . 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 gitscip-shell system . . git. update-ref refs/custom/remote/heads/main refs/heads/main
939
940 gitscip-shell system . . 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_setupscip-shell shell shell-project 0.0.0 push_all_setup(). "push-invalid-oid"
950
951 gitscip-shell system . . git. lfs push --object-id origin '' 2>&1 | teescip-shell system . . tee. push.log
952 gitscip-shell system . . git. lfs push --object-id origin "${oid1:0:3}" 2>&1 | teescip-shell system . . tee. -a push.log
953
954 [scip-shell system . . `[`. "$(grepscip-shell system . . grep. -c 'too short object ID' push.log)" -eq 2 ]
955 )
956 end_test