Debian Codegraph @

t/testhelpers.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # assert_pointer confirms that the pointer in the repository for $path in the
4 # given $ref matches the given $oid and $size.
5 # Note that $path is prepended with a space to match the against the start
6 # of path field in the ls-tree output, so be careful if your test involves
7 # files with spaces in their paths.
8 #
9 # $ assert_pointer "main" "path/to/file" "some-oid" 123
10 assert_pointerscip-shell shell shell-project 0.0.0 assert_pointer().() {
11 local ref="$1"
12 local path="$2"
13 local oid="$3"
14 local size="$4"
15
16 gitblob=$(gitscip-shell system . . git. ls-tree -lrz "$ref" |
17 while read -r -d $'\0' x; do
18 echoscip-shell system . . echo. $x
19 done |
20 grepscip-shell system . . grep. -F " $path" | cutscip-shell system . . cut. -f 3 -d " ")
21
22 actual=$(gitscip-shell system . . git. cat-file -p $gitblob)
23 expected=$(pointer $oid $size)
24
25 if [scip-shell system . . `[`. "$expected" != "$actual" ]; then
26 exit 1
27 fi
28 }
29
30 # refute_pointer confirms that the file in the repository for $path in the
31 # given $ref is _not_ a pointer.
32 # Note that $path is prepended with a space to match the against the start
33 # of path field in the ls-tree output, so be careful if your test involves
34 # files with spaces in their paths.
35 #
36 # $ refute_pointer "main" "path/to/file"
37 refute_pointerscip-shell shell shell-project 0.0.0 refute_pointer().() {
38 local ref="$1"
39 local path="$2"
40
41 gitblob=$(gitscip-shell system . . git. ls-tree -lrz "$ref" |
42 while read -r -d $'\0' x; do
43 echoscip-shell system . . echo. $x
44 done |
45 grepscip-shell system . . grep. -F " $path" | cutscip-shell system . . cut. -f 3 -d " ")
46
47 file=$(gitscip-shell system . . git. cat-file -p $gitblob)
48 version="version https://git-lfs.github.com/spec/v[0-9]"
49 oid="oid sha256:[0-9a-f]\{64\}"
50 size="size [0-9]*"
51 regex="$version.*$oid.*$size"
52
53 if echoscip-shell system . . echo. $file | grepscip-shell system . . grep. -q "$regex"; then
54 exit 1
55 fi
56 }
57
58 # local_object_path computes the path to the local storage for an oid
59 # $ local_object_path "some-oid"
60 local_object_pathscip-shell shell shell-project 0.0.0 local_object_path().() {
61 local oid="$1"
62 local cfg=`gitscip-shell system . . git. lfs env | grepscip-shell system . . grep. LocalMediaDir`
63 echoscip-shell system . . echo. "${cfg#LocalMediaDir=}/${oid:0:2}/${oid:2:2}/$oid"
64 }
65
66 # assert_local_object confirms that an object file is stored for the given oid &
67 # has the correct size
68 # $ assert_local_object "some-oid" size
69 assert_local_objectscip-shell shell shell-project 0.0.0 assert_local_object().() {
70 local oid="$1"
71 local size="$2"
72 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
73 actualsize=$(wcscip-shell system . . wc. -c <"$f" | trscip-shell system . . tr. -d '[[:space:]]')
74 if [scip-shell system . . `[`. "$size" != "$actualsize" ]; then
75 exit 1
76 fi
77 }
78
79 # is_valid_oid() confirms that an object ID is a valid SHA-256 hash, for use
80 # in our refute_*_object() functions which otherwise just check that an
81 # object file or record does not exist
82 is_valid_oidscip-shell shell shell-project 0.0.0 is_valid_oid().() {
83 local oid="$1"
84
85 printfscip-shell system . . printf. "%s" "$oid" | grepscip-shell system . . grep. -q "^[0-9a-f]\{64\}$"
86 }
87
88 # refute_local_object confirms that an object file is NOT stored for an oid.
89 # If "$size" is given as the second argument, assert that the file exists _and_
90 # that it does _not_ the expected size
91 #
92 # $ refute_local_object "some-oid"
93 # $ refute_local_object "some-oid" "123"
94 refute_local_objectscip-shell shell shell-project 0.0.0 refute_local_object().() {
95 local oid="$1"
96 local size="$2"
97
98 is_valid_oidscip-shell shell shell-project 0.0.0 is_valid_oid(). "$oid"
99
100 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
101 if [scip-shell system . . `[`. -e $f ]; then
102 if [scip-shell system . . `[`. -z "$size" ]; then
103 exit 1
104 fi
105
106 actual_size="$(wcscip-shell system . . wc. -c < "$f" | awkscip-shell system . . awk. '{ print $1 }')"
107 if [scip-shell system . . `[`. "$size" -eq "$actual_size" ]; then
108 echoscip-shell system . . echo. >&2 "fatal: expected object $oid not to have size: $size"
109 exit 1
110 fi
111 fi
112 }
113
114 # delete_local_object deletes the local storage for an oid
115 # $ delete_local_object "some-oid"
116 delete_local_objectscip-shell shell shell-project 0.0.0 delete_local_object().() {
117 local oid="$1"
118 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
119 # Note that so long as we do not use "rm -f" we do not need to first
120 # check that the object ID is valid or that file exists.
121 rmscip-shell system . . rm. "$f"
122 }
123
124 # corrupt_local_object corrupts the local storage for an oid
125 # $ corrupt_local_object "some-oid"
126 corrupt_local_objectscip-shell shell shell-project 0.0.0 corrupt_local_object().() {
127 local oid="$1"
128 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
129
130 [scip-shell system . . `[`. -f "$f" ]
131 cpscip-shell system . . cp. /dev/nullscip-shell filesystem . . `/dev/null`. "$f"
132 }
133
134
135 # check that the object does not exist in the git lfs server. HTTP log is
136 # written to http.log. JSON output is written to http.json.
137 #
138 # $ refute_server_object "reponame" "oid"
139 refute_server_objectscip-shell shell shell-project 0.0.0 refute_server_object().() {
140 local reponame="$1"
141 local oid="$2"
142
143 [scip-shell system . . `[`. -d "$(canonical_path "$REMOTEDIR/$reponame.git")" ]
144 is_valid_oidscip-shell shell shell-project 0.0.0 is_valid_oid(). "$oid"
145
146 curlscip-shell system . . curl. -v "$GITSERVER/$reponame.git/info/lfs/objects/batch" \
147 -u "user:pass" \
148 -o http.json \
149 -d "{\"operation\":\"download\",\"objects\":[{\"oid\":\"$oid\"}]}" \
150 -H "Accept: application/vnd.git-lfs+json" \
151 -H "Content-Type: application/vnd.git-lfs+json" \
152 -H "X-Check-Object: 1" \
153 -H "X-Ignore-Retries: true" 2>&1 |
154 teescip-shell system . . tee. http.log
155
156 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "download" http.json)" ] || {
157 catscip-shell system . . cat. http.json
158 exit 1
159 }
160 }
161
162 # Delete an object on the lfs server. HTTP log is
163 # written to http.log. JSON output is written to http.json.
164 #
165 # $ delete_server_object "reponame" "oid"
166 delete_server_objectscip-shell shell shell-project 0.0.0 delete_server_object().() {
167 local reponame="$1"
168 local oid="$2"
169
170 [scip-shell system . . `[`. -d "$(canonical_path "$REMOTEDIR/$reponame.git")" ]
171 is_valid_oidscip-shell shell shell-project 0.0.0 is_valid_oid(). "$oid"
172
173 curlscip-shell system . . curl. -v "$GITSERVER/$reponame.git/info/lfs/objects/$oid" \
174 -X DELETE \
175 -u "user:pass" \
176 -o http.json \
177 -H "Accept: application/vnd.git-lfs+json" 2>&1 |
178 teescip-shell system . . tee. http.log
179
180 grepscip-shell system . . grep. "200 OK" http.log
181 }
182
183 # check that the object does exist in the git lfs server. HTTP log is written
184 # to http.log. JSON output is written to http.json.
185 assert_server_objectscip-shell shell shell-project 0.0.0 assert_server_object().() {
186 local reponame="$1"
187 local oid="$2"
188 local refspec="$3"
189 curlscip-shell system . . curl. -v "$GITSERVER/$reponame.git/info/lfs/objects/batch" \
190 -u "user:pass" \
191 -o http.json \
192 -d "{\"operation\":\"download\",\"objects\":[{\"oid\":\"$oid\"}],\"ref\":{\"name\":\"$refspec\"}}" \
193 -H "Accept: application/vnd.git-lfs+json" \
194 -H "Content-Type: application/vnd.git-lfs+json" \
195 -H "X-Check-Object: 1" \
196 -H "X-Ignore-Retries: true" 2>&1 |
197 teescip-shell system . . tee. http.log
198 grepscip-shell system . . grep. "200 OK" http.log
199
200 grepscip-shell system . . grep. "download" http.json || {
201 catscip-shell system . . cat. http.json
202 exit 1
203 }
204 }
205
206 # assert_remote_object() confirms that an object file with the given OID and
207 # size is stored in the "remote" copy of a repository
208 assert_remote_objectscip-shell shell shell-project 0.0.0 assert_remote_object().() {
209 local reponame="$1"
210 local oid="$2"
211 local size="$3"
212 local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
213
214 pushd "$destination"
215 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
216 actualsize="$(wcscip-shell system . . wc. -c <"$f" | trscip-shell system . . tr. -d '[[:space:]]')"
217 [scip-shell system . . `[`. "$size" -eq "$actualsize" ]
218 popd
219 }
220
221 # refute_remote_object() confirms that an object file with the given OID
222 # is not stored in the "remote" copy of a repository
223 refute_remote_objectscip-shell shell shell-project 0.0.0 refute_remote_object().() {
224 local reponame="$1"
225 local oid="$2"
226
227 is_valid_oidscip-shell shell shell-project 0.0.0 is_valid_oid(). "$oid"
228
229 local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
230
231 pushd "$destination"
232 local f="$(local_object_pathscip-shell shell shell-project 0.0.0 local_object_path(). "$oid")"
233 if [scip-shell system . . `[`. -e $f ]; then
234 exit 1
235 fi
236 popd
237 }
238
239 # Set rate limit counts on the LFS server. HTTP log is written to http.log.
240 #
241 # $ reset_server_rate_limit "api" "direction" "reponame" "oid" "num-tokens"
242 set_server_rate_limitscip-shell shell shell-project 0.0.0 set_server_rate_limit().() {
243 local api="$1"
244 local direction="$2"
245 local reponame="$3"
246 local oid="$4"
247 local tokens="$5"
248
249 local query="api=$api&direction=$direction&repo=$reponame&oid=$oid&tokens=$tokens"
250
251 curlscip-shell system . . curl. -v "$GITSERVER/limits/?$query" 2>&1 | teescip-shell system . . tee. http.log
252
253 grepscip-shell system . . grep. "200 OK" http.log
254 }
255
256 check_server_lock_sshscip-shell shell shell-project 0.0.0 check_server_lock_ssh().() {
257 local reponame="$1"
258 local id="$2"
259 local refspec="$3"
260 local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
261
262 (
263 pktize_textscip-shell shell shell-project 0.0.0 pktize_text(). 'version 1'
264 pktize_flushscip-shell shell shell-project 0.0.0 pktize_flush().
265 pktize_textscip-shell shell shell-project 0.0.0 pktize_text(). 'list-lock'
266 pktize_textscip-shell shell shell-project 0.0.0 pktize_text(). "id=$id"
267 pktize_textscip-shell shell shell-project 0.0.0 pktize_text(). "refname=$refname"
268 pktize_flushscip-shell shell shell-project 0.0.0 pktize_flush().
269 pktize_textscip-shell shell shell-project 0.0.0 pktize_text(). 'quit'
270 pktize_flushscip-shell shell shell-project 0.0.0 pktize_flush().
271 ) | lfs-ssh-echo [email protected] "git-lfs-transfer '$destination' download" 2>&1
272 }
273
274 # This asserts the lock path and returns the lock ID by parsing the response of
275 #
276 # git lfs lock --json <path>
277 assert_lockscip-shell shell shell-project 0.0.0 assert_lock().() {
278 local log="$1"
279 local path="$2"
280
281 if [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "\"path\":\"$path\"" "$log") -eq 0 ]; then
282 echoscip-shell system . . echo. "path '$path' not found in:"
283 catscip-shell system . . cat. "$log"
284 exit 1
285 fi
286
287 local jsonid=$(grepscip-shell system . . grep. -oh "\"id\":\"\w\+\"" "$log")
288 echoscip-shell system . . echo. "${jsonid:3}" | trscip-shell system . . tr. -d \"\:
289 }
290
291 # assert that a lock with the given ID exists on the test server
292 assert_server_lockscip-shell shell shell-project 0.0.0 assert_server_lock().() {
293 local reponame="$1"
294 local id="$2"
295 local refspec="$3"
296
297 curlscip-shell system . . curl. -v "$GITSERVER/$reponame.git/info/lfs/locks?refspec=$refspec" \
298 -u "user:pass" \
299 -o http.json \
300 -H "Accept:application/vnd.git-lfs+json" 2>&1 |
301 teescip-shell system . . tee. http.log
302
303 grepscip-shell system . . grep. "200 OK" http.log
304 grepscip-shell system . . grep. "$id" http.json || {
305 catscip-shell system . . cat. http.json
306 exit 1
307 }
308 }
309
310 # assert that a lock with the given ID exists on the test server
311 assert_server_lock_sshscip-shell shell shell-project 0.0.0 assert_server_lock_ssh().() {
312 local reponame="$1"
313 local id="$2"
314 local refspec="$3"
315
316 check_server_lock_sshscip-shell shell shell-project 0.0.0 check_server_lock_ssh(). "$reponame" "$id" "$refspec" |
317 teescip-shell system . . tee. output.log
318
319 grepscip-shell system . . grep. "status 200" output.log
320 grepscip-shell system . . grep. "$id" output.log || {
321 catscip-shell system . . cat. output.log
322 exit 1
323 }
324 }
325
326 # refute that a lock with the given ID exists on the test server
327 refute_server_lockscip-shell shell shell-project 0.0.0 refute_server_lock().() {
328 local reponame="$1"
329 local id="$2"
330 local refspec="$3"
331
332 curlscip-shell system . . curl. -v "$GITSERVER/$reponame.git/info/lfs/locks?refspec=$refspec" \
333 -u "user:pass" \
334 -o http.json \
335 -H "Accept:application/vnd.git-lfs+json" 2>&1 | teescip-shell system . . tee. http.log
336
337 grepscip-shell system . . grep. "200 OK" http.log
338
339 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "$id" http.json) -eq 0 ]
340 }
341
342 # refute that a lock with the given ID exists on the test server
343 refute_server_lock_sshscip-shell shell shell-project 0.0.0 refute_server_lock_ssh().() {
344 local reponame="$1"
345 local id="$2"
346 local refspec="$3"
347 local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
348
349 check_server_lock_sshscip-shell shell shell-project 0.0.0 check_server_lock_ssh(). "$reponame" "$id" "$refspec" |
350 teescip-shell system . . tee. output.log
351
352 grepscip-shell system . . grep. "status 200" output.log
353 if grepscip-shell system . . grep. "$id" output.log
354 then
355 catscip-shell system . . cat. output.log
356 exit 1
357 fi
358 }
359
360 # Assert that .gitattributes contains a given attribute N times
361 assert_attributes_countscip-shell shell shell-project 0.0.0 assert_attributes_count().() {
362 local fileext="$1"
363 local attrib="$2"
364 local count="$3"
365
366 pattern="\(*.\)\?$fileext\(.*\)$attrib"
367 actual="$(grepscip-shell system . . grep. -c -e "$pattern" .gitattributes || truescip-shell system . . true.)"
368 if [scip-shell system . . `[`. "$(printfscip-shell system . . printf. "%d" "$actual")" -ne "$count" ]; then
369 echoscip-shell system . . echo. "wrong number of $attrib entries for $fileext"
370 echoscip-shell system . . echo. "expected: $count actual: $actual"
371 catscip-shell system . . cat. .gitattributes
372 exit 1
373 fi
374 }
375
376 assert_file_writeablescip-shell shell shell-project 0.0.0 assert_file_writeable().() {
377 lsscip-shell system . . ls. -l "$1" | grepscip-shell system . . grep. -e "^-rw"
378 }
379
380 refute_file_writeablescip-shell shell shell-project 0.0.0 refute_file_writeable().() {
381 lsscip-shell system . . ls. -l "$1" | grepscip-shell system . . grep. -e "^-r-"
382 }
383
384 git_rootscip-shell shell shell-project 0.0.0 git_root().() {
385 gitscip-shell system . . git. rev-parse --show-toplevel 2>/dev/nullscip-shell filesystem . . `/dev/null`.
386 }
387
388 dot_git_dirscip-shell shell shell-project 0.0.0 dot_git_dir().() {
389 echoscip-shell system . . echo. "$(git_rootscip-shell shell shell-project 0.0.0 git_root().)/.git"
390 }
391
392 assert_hooksscip-shell shell shell-project 0.0.0 assert_hooks().() {
393 local git_root="$1"
394
395 if [scip-shell system . . `[`. -z "$git_root" ]; then
396 echoscip-shell system . . echo. >&2 "fatal: (assert_hooks) not in git repository"
397 exit 1
398 fi
399
400 [scip-shell system . . `[`. -x "$git_root/hooks/post-checkout" ]
401 [scip-shell system . . `[`. -x "$git_root/hooks/post-commit" ]
402 [scip-shell system . . `[`. -x "$git_root/hooks/post-merge" ]
403 [scip-shell system . . `[`. -x "$git_root/hooks/pre-push" ]
404 }
405
406 assert_clean_indexscip-shell shell shell-project 0.0.0 assert_clean_index().() {
407 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. diff-index --cached HEAD)" ]
408 }
409
410 assert_clean_worktreescip-shell shell shell-project 0.0.0 assert_clean_worktree().() {
411 [scip-shell system . . `[`. -z "$(gitscip-shell system . . git. diff-index HEAD)" ]
412 }
413
414 assert_clean_worktree_with_exceptionsscip-shell shell shell-project 0.0.0 assert_clean_worktree_with_exceptions().() {
415 local exceptions="$1"
416
417 [scip-shell system . . `[`. 0 -eq "$(gitscip-shell system . . git. diff-index HEAD | grepscip-shell system . . grep. -c -v -E "$exceptions")" ]
418 }
419
420 assert_clean_statusscip-shell shell shell-project 0.0.0 assert_clean_status().() {
421 assert_clean_worktreescip-shell shell shell-project 0.0.0 assert_clean_worktree().
422
423 status="$(gitscip-shell system . . git. status)"
424 echoscip-shell system . . echo. "$status" | grepscip-shell system . . grep. "working \(directory\|tree\) clean" || {
425 echoscip-shell system . . echo. $status
426 gitscip-shell system . . git. lfs status
427 exit 1
428 }
429 }
430
431 # pointer returns a string Git LFS pointer file.
432 #
433 # $ pointer abc-some-oid 123 <version>
434 # > version ...
435 pointerscip-shell shell shell-project 0.0.0 pointer().() {
436 local oid=$1
437 local size=$2
438 local version=${3:-https://git-lfs.github.com/spec/v1}
439 printfscip-shell system . . printf. "version %s
440 oid sha256:%s
441 size %s
442 " "$version" "$oid" "$size"
443 }
444
445 # wait_for_file simply sleeps until a file exists.
446 #
447 # $ wait_for_file "path/to/upcoming/file"
448 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file().() {
449 local filename="$1"
450 n=0
451 wait_time=1
452 while [scip-shell system . . `[`. $n -lt 17 ]; do
453 if [scip-shell system . . `[`. -s $filename ]; then
454 return 0
455 fi
456
457 sleepscip-shell system . . sleep. $wait_time
458 n=`exprscip-shell system . . expr. $n + 1`
459 if [scip-shell system . . `[`. $wait_time -lt 4 ]; then
460 wait_time=`exprscip-shell system . . expr. $wait_time \* 2`
461 fi
462 done
463
464 echoscip-shell system . . echo. "$filename did not appear after 60 seconds."
465 return 1
466 }
467
468 # setup_remote_repo initializes a bare Git repository that is accessible through
469 # the test Git server. The `pwd` is set to the repository's directory, in case
470 # further commands need to be run. This server is running for every test in an
471 # integration run, so every test file should setup its own remote repository to
472 # avoid conflicts.
473 #
474 # $ setup_remote_repo "some-name"
475 #
476 setup_remote_reposcip-shell shell shell-project 0.0.0 setup_remote_repo().() {
477 local reponame="$1"
478 echoscip-shell system . . echo. "set up remote git repository: $reponame"
479 repodir="$REMOTEDIR/$reponame.git"
480 mkdirscip-shell system . . mkdir. -p "$repodir"
481 cd "$repodir"
482 gitscip-shell system . . git. init --bare
483 gitscip-shell system . . git. config http.receivepack true
484 gitscip-shell system . . git. config receive.denyCurrentBranch ignore
485 }
486
487 # creates a bare remote repository for a local clone. Useful to test pushing to
488 # a fresh remote server.
489 #
490 # $ setup_alternate_remote "$reponame-whatever"
491 # $ setup_alternate_remote "$reponame-whatever" "other-remote-name"
492 #
493 setup_alternate_remotescip-shell shell shell-project 0.0.0 setup_alternate_remote().() {
494 local newRemoteName=$1
495 local remote=${2:-origin}
496
497 wd=`pwdscip-shell system . . pwd.`
498
499 setup_remote_reposcip-shell shell shell-project 0.0.0 setup_remote_repo(). "$newRemoteName"
500 cd $wd
501 gitscip-shell system . . git. remote rm "$remote"
502 gitscip-shell system . . git. remote add "$remote" "$GITSERVER/$newRemoteName"
503 }
504
505 # clone_repo clones a repository from the test Git server to the subdirectory
506 # $dir under $TRASHDIR. setup_remote_repo() needs to be run first. Output is
507 # written to clone.log.
508 clone_reposcip-shell shell shell-project 0.0.0 clone_repo().() {
509 cd "$TRASHDIR"
510
511 local reponame="$1"
512 local dir="$2"
513 echoscip-shell system . . echo. "clone local git repository $reponame to $dir"
514 gitscip-shell system . . git. clone "$GITSERVER/$reponame" "$dir" 2>&1 | teescip-shell system . . tee. clone.log
515
516 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
517 return 1
518 fi
519
520 cd "$dir"
521 mvscip-shell system . . mv. ../clone.log .
522
523 gitscip-shell system . . git. config credential.helper lfstest
524 }
525
526 # clone_repo_url clones a Git repository to the subdirectory $dir under $TRASHDIR.
527 # setup_remote_repo() needs to be run first. Output is written to clone.log.
528 clone_repo_urlscip-shell shell shell-project 0.0.0 clone_repo_url().() {
529 cd "$TRASHDIR"
530
531 local repo="$1"
532 local dir="$2"
533 echoscip-shell system . . echo. "clone git repository $repo to $dir"
534 gitscip-shell system . . git. clone "$repo" "$dir" 2>&1 | teescip-shell system . . tee. clone.log
535
536 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
537 return 1
538 fi
539
540 cd "$dir"
541 mvscip-shell system . . mv. ../clone.log .
542
543 gitscip-shell system . . git. config credential.helper lfstest
544 }
545
546 # clone_repo_ssl clones a repository from the test Git server to the subdirectory
547 # $dir under $TRASHDIR, using the SSL endpoint.
548 # setup_remote_repo() needs to be run first. Output is written to clone_ssl.log.
549 clone_repo_sslscip-shell shell shell-project 0.0.0 clone_repo_ssl().() {
550 cd "$TRASHDIR"
551
552 local reponame="$1"
553 local dir="$2"
554 echoscip-shell system . . echo. "clone local git repository $reponame to $dir"
555 gitscip-shell system . . git. clone "$SSLGITSERVER/$reponame" "$dir" 2>&1 | teescip-shell system . . tee. clone_ssl.log
556
557 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
558 return 1
559 fi
560
561 cd "$dir"
562 mvscip-shell system . . mv. ../clone_ssl.log .
563
564 gitscip-shell system . . git. config credential.helper lfstest
565 }
566
567 # clone_repo_clientcert clones a repository from the test Git server to the subdirectory
568 # $dir under $TRASHDIR, using the client cert endpoint.
569 # setup_remote_repo() needs to be run first. Output is written to clone_client_cert.log.
570 clone_repo_clientcertscip-shell shell shell-project 0.0.0 clone_repo_clientcert().() {
571 cd "$TRASHDIR"
572
573 local reponame="$1"
574 local dir="$2"
575 echoscip-shell system . . echo. "clone $CLIENTCERTGITSERVER/$reponame to $dir"
576 gitscip-shell system . . git. clone "$CLIENTCERTGITSERVER/$reponame" "$dir" 2>&1 | teescip-shell system . . tee. clone_client_cert.log
577
578 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
579 return 1
580 fi
581
582 cd "$dir"
583 mvscip-shell system . . mv. ../clone_client_cert.log .
584
585 gitscip-shell system . . git. config credential.helper lfstest
586 }
587
588 # setup_remote_repo_with_file creates a remote repo, clones it locally, commits
589 # a file tracked by LFS, and pushes it to the remote:
590 #
591 # setup_remote_repo_with_file "reponame" "filename"
592 setup_remote_repo_with_filescip-shell shell shell-project 0.0.0 setup_remote_repo_with_file().() {
593 local reponame="$1"
594 local filename="$2"
595 local dirname="$(dirnamescip-shell system . . dirname. "$filename")"
596
597 setup_remote_reposcip-shell shell shell-project 0.0.0 setup_remote_repo(). "$reponame"
598 clone_reposcip-shell shell shell-project 0.0.0 clone_repo(). "$reponame" "clone_$reponame"
599
600 mkdirscip-shell system . . mkdir. -p "$dirname"
601
602 gitscip-shell system . . git. lfs track "$filename"
603 echoscip-shell system . . echo. "$filename" > "$filename"
604 gitscip-shell system . . git. add .gitattributes $filename
605 gitscip-shell system . . git. commit -m "add $filename" | teescip-shell system . . tee. commit.log
606
607 grepscip-shell system . . grep. "main (root-commit)" commit.log
608 grepscip-shell system . . grep. "2 files changed" commit.log
609 grepscip-shell system . . grep. "create mode 100644 $filename" commit.log
610 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
611
612 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
613 grepscip-shell system . . grep. "main -> main" push.log
614 }
615
616 # substring_position returns the position of a substring in a 1-indexed search
617 # space.
618 #
619 # [ "$(substring_position "foo bar baz" "baz")" -eq "9" ]
620 substring_positionscip-shell shell shell-project 0.0.0 substring_position().() {
621 local str="$1"
622 local substr="$2"
623
624 # 1) Print the string...
625 # 2) Remove the substring and everything after it
626 # 3) Count the number of characters (bytes) left, i.e., the offset of the
627 # string we were looking for.
628
629 echoscip-shell system . . echo. "$str" \
630 | sedscip-shell system . . sed. "s/$substr.*$//" \
631 | wcscip-shell system . . wc. -c
632 }
633
634 # repo_endpoint returns the LFS endpoint for a given server and repository.
635 #
636 # [ "$GITSERVER/example/repo.git/info/lfs" = "$(repo_endpoint $GITSERVER example-repo)" ]
637 repo_endpointscip-shell shell shell-project 0.0.0 repo_endpoint().() {
638 local server="$1"
639 local repo="$2"
640
641 echoscip-shell system . . echo. "$server/$repo.git/info/lfs"
642 }
643
644 # write_creds_file writes credentials to a file iff it doesn't exist.
645 write_creds_filescip-shell shell shell-project 0.0.0 write_creds_file().() {
646 local creds="$1"
647 local file="$2"
648
649 if [scip-shell system . . `[`. ! -f "$file" ]
650 then
651 printfscip-shell system . . printf. "%s" "$creds" > "$file"
652 fi
653 }
654
655 setup_credsscip-shell shell shell-project 0.0.0 setup_creds().() {
656 mkdirscip-shell system . . mkdir. -p "$CREDSDIR"
657 write_creds_filescip-shell shell shell-project 0.0.0 write_creds_file(). ":user:pass" "$CREDSDIR/127.0.0.1"
658 }
659
660 # setup initializes the clean, isolated environment for integration tests.
661 setupscip-shell shell shell-project 0.0.0 setup().() {
662 cd "$ROOTDIR"
663
664 if [scip-shell system . . `[`. ! -d "$REMOTEDIR" ]; then
665 mkdirscip-shell system . . mkdir. "$REMOTEDIR"
666 fi
667
668 echoscip-shell system . . echo. "# Git LFS: ${LFS_BIN:-$(command -v git-lfs)}"
669 gitscip-shell system . . git. lfs version | sedscip-shell system . . sed. -e 's/^/# /g'
670 gitscip-shell system . . git. version | sedscip-shell system . . sed. -e 's/^/# /g'
671
672 LFSTEST_URL="$LFS_URL_FILE" \
673 LFSTEST_SSL_URL="$LFS_SSL_URL_FILE" \
674 LFSTEST_CLIENT_CERT_URL="$LFS_CLIENT_CERT_URL_FILE" \
675 LFSTEST_DIR="$REMOTEDIR" \
676 LFSTEST_CERT="$LFS_CERT_FILE" \
677 LFSTEST_CLIENT_CERT="$LFS_CLIENT_CERT_FILE" \
678 LFSTEST_CLIENT_KEY="$LFS_CLIENT_KEY_FILE" \
679 LFSTEST_CLIENT_KEY_ENCRYPTED="$LFS_CLIENT_KEY_FILE_ENCRYPTED" \
680 lfstest-count-tests increment
681
682 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_URL_FILE"
683 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_SSL_URL_FILE"
684 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_CLIENT_CERT_URL_FILE"
685 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_CERT_FILE"
686 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_CLIENT_CERT_FILE"
687 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_CLIENT_KEY_FILE"
688 wait_for_filescip-shell shell shell-project 0.0.0 wait_for_file(). "$LFS_CLIENT_KEY_FILE_ENCRYPTED"
689
690 LFS_CLIENT_CERT_URL=`catscip-shell system . . cat. $LFS_CLIENT_CERT_URL_FILE`
691
692 # Set up the initial git config and osx keychain if applicable
693 HOME="$TESTHOME"
694 if [scip-shell system . . `[`. ! -d "$HOME" ]; then
695 mkdirscip-shell system . . mkdir. "$HOME"
696 fi
697
698 # do not let Git use a different configuration file
699 unset GIT_CONFIG
700 unset XDG_CONFIG_HOME
701
702 if [scip-shell system . . `[`. ! -f $HOME/.gitconfig ]; then
703 gitscip-shell system . . git. lfs install --skip-repo
704 gitscip-shell system . . git. config --global credential.usehttppath true
705 gitscip-shell system . . git. config --global credential.helper lfstest
706 gitscip-shell system . . git. config --global user.name "Git LFS Tests"
707 gitscip-shell system . . git. config --global user.email "[email protected]"
708 gitscip-shell system . . git. config --global http.sslcainfo "$LFS_CERT_FILE"
709 gitscip-shell system . . git. config --global init.defaultBranch main
710 fi | sedscip-shell system . . sed. -e 's/^/# /g'
711
712 # setup the git credential password storage
713 setup_credsscip-shell shell shell-project 0.0.0 setup_creds().
714
715 echoscip-shell system . . echo. "#"
716 echoscip-shell system . . echo. "# HOME: $HOME"
717 echoscip-shell system . . echo. "# TMP: $TMPDIR"
718 echoscip-shell system . . echo. "# CREDS: $CREDSDIR"
719 echoscip-shell system . . echo. "# lfstest-gitserver:"
720 echoscip-shell system . . echo. "# LFSTEST_URL=$LFS_URL_FILE"
721 echoscip-shell system . . echo. "# LFSTEST_SSL_URL=$LFS_SSL_URL_FILE"
722 echoscip-shell system . . echo. "# LFSTEST_CLIENT_CERT_URL=$LFS_CLIENT_CERT_URL_FILE ($LFS_CLIENT_CERT_URL)"
723 echoscip-shell system . . echo. "# LFSTEST_CERT=$LFS_CERT_FILE"
724 echoscip-shell system . . echo. "# LFSTEST_CLIENT_CERT=$LFS_CLIENT_CERT_FILE"
725 echoscip-shell system . . echo. "# LFSTEST_CLIENT_KEY=$LFS_CLIENT_KEY_FILE"
726 echoscip-shell system . . echo. "# LFSTEST_CLIENT_KEY_ENCRYPTED=$LFS_CLIENT_KEY_FILE_ENCRYPTED"
727 echoscip-shell system . . echo. "# LFSTEST_DIR=$REMOTEDIR"
728 }
729
730 # shutdown cleans the $TRASHDIR and shuts the test Git server down.
731 shutdownscip-shell shell shell-project 0.0.0 shutdown().() {
732 # every t/t-*.sh file should cleanup its trashdir
733 [scip-shell system . . `[`. -z "$KEEPTRASH" ] && rmscip-shell system . . rm. -rf "$TRASHDIR"
734
735 LFSTEST_DIR="$REMOTEDIR" \
736 LFS_URL_FILE="$LFS_URL_FILE" \
737 lfstest-count-tests decrement
738
739 # delete entire lfs test root if we created it (double check pattern)
740 if [scip-shell system . . `[`. -z "$KEEPTRASH" ] && [scip-shell system . . `[`. "$RM_GIT_LFS_TEST_DIR" = "yes" ] && [[ $GIT_LFS_TEST_DIR == *"$TEMPDIR_PREFIX"* ]]; then
741 rmscip-shell system . . rm. -rf "$GIT_LFS_TEST_DIR"
742 fi
743 }
744
745 tap_show_planscip-shell shell shell-project 0.0.0 tap_show_plan().() {
746 local tests="$1"
747
748 printfscip-shell system . . printf. "1..%i\n" "$tests"
749 }
750
751 skip_if_root_or_adminscip-shell shell shell-project 0.0.0 skip_if_root_or_admin().() {
752 local test_description="$1"
753
754 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
755 # The sfc.exe (System File Checker) command should be available on all
756 # modern Windows systems, and when run without arguments, returns help
757 # text, but only when the user has Administrator privileges. By checking
758 # the help text, if any, for the /SCANNOW (i.e., "scan now") option
759 # common to all versions of the command, we can determine if the
760 # current user has Administrator privileges.
761 #
762 # Adapted from: https://stackoverflow.com/a/58846650
763 # https://stackoverflow.com/a/21295806
764 SFC=$(sfc | trscip-shell system . . tr. -d '\0' | grepscip-shell system . . grep. "SCANNOW")
765 if [scip-shell system . . `[`. -n "$SFC" ]; then
766 prscip-shell system . . printf.intfscip-shell system . . printf. "skip: '%s' test requires non-administrator privileges\n" \
767 "$test_description"
768 exit 0
769 fi
770 elif [scip-shell system . . `[`. "$EUID" -eq 0 ]; then
771 printfscip-shell system . . printf. "skip: '%s' test requires non-root user\n" "$test_description"
772 exit 0
773 fi
774 }
775
776 ensure_git_version_isntscip-shell shell shell-project 0.0.0 ensure_git_version_isnt().() {
777 local expectedComparison=$1
778 local version=$2
779
780 local gitVersion=$(gitscip-shell system . . git. version | cutscip-shell system . . cut. -d" " -f3)
781
782 set +e
783 compare_versionscip-shell shell shell-project 0.0.0 compare_version(). $gitVersion $version
784 result=$?
785 set -e
786
787 if [[ $result == $expectedComparison ]]; then
788 echoscip-shell system . . echo. "skip: $0 (git version $(comparison_to_operator $expectedComparison) $version)"
789 exit
790 fi
791 }
792
793 VERSION_EQUAL=0
794 VERSION_HIGHER=1
795 VERSION_LOWER=2
796
797 # Compare $1 and $2 and return VERSION_EQUAL / VERSION_LOWER / VERSION_HIGHER
798 compare_versionscip-shell shell shell-project 0.0.0 compare_version().() {
799 if [[ $1 == $2 ]]
800 then
801 return $VERSION_EQUAL
802 fi
803 local IFS=.
804 local i ver1=($1) ver2=($2)
805 # fill empty fields in ver1 with zeros
806 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
807 do
808 ver1[i]=0
809 done
810 for ((i=0; i<${#ver1[@]}; i++))
811 do
812 if [[ -z ${ver2[i]} ]]
813 then
814 # fill empty fields in ver2 with zeros
815 ver2[i]=0
816 fi
817 if ((10#${ver1[i]} > 10#${ver2[i]}))
818 then
819 return $VERSION_HIGHER
820 fi
821 if ((10#${ver1[i]} < 10#${ver2[i]}))
822 then
823 return $VERSION_LOWER
824 fi
825 done
826 return $VERSION_EQUAL
827 }
828
829 comparison_to_operatorscip-shell shell shell-project 0.0.0 comparison_to_operator().() {
830 local comparison=$1
831 if [[ $1 == $VERSION_EQUAL ]]; then
832 echoscip-shell system . . echo. "=="
833 elif [[ $1 == $VERSION_HIGHER ]]; then
834 echoscip-shell system . . echo. ">"
835 elif [[ $1 == $VERSION_LOWER ]]; then
836 echoscip-shell system . . echo. "<"
837 else
838 echoscip-shell system . . echo. "???"
839 fi
840 }
841
842 # Calculate the object ID from the string passed as the argument
843 calc_oidscip-shell shell shell-project 0.0.0 calc_oid().() {
844 printfscip-shell system . . printf. "%s" "$1" | $SHASUM | cutscip-shell system . . cut. -f 1 -d " "
845 }
846
847 # Calculate the object ID from the file passed as the argument
848 calc_oid_filescip-shell shell shell-project 0.0.0 calc_oid_file().() {
849 $SHASUM "$1" | cutscip-shell system . . cut. -f 1 -d " "
850 }
851
852 # Get a date string with an offset
853 # Args: One or more date offsets of the form (regex) "[+-]\d+[dmyHM]"
854 # e.g. +1d = 1 day forward from today
855 # -5y = 5 years before today
856 # Example call:
857 # D=$(get_date +1y +1m -5H)
858 # returns date as string in RFC3339 format ccyy-mm-ddThh:MM:ssZ
859 # note returns in UTC time not local time hence Z and not +/-
860 get_datescip-shell shell shell-project 0.0.0 get_date().() {
861 # Wrapped because BSD (inc OSX) & GNU 'date' functions are different
862 # on Windows under Git Bash it's GNU
863 if datescip-shell system . . date. --version >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then # GNU
864 ARGS=""
865 for var in "$@"
866 do
867 # GNU offsets are more verbose
868 unit=${var: -1}
869 val=${var:0:${#var}-1}
870 case "$unit" in
871 d) unit="days" ;;
872 m) unit="months" ;;
873 y) unit="years" ;;
874 H) unit="hours" ;;
875 M) unit="minutes" ;;
876 esac
877 ARGS="$ARGS $val $unit"
878 done
879 datescip-shell system . . date. -d "$ARGS" -u +%Y-%m-%dT%TZ
880 else # BSD
881 ARGS=""
882 for var in "$@"
883 do
884 ARGS="$ARGS -v$var"
885 done
886 datescip-shell system . . date. $ARGS -u +%Y-%m-%dT%TZ
887 fi
888 }
889
890 # escape any instance of '\' with '\\' on Windows
891 escape_pathscip-shell shell shell-project 0.0.0 escape_path().() {
892 local unescaped="$1"
893 if [scip-shell system . . `[`. $IS_WINDOWS -eq 1 ]; then
894 printfscip-shell system . . printf. '%s' "${unescaped//\\/\\\\}"
895 else
896 printfscip-shell system . . printf. '%s' "$unescaped"
897 fi
898 }
899
900 # As native_path but escape all backslash characters to "\\"
901 native_path_escapedscip-shell shell shell-project 0.0.0 native_path_escaped().() {
902 local unescaped=$(native_path "$1")
903 escape_pathscip-shell shell shell-project 0.0.0 escape_path(). "$unescaped"
904 }
905
906 # native_path_list_separator prints the operating system-specific path list
907 # separator.
908 native_path_list_separatorscip-shell shell shell-project 0.0.0 native_path_list_separator().() {
909 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
910 printfscip-shell system . . printf. ";";
911 else
912 printfscip-shell system . . printf. ":";
913 fi
914 }
915
916 # canonical_path prints the native path name in a canonical form, as if
917 # realpath(3) were called on it.
918 canonical_pathscip-shell shell shell-project 0.0.0 canonical_path().() {
919 printfscip-shell system . . printf. "%s" "$(lfstest-realpath "$(native_path "$1")")"
920 }
921
922 # canonical_path_escaped prints the native path name in a canonical form, as if
923 # realpath(3) were called on it, and then escapes it.
924 canonical_path_escapedscip-shell shell shell-project 0.0.0 canonical_path_escaped().() {
925 printfscip-shell system . . printf. "%s" "$(escape_pathscip-shell shell shell-project 0.0.0 escape_path(). "$(lfstest-realpath "$(native_path "$1")")")"
926 }
927
928 cat_endscip-shell shell shell-project 0.0.0 cat_end().() {
929 if [scip-shell system . . `[`. $IS_WINDOWS -eq 1 ]; then
930 printfscip-shell system . . printf. '^M$'
931 else
932 printfscip-shell system . . printf. '$'
933 fi
934 }
935
936 # Compare 2 lists which are newline-delimited in a string, ignoring ordering and blank lines
937 contains_same_elementsscip-shell shell shell-project 0.0.0 contains_same_elements().() {
938 # Remove blank lines then sort
939 diffscip-shell system . . diff. -u <(printfscip-shell system . . printf. '%s' "$1" | grepscip-shell system . . grep. -v '^$' | sortscip-shell system . . sort.) <(printfscip-shell system . . printf. '%s' "$2" | grepscip-shell system . . grep. -v '^$' | sortscip-shell system . . sort.)
940 }
941
942 is_stdin_attachedscip-shell shell shell-project 0.0.0 is_stdin_attached().() {
943 testscip-shell system . . test. -t0
944 echoscip-shell system . . echo. $?
945 }
946
947 has_test_dirscip-shell shell shell-project 0.0.0 has_test_dir().() {
948 if [scip-shell system . . `[`. -z "$GIT_LFS_TEST_DIR" ]; then
949 echoscip-shell system . . echo. "No GIT_LFS_TEST_DIR. Skipping..."
950 exit 0
951 fi
952 }
953
954 has_native_symlinksscip-shell shell shell-project 0.0.0 has_native_symlinks().() {
955 if [scip-shell system . . `[`. -z "$NATIVE_SYMLINKS" ]; then
956 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
957 # On Windows, we need to enable native symlink support in Cygwin or MSYS2,
958 # without falling back to default Cygwin symlink emulation. If this mode
959 # is not available, we should skip our tests with symbolic links.
960 #
961 # https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
962 # https://www.msys2.org/docs/symlinks/
963 # https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development
964 export CYGWIN="winsymlinks:nativestrict${CYGWIN:+ $CYGWIN}"
965 export MSYS="winsymlinks:nativestrict${MSYS:+ $MSYS}"
966
967 touchscip-shell system . . touch. testfile.tmp
968 lnscip-shell system . . ln. -s testfile.tmp testlink.tmp
969
970 if [scip-shell system . . `[`. $(fsutil reparsepoint query testlink.tmp | grepscip-shell system . . grep. -c "Tag value: Symbolic Link") -eq 0 ]; then
971 NATIVE_SYMLINKS=0
972 else
973 NATIVE_SYMLINKS=1
974 fi
975
976 rmscip-shell system . . rm. -f testfile.tmp testlink.tmp
977 else
978 NATIVE_SYMLINKS=1
979 fi
980 fi
981
982 if [scip-shell system . . `[`. "$NATIVE_SYMLINKS" -ne 1 ]; then
983 return 1
984 else
985 return 0
986 fi
987 }
988
989 skip_if_symlinks_unsupportedscip-shell shell shell-project 0.0.0 skip_if_symlinks_unsupported().() {
990 has_native_symlinksscip-shell shell shell-project 0.0.0 has_native_symlinks(). || exit 0
991 }
992
993 add_symlinkscip-shell shell shell-project 0.0.0 add_symlink().() {
994 local src=$1
995 local dest=$2
996
997 prefix=`gitscip-shell system . . git. rev-parse --show-prefix`
998 hashsrc=`printfscip-shell system . . printf. "$src" | gitscip-shell system . . git. hash-object -w --stdin`
999
1000 gitscip-shell system . . git. update-index --add --cacheinfo 120000 "$hashsrc" "$prefix$dest"
1001 gitscip-shell system . . git. checkout -- "$dest"
1002 }
1003
1004 setup_case_inverter_extensionscip-shell shell shell-project 0.0.0 setup_case_inverter_extension().() {
1005 export LFSTEST_EXT_LOG="$TRASHDIR/caseinverterextension.log"
1006
1007 gitscip-shell system . . git. config lfs.extension.caseinverter.clean \
1008 "lfstest-caseinverterextension clean -- %f"
1009 gitscip-shell system . . git. config lfs.extension.caseinverter.smudge \
1010 "lfstest-caseinverterextension smudge -- %f"
1011 gitscip-shell system . . git. config lfs.extension.caseinverter.priority 0
1012 }
1013
1014 case_inverter_extension_pointerscip-shell shell shell-project 0.0.0 case_inverter_extension_pointer().() {
1015 local ext_oid_line="ext-0-caseinverter sha256:$1"
1016 local base_pointer="$(pointerscip-shell shell shell-project 0.0.0 pointer(). "$2" "$3")"
1017
1018 printfscip-shell system . . printf. "%s" "$base_pointer" | sedscip-shell system . . sed. "s/^oid /$ext_oid_line\noid /"
1019 }
1020
1021 invert_casescip-shell shell shell-project 0.0.0 invert_case().() {
1022 printfscip-shell system . . printf. "%s" "$1" | trscip-shell system . . tr. "[:lower:][:upper:]" "[:upper:][:lower:]"
1023 }
1024
1025 urlifyscip-shell shell shell-project 0.0.0 urlify().() {
1026 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]
1027 then
1028 local prefix="" path="$(canonical_pathscip-shell shell shell-project 0.0.0 canonical_path(). "$1")"
1029 if echoscip-shell system . . echo. "$path" | grepscip-shell system . . grep. -qsv "^/"
1030 then
1031 prefix="/scip-shell filesystem . . `/`."
1032 fi
1033 echoscip-shell system . . echo. "$prefix$path" | sedscip-shell system . . sed. -e 's,\\,/,g' -e 's,:,%3a,g' -e 's, ,%20,g'
1034 else
1035 echoscip-shell system . . echo. "$1"
1036 fi
1037 }
1038
1039 setup_pure_sshscip-shell shell shell-project 0.0.0 setup_pure_ssh().() {
1040 export PATH="$ROOTDIR/t/scutiger/bin:$PATH"
1041 if ! command -v git-lfs-transfer >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
1042 then
1043 if [scip-shell system . . `[`. -z "$CI" ] || [scip-shell system . . `[`. -n "$TEST_SKIP_LFS_TRANSFER" ]
1044 then
1045 echoscip-shell system . . echo. "No git-lfs-transfer. Skipping..."
1046 exit 0
1047 else
1048 echoscip-shell system . . echo. "No git-lfs-transfer. Failing.."
1049 exit 1
1050 fi
1051 elif [scip-shell system . . `[`. "$GIT_DEFAULT_HASH" = sha256 ]
1052 then
1053 # Scutiger's git-lfs-transfer uses libgit2, which doesn't yet do SHA-256
1054 # repos.
1055 echoscip-shell system . . echo. "Using SHA-256 repositories. Skipping..."
1056 exit 0
1057 fi
1058 }
1059
1060 ssh_remotescip-shell shell shell-project 0.0.0 ssh_remote().() {
1061 local reponame="$1"
1062 local destination=$(urlifyscip-shell shell shell-project 0.0.0 urlify(). "$(canonical_pathscip-shell shell shell-project 0.0.0 canonical_path(). "$REMOTEDIR/$reponame.git")")
1063 # Prepend a slash iff it lacks one. Windows compatibiity.
1064 [scip-shell system . . `[`. -z "${destination##/*}" ] || destination="/$destination"
1065 echoscip-shell system . . echo. "ssh://[email protected]$destination"
1066 }
1067
1068 # Create a pkt-line message from s, which is an argument string to printf(1).
1069 pktizescip-shell shell shell-project 0.0.0 pktize().() {
1070 local s="$1"
1071 local len=$(printfscip-shell system . . printf. "$s" | wcscip-shell system . . wc. -c)
1072 printfscip-shell system . . printf. "%04x$s" $((len + 4))
1073 }
1074
1075 pktize_textscip-shell shell shell-project 0.0.0 pktize_text().() {
1076 local s="$1"
1077 pktizescip-shell shell shell-project 0.0.0 pktize(). "$s"'\n'
1078 }
1079
1080 pktize_delimscip-shell shell shell-project 0.0.0 pktize_delim().() {
1081 printfscip-shell system . . printf. '0001'
1082 }
1083
1084 pktize_flushscip-shell shell shell-project 0.0.0 pktize_flush().() {
1085 printfscip-shell system . . printf. '0000'
1086 }
1087
1088 # At present, we expect a fixed default value of 8 concurrent transfers,
1089 # which is less than ideal for HTTP-based transfers when many objects
1090 # are transferred by a single "git lfs filter-process" command.
1091 #
1092 # However, the "lfs.concurrentTransfers" setting also controls the number
1093 # of processes we spawn for SSH-based or custom transfers, and we want
1094 # to avoid spawning large numbers of separate processes.
1095 #
1096 # In the future, we may allow this default value to be scaled by the
1097 # number of CPUs, as returned by our lfstest-getnumcpu utility.
1098 setup_expected_concurrent_transfersscip-shell shell shell-project 0.0.0 setup_expected_concurrent_transfers().() {
1099 expectedConcurrentTransfers=8
1100 }