2015-07-30 02:37:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-05-18 19:44:22 +00:00
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# assert_pointer confirms that the pointer in the repository for $path in the
|
|
|
|
# given $ref matches the given $oid and $size.
|
|
|
|
#
|
2020-06-29 16:18:57 +00:00
|
|
|
# $ assert_pointer "main" "path/to/file" "some-oid" 123
|
2015-05-18 22:49:21 +00:00
|
|
|
assert_pointer() {
|
2015-05-22 22:16:47 +00:00
|
|
|
local ref="$1"
|
|
|
|
local path="$2"
|
|
|
|
local oid="$3"
|
|
|
|
local size="$4"
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2016-02-21 18:10:36 +00:00
|
|
|
gitblob=$(git ls-tree -lrz "$ref" |
|
|
|
|
while read -r -d $'\0' x; do
|
|
|
|
echo $x
|
|
|
|
done |
|
2019-08-05 20:44:27 +00:00
|
|
|
grep -F "$path" | cut -f 3 -d " ")
|
2016-02-21 18:10:36 +00:00
|
|
|
|
2015-05-18 22:49:21 +00:00
|
|
|
actual=$(git cat-file -p $gitblob)
|
|
|
|
expected=$(pointer $oid $size)
|
|
|
|
|
|
|
|
if [ "$expected" != "$actual" ]; then
|
|
|
|
exit 1
|
2015-05-18 19:44:22 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-02 22:02:44 +00:00
|
|
|
# refute_pointer confirms that the file in the repository for $path in the
|
|
|
|
# given $ref is _not_ a pointer.
|
|
|
|
#
|
2020-06-29 16:18:57 +00:00
|
|
|
# $ refute_pointer "main" "path/to/file"
|
2018-07-02 22:02:44 +00:00
|
|
|
refute_pointer() {
|
|
|
|
local ref="$1"
|
|
|
|
local path="$2"
|
|
|
|
|
|
|
|
gitblob=$(git ls-tree -lrz "$ref" |
|
|
|
|
while read -r -d $'\0' x; do
|
|
|
|
echo $x
|
|
|
|
done |
|
|
|
|
grep "$path" | cut -f 3 -d " ")
|
|
|
|
|
|
|
|
file=$(git cat-file -p $gitblob)
|
|
|
|
version="version https://git-lfs.github.com/spec/v[0-9]"
|
2018-07-09 18:47:07 +00:00
|
|
|
oid="oid sha256:[0-9a-f]\{64\}"
|
2018-07-02 22:02:44 +00:00
|
|
|
size="size [0-9]*"
|
|
|
|
regex="$version.*$oid.*$size"
|
|
|
|
|
|
|
|
if echo $file | grep -q "$regex"; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-06 10:44:38 +00:00
|
|
|
# assert_local_object confirms that an object file is stored for the given oid &
|
|
|
|
# has the correct size
|
|
|
|
# $ assert_local_object "some-oid" size
|
|
|
|
assert_local_object() {
|
|
|
|
local oid="$1"
|
|
|
|
local size="$2"
|
|
|
|
local cfg=`git lfs env | grep LocalMediaDir`
|
|
|
|
local f="${cfg:14}/${oid:0:2}/${oid:2:2}/$oid"
|
|
|
|
actualsize=$(wc -c <"$f" | tr -d '[[:space:]]')
|
|
|
|
if [ "$size" != "$actualsize" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-03-24 20:36:12 +00:00
|
|
|
# refute_local_object confirms that an object file is NOT stored for an oid.
|
|
|
|
# If "$size" is given as the second argument, assert that the file exists _and_
|
|
|
|
# that it does _not_ the expected size
|
|
|
|
#
|
2015-08-06 10:44:38 +00:00
|
|
|
# $ refute_local_object "some-oid"
|
2017-03-24 20:36:12 +00:00
|
|
|
# $ refute_local_object "some-oid" "123"
|
2015-08-06 10:44:38 +00:00
|
|
|
refute_local_object() {
|
|
|
|
local oid="$1"
|
2017-03-24 20:36:12 +00:00
|
|
|
local size="$2"
|
2015-08-06 10:44:38 +00:00
|
|
|
local cfg=`git lfs env | grep LocalMediaDir`
|
|
|
|
local regex="LocalMediaDir=(\S+)"
|
|
|
|
local f="${cfg:14}/${oid:0:2}/${oid:2:2}/$oid"
|
|
|
|
if [ -e $f ]; then
|
2017-03-24 20:36:12 +00:00
|
|
|
if [ -z "$size" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
actual_size="$(wc -c < "$f" | awk '{ print $1 }')"
|
|
|
|
if [ "$size" -eq "$actual_size" ]; then
|
|
|
|
echo >&2 "fatal: expected object $oid not to have size: $size"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-08-06 10:44:38 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-10-15 15:35:26 +00:00
|
|
|
# delete_local_object deletes the local storage for an oid
|
|
|
|
# $ delete_local_object "some-oid"
|
|
|
|
delete_local_object() {
|
|
|
|
local oid="$1"
|
|
|
|
local cfg=`git lfs env | grep LocalMediaDir`
|
|
|
|
local f="${cfg:14}/${oid:0:2}/${oid:2:2}/$oid"
|
|
|
|
rm "$f"
|
|
|
|
}
|
|
|
|
|
2017-03-24 20:36:33 +00:00
|
|
|
# corrupt_local_object corrupts the local storage for an oid
|
|
|
|
# $ corrupt_local_object "some-oid"
|
|
|
|
corrupt_local_object() {
|
|
|
|
local oid="$1"
|
|
|
|
local cfg=`git lfs env | grep LocalMediaDir`
|
|
|
|
local f="${cfg:14}/${oid:0:2}/${oid:2:2}/$oid"
|
|
|
|
cp /dev/null "$f"
|
|
|
|
}
|
|
|
|
|
2015-10-15 15:35:26 +00:00
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
# check that the object does not exist in the git lfs server. HTTP log is
|
|
|
|
# written to http.log. JSON output is written to http.json.
|
|
|
|
#
|
|
|
|
# $ refute_server_object "reponame" "oid"
|
2015-05-18 22:49:21 +00:00
|
|
|
refute_server_object() {
|
2015-07-06 18:19:18 +00:00
|
|
|
local reponame="$1"
|
|
|
|
local oid="$2"
|
2016-11-08 22:32:01 +00:00
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/objects/batch" \
|
2015-07-06 18:19:18 +00:00
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
2016-11-08 22:32:01 +00:00
|
|
|
-d "{\"operation\":\"download\",\"objects\":[{\"oid\":\"$oid\"}]}" \
|
2016-10-14 20:56:27 +00:00
|
|
|
-H "Accept: application/vnd.git-lfs+json" \
|
2019-05-22 17:48:01 +00:00
|
|
|
-H "Content-Type: application/vnd.git-lfs+json" \
|
2016-11-08 22:32:01 +00:00
|
|
|
-H "X-Check-Object: 1" \
|
2016-10-14 20:56:27 +00:00
|
|
|
-H "X-Ignore-Retries: true" 2>&1 |
|
2015-07-06 18:19:18 +00:00
|
|
|
tee http.log
|
|
|
|
|
2016-11-08 22:32:01 +00:00
|
|
|
[ "0" = "$(grep -c "download" http.json)" ] || {
|
|
|
|
cat http.json
|
|
|
|
exit 1
|
|
|
|
}
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 14:29:25 +00:00
|
|
|
# Delete an object on the lfs server. HTTP log is
|
|
|
|
# written to http.log. JSON output is written to http.json.
|
|
|
|
#
|
|
|
|
# $ delete_server_object "reponame" "oid"
|
|
|
|
delete_server_object() {
|
|
|
|
local reponame="$1"
|
|
|
|
local oid="$2"
|
2016-11-08 22:32:01 +00:00
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/objects/$oid" \
|
|
|
|
-X DELETE \
|
2015-10-13 14:29:25 +00:00
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
|
|
|
-H "Accept: application/vnd.git-lfs+json" 2>&1 |
|
|
|
|
tee http.log
|
|
|
|
|
|
|
|
grep "200 OK" http.log
|
|
|
|
}
|
|
|
|
|
2015-07-06 18:19:18 +00:00
|
|
|
# check that the object does exist in the git lfs server. HTTP log is written
|
|
|
|
# to http.log. JSON output is written to http.json.
|
2015-05-18 22:49:21 +00:00
|
|
|
assert_server_object() {
|
2015-07-06 18:19:18 +00:00
|
|
|
local reponame="$1"
|
|
|
|
local oid="$2"
|
2018-01-05 18:12:57 +00:00
|
|
|
local refspec="$3"
|
2016-11-08 22:32:01 +00:00
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/objects/batch" \
|
2015-07-06 18:19:18 +00:00
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
2018-01-05 18:12:57 +00:00
|
|
|
-d "{\"operation\":\"download\",\"objects\":[{\"oid\":\"$oid\"}],\"ref\":{\"name\":\"$refspec\"}}" \
|
2016-10-14 20:56:27 +00:00
|
|
|
-H "Accept: application/vnd.git-lfs+json" \
|
2019-05-22 17:48:01 +00:00
|
|
|
-H "Content-Type: application/vnd.git-lfs+json" \
|
2016-11-08 22:32:01 +00:00
|
|
|
-H "X-Check-Object: 1" \
|
2016-10-14 20:56:27 +00:00
|
|
|
-H "X-Ignore-Retries: true" 2>&1 |
|
2015-07-06 18:19:18 +00:00
|
|
|
tee http.log
|
|
|
|
grep "200 OK" http.log
|
|
|
|
|
|
|
|
grep "download" http.json || {
|
|
|
|
cat http.json
|
|
|
|
exit 1
|
|
|
|
}
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 19:23:14 +00:00
|
|
|
check_server_lock_ssh() {
|
|
|
|
local reponame="$1"
|
|
|
|
local id="$2"
|
|
|
|
local refspec="$3"
|
|
|
|
local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
|
|
|
|
|
|
|
|
(
|
|
|
|
pktize_text 'version 1'
|
|
|
|
pktize_flush
|
|
|
|
pktize_text 'list-lock'
|
|
|
|
pktize_text "id=$id"
|
|
|
|
pktize_text "refname=$refname"
|
|
|
|
pktize_flush
|
|
|
|
pktize_text 'quit'
|
|
|
|
pktize_flush
|
|
|
|
) | lfs-ssh-echo git@127.0.0.1 "git-lfs-transfer '$destination' download" 2>&1
|
|
|
|
}
|
|
|
|
|
2017-02-23 19:47:14 +00:00
|
|
|
# This asserts the lock path and returns the lock ID by parsing the response of
|
|
|
|
#
|
|
|
|
# git lfs lock --json <path>
|
|
|
|
assert_lock() {
|
2017-02-17 17:59:45 +00:00
|
|
|
local log="$1"
|
2017-02-23 19:47:14 +00:00
|
|
|
local path="$2"
|
|
|
|
|
|
|
|
if [ $(grep -c "\"path\":\"$path\"" "$log") -eq 0 ]; then
|
|
|
|
echo "path '$path' not found in:"
|
|
|
|
cat "$log"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local jsonid=$(grep -oh "\"id\":\"\w\+\"" "$log")
|
|
|
|
echo "${jsonid:3}" | tr -d \"\:
|
2017-02-17 17:59:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 16:36:13 +00:00
|
|
|
# assert that a lock with the given ID exists on the test server
|
|
|
|
assert_server_lock() {
|
2016-12-28 23:22:47 +00:00
|
|
|
local reponame="$1"
|
|
|
|
local id="$2"
|
2018-01-05 21:25:50 +00:00
|
|
|
local refspec="$3"
|
2016-06-03 16:36:13 +00:00
|
|
|
|
2018-01-05 21:25:50 +00:00
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/locks?refspec=$refspec" \
|
2016-06-03 16:36:13 +00:00
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
|
|
|
-H "Accept:application/vnd.git-lfs+json" 2>&1 |
|
|
|
|
tee http.log
|
|
|
|
|
|
|
|
grep "200 OK" http.log
|
|
|
|
grep "$id" http.json || {
|
|
|
|
cat http.json
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 19:23:14 +00:00
|
|
|
# assert that a lock with the given ID exists on the test server
|
|
|
|
assert_server_lock_ssh() {
|
|
|
|
local reponame="$1"
|
|
|
|
local id="$2"
|
|
|
|
local refspec="$3"
|
|
|
|
|
|
|
|
check_server_lock_ssh "$reponame" "$id" "$refspec" |
|
|
|
|
tee output.log
|
|
|
|
|
|
|
|
grep "status 200" output.log
|
|
|
|
grep "$id" output.log || {
|
|
|
|
cat output.log
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-03 16:36:13 +00:00
|
|
|
# refute that a lock with the given ID exists on the test server
|
|
|
|
refute_server_lock() {
|
2016-12-28 23:23:40 +00:00
|
|
|
local reponame="$1"
|
|
|
|
local id="$2"
|
2018-01-05 21:25:50 +00:00
|
|
|
local refspec="$3"
|
2016-06-03 16:36:13 +00:00
|
|
|
|
2018-01-05 21:25:50 +00:00
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/locks?refspec=$refspec" \
|
2016-06-03 16:36:13 +00:00
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
2016-06-03 21:00:36 +00:00
|
|
|
-H "Accept:application/vnd.git-lfs+json" 2>&1 | tee http.log
|
2016-06-03 16:36:13 +00:00
|
|
|
|
|
|
|
grep "200 OK" http.log
|
2016-06-03 21:00:36 +00:00
|
|
|
|
|
|
|
[ $(grep -c "$id" http.json) -eq 0 ]
|
2016-06-03 16:36:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 19:23:14 +00:00
|
|
|
# refute that a lock with the given ID exists on the test server
|
|
|
|
refute_server_lock_ssh() {
|
|
|
|
local reponame="$1"
|
|
|
|
local id="$2"
|
|
|
|
local refspec="$3"
|
|
|
|
local destination="$(canonical_path "$REMOTEDIR/$reponame.git")"
|
|
|
|
|
|
|
|
check_server_lock_ssh "$reponame" "$id" "$refspec" |
|
|
|
|
tee output.log
|
|
|
|
|
|
|
|
grep "status 200" output.log
|
|
|
|
if grep "$id" output.log
|
|
|
|
then
|
|
|
|
cat output.log
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-01-09 12:02:27 +00:00
|
|
|
# Assert that .gitattributes contains a given attribute N times
|
|
|
|
assert_attributes_count() {
|
|
|
|
local fileext="$1"
|
|
|
|
local attrib="$2"
|
|
|
|
local count="$3"
|
|
|
|
|
2017-03-23 23:07:13 +00:00
|
|
|
pattern="\(*.\)\?$fileext\(.*\)$attrib"
|
2017-01-09 12:02:27 +00:00
|
|
|
actual=$(grep -e "$pattern" .gitattributes | wc -l)
|
|
|
|
if [ "$(printf "%d" "$actual")" != "$count" ]; then
|
|
|
|
echo "wrong number of $attrib entries for $fileext"
|
|
|
|
echo "expected: $count actual: $actual"
|
|
|
|
cat .gitattributes
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-08-18 00:08:47 +00:00
|
|
|
assert_file_writeable() {
|
2017-03-01 00:45:11 +00:00
|
|
|
ls -l "$1" | grep -e "^-rw"
|
|
|
|
}
|
|
|
|
|
2017-08-18 00:09:10 +00:00
|
|
|
refute_file_writeable() {
|
2017-03-01 00:45:11 +00:00
|
|
|
ls -l "$1" | grep -e "^-r-"
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:54:52 +00:00
|
|
|
git_root() {
|
|
|
|
git rev-parse --show-toplevel 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
dot_git_dir() {
|
|
|
|
echo "$(git_root)/.git"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_hooks() {
|
|
|
|
local git_root="$1"
|
|
|
|
|
|
|
|
if [ -z "$git_root" ]; then
|
|
|
|
echo >&2 "fatal: (assert_hooks) not in git repository"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -x "$git_root/hooks/post-checkout" ]
|
|
|
|
[ -x "$git_root/hooks/post-commit" ]
|
|
|
|
[ -x "$git_root/hooks/post-merge" ]
|
|
|
|
[ -x "$git_root/hooks/pre-push" ]
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:48:18 +00:00
|
|
|
assert_clean_status() {
|
|
|
|
status="$(git status)"
|
|
|
|
echo "$status" | grep "working tree clean" || {
|
|
|
|
echo $status
|
|
|
|
git lfs status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# pointer returns a string Git LFS pointer file.
|
|
|
|
#
|
2016-10-21 00:07:45 +00:00
|
|
|
# $ pointer abc-some-oid 123 <version>
|
2015-05-19 22:54:15 +00:00
|
|
|
# > version ...
|
2015-05-18 22:49:21 +00:00
|
|
|
pointer() {
|
|
|
|
local oid=$1
|
|
|
|
local size=$2
|
2016-10-21 00:07:45 +00:00
|
|
|
local version=${3:-https://git-lfs.github.com/spec/v1}
|
|
|
|
printf "version %s
|
2015-05-18 22:49:21 +00:00
|
|
|
oid sha256:%s
|
|
|
|
size %s
|
2016-10-21 00:07:45 +00:00
|
|
|
" "$version" "$oid" "$size"
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# wait_for_file simply sleeps until a file exists.
|
|
|
|
#
|
|
|
|
# $ wait_for_file "path/to/upcoming/file"
|
2015-05-18 19:44:22 +00:00
|
|
|
wait_for_file() {
|
2015-05-22 22:16:47 +00:00
|
|
|
local filename="$1"
|
2015-05-18 19:58:58 +00:00
|
|
|
n=0
|
2017-11-04 03:27:57 +00:00
|
|
|
wait_time=1
|
|
|
|
while [ $n -lt 17 ]; do
|
2015-05-18 19:44:22 +00:00
|
|
|
if [ -s $filename ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-11-04 03:27:57 +00:00
|
|
|
sleep $wait_time
|
2015-05-18 19:58:58 +00:00
|
|
|
n=`expr $n + 1`
|
2017-11-04 03:27:57 +00:00
|
|
|
if [ $wait_time -lt 4 ]; then
|
|
|
|
wait_time=`expr $wait_time \* 2`
|
|
|
|
fi
|
2015-05-18 19:44:22 +00:00
|
|
|
done
|
|
|
|
|
2017-11-04 03:27:57 +00:00
|
|
|
echo "$filename did not appear after 60 seconds."
|
2015-05-18 19:44:22 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2016-10-24 06:13:49 +00:00
|
|
|
# setup_remote_repo initializes a bare Git repository that is accessible through
|
2015-05-19 22:54:15 +00:00
|
|
|
# the test Git server. The `pwd` is set to the repository's directory, in case
|
2018-07-13 17:43:13 +00:00
|
|
|
# further commands need to be run. This server is running for every test in an
|
|
|
|
# integration run, so every test file should setup its own remote repository to
|
|
|
|
# avoid conflicts.
|
2015-05-19 22:54:15 +00:00
|
|
|
#
|
|
|
|
# $ setup_remote_repo "some-name"
|
|
|
|
#
|
2015-05-18 19:44:22 +00:00
|
|
|
setup_remote_repo() {
|
2015-05-22 22:16:47 +00:00
|
|
|
local reponame="$1"
|
2015-05-18 22:49:21 +00:00
|
|
|
echo "set up remote git repository: $reponame"
|
2015-05-18 19:44:22 +00:00
|
|
|
repodir="$REMOTEDIR/$reponame.git"
|
2015-05-18 22:49:21 +00:00
|
|
|
mkdir -p "$repodir"
|
|
|
|
cd "$repodir"
|
2015-05-18 19:44:22 +00:00
|
|
|
git init --bare
|
|
|
|
git config http.receivepack true
|
|
|
|
git config receive.denyCurrentBranch ignore
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 20:18:51 +00:00
|
|
|
# creates a bare remote repository for a local clone. Useful to test pushing to
|
|
|
|
# a fresh remote server.
|
|
|
|
#
|
|
|
|
# $ setup_alternate_remote "$reponame-whatever"
|
|
|
|
# $ setup_alternate_remote "$reponame-whatever" "other-remote-name"
|
|
|
|
#
|
|
|
|
setup_alternate_remote() {
|
|
|
|
local newRemoteName=$1
|
|
|
|
local remote=${2:-origin}
|
|
|
|
|
|
|
|
wd=`pwd`
|
|
|
|
|
|
|
|
setup_remote_repo "$newRemoteName"
|
|
|
|
cd $wd
|
|
|
|
git remote rm "$remote"
|
|
|
|
git remote add "$remote" "$GITSERVER/$newRemoteName"
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# clone_repo clones a repository from the test Git server to the subdirectory
|
2015-09-23 19:30:10 +00:00
|
|
|
# $dir under $TRASHDIR. setup_remote_repo() needs to be run first. Output is
|
|
|
|
# written to clone.log.
|
2015-05-18 22:49:21 +00:00
|
|
|
clone_repo() {
|
|
|
|
cd "$TRASHDIR"
|
|
|
|
|
2015-05-22 22:16:47 +00:00
|
|
|
local reponame="$1"
|
|
|
|
local dir="$2"
|
2015-05-18 22:49:21 +00:00
|
|
|
echo "clone local git repository $reponame to $dir"
|
2015-05-26 15:39:04 +00:00
|
|
|
out=$(git clone "$GITSERVER/$reponame" "$dir" 2>&1)
|
2015-05-18 22:49:21 +00:00
|
|
|
cd "$dir"
|
|
|
|
|
2015-05-21 17:04:59 +00:00
|
|
|
git config credential.helper lfstest
|
2015-09-23 19:30:10 +00:00
|
|
|
echo "$out" > clone.log
|
2015-05-18 22:49:21 +00:00
|
|
|
echo "$out"
|
2015-05-18 19:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 14:09:14 +00:00
|
|
|
# clone_repo_url clones a Git repository to the subdirectory $dir under $TRASHDIR.
|
|
|
|
# setup_remote_repo() needs to be run first. Output is written to clone.log.
|
|
|
|
clone_repo_url() {
|
|
|
|
cd "$TRASHDIR"
|
|
|
|
|
|
|
|
local repo="$1"
|
|
|
|
local dir="$2"
|
|
|
|
echo "clone git repository $repo to $dir"
|
|
|
|
out=$(git clone "$repo" "$dir" 2>&1)
|
|
|
|
cd "$dir"
|
|
|
|
|
|
|
|
git config credential.helper lfstest
|
|
|
|
echo "$out" > clone.log
|
|
|
|
echo "$out"
|
|
|
|
}
|
|
|
|
|
2016-03-09 17:31:04 +00:00
|
|
|
# clone_repo_ssl clones a repository from the test Git server to the subdirectory
|
2016-05-23 21:03:25 +00:00
|
|
|
# $dir under $TRASHDIR, using the SSL endpoint.
|
2016-03-09 17:31:04 +00:00
|
|
|
# setup_remote_repo() needs to be run first. Output is written to clone_ssl.log.
|
|
|
|
clone_repo_ssl() {
|
|
|
|
cd "$TRASHDIR"
|
|
|
|
|
|
|
|
local reponame="$1"
|
|
|
|
local dir="$2"
|
|
|
|
echo "clone local git repository $reponame to $dir"
|
2016-03-09 18:03:15 +00:00
|
|
|
out=$(git clone "$SSLGITSERVER/$reponame" "$dir" 2>&1)
|
2016-03-09 17:31:04 +00:00
|
|
|
cd "$dir"
|
|
|
|
|
|
|
|
git config credential.helper lfstest
|
2016-03-09 18:03:15 +00:00
|
|
|
|
2016-03-09 17:31:04 +00:00
|
|
|
echo "$out" > clone_ssl.log
|
|
|
|
echo "$out"
|
|
|
|
}
|
2016-06-03 16:36:13 +00:00
|
|
|
|
2017-01-24 14:53:43 +00:00
|
|
|
# clone_repo_clientcert clones a repository from the test Git server to the subdirectory
|
|
|
|
# $dir under $TRASHDIR, using the client cert endpoint.
|
|
|
|
# setup_remote_repo() needs to be run first. Output is written to clone_client_cert.log.
|
|
|
|
clone_repo_clientcert() {
|
|
|
|
cd "$TRASHDIR"
|
|
|
|
|
|
|
|
local reponame="$1"
|
|
|
|
local dir="$2"
|
|
|
|
echo "clone $CLIENTCERTGITSERVER/$reponame to $dir"
|
2017-01-25 21:49:35 +00:00
|
|
|
set +e
|
2017-01-24 14:53:43 +00:00
|
|
|
out=$(git clone "$CLIENTCERTGITSERVER/$reponame" "$dir" 2>&1)
|
2017-01-25 21:49:35 +00:00
|
|
|
res="${PIPESTATUS[0]}"
|
|
|
|
set -e
|
2017-01-24 14:53:43 +00:00
|
|
|
|
2017-01-25 21:49:35 +00:00
|
|
|
if [ "0" -eq "$res" ]; then
|
|
|
|
cd "$dir"
|
|
|
|
echo "$out" > clone_client_cert.log
|
|
|
|
|
|
|
|
git config credential.helper lfstest
|
2018-09-13 22:41:11 +00:00
|
|
|
return 0
|
2017-01-25 21:49:35 +00:00
|
|
|
fi
|
2017-01-24 14:53:43 +00:00
|
|
|
|
|
|
|
echo "$out" > clone_client_cert.log
|
2017-01-25 21:49:35 +00:00
|
|
|
if [ $(grep -c "NSInvalidArgumentException" clone_client_cert.log) -gt 0 ]; then
|
|
|
|
echo "client-cert-mac-openssl" > clone_client_cert.log
|
2018-09-13 22:41:11 +00:00
|
|
|
return 0
|
2017-01-25 21:49:35 +00:00
|
|
|
fi
|
|
|
|
|
2018-09-13 22:41:11 +00:00
|
|
|
return 1
|
2017-01-24 14:53:43 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 16:36:13 +00:00
|
|
|
# setup_remote_repo_with_file creates a remote repo, clones it locally, commits
|
|
|
|
# a file tracked by LFS, and pushes it to the remote:
|
|
|
|
#
|
|
|
|
# setup_remote_repo_with_file "reponame" "filename"
|
|
|
|
setup_remote_repo_with_file() {
|
|
|
|
local reponame="$1"
|
|
|
|
local filename="$2"
|
2017-08-11 18:31:52 +00:00
|
|
|
local dirname="$(dirname "$filename")"
|
2016-06-03 16:36:13 +00:00
|
|
|
|
2017-02-01 00:03:21 +00:00
|
|
|
setup_remote_repo "$reponame"
|
|
|
|
clone_repo "$reponame" "clone_$reponame"
|
2016-06-03 16:36:13 +00:00
|
|
|
|
2017-08-11 18:31:52 +00:00
|
|
|
mkdir -p "$dirname"
|
|
|
|
|
2016-06-03 16:36:13 +00:00
|
|
|
git lfs track "$filename"
|
|
|
|
echo "$filename" > "$filename"
|
|
|
|
git add .gitattributes $filename
|
|
|
|
git commit -m "add $filename" | tee commit.log
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
grep "main (root-commit)" commit.log
|
2016-06-03 16:36:13 +00:00
|
|
|
grep "2 files changed" commit.log
|
|
|
|
grep "create mode 100644 $filename" commit.log
|
|
|
|
grep "create mode 100644 .gitattributes" commit.log
|
|
|
|
|
2020-06-29 16:18:57 +00:00
|
|
|
git push origin main 2>&1 | tee push.log
|
|
|
|
grep "main -> main" push.log
|
2016-06-03 16:36:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 01:04:03 +00:00
|
|
|
# substring_position returns the position of a substring in a 1-indexed search
|
|
|
|
# space.
|
|
|
|
#
|
|
|
|
# [ "$(substring_position "foo bar baz" "baz")" -eq "9" ]
|
|
|
|
substring_position() {
|
|
|
|
local str="$1"
|
|
|
|
local substr="$2"
|
|
|
|
|
|
|
|
# 1) Print the string...
|
|
|
|
# 2) Remove the substring and everything after it
|
|
|
|
# 3) Count the number of characters (bytes) left, i.e., the offset of the
|
|
|
|
# string we were looking for.
|
|
|
|
|
|
|
|
echo "$str" \
|
|
|
|
| sed "s/$substr.*$//" \
|
|
|
|
| wc -c
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:25:50 +00:00
|
|
|
# repo_endpoint returns the LFS endpoint for a given server and repository.
|
|
|
|
#
|
|
|
|
# [ "$GITSERVER/example/repo.git/info/lfs" = "$(repo_endpoint $GITSERVER example-repo)" ]
|
|
|
|
repo_endpoint() {
|
|
|
|
local server="$1"
|
|
|
|
local repo="$2"
|
|
|
|
|
|
|
|
echo "$server/$repo.git/info/lfs"
|
|
|
|
}
|
|
|
|
|
2019-08-26 19:15:32 +00:00
|
|
|
# write_creds_file writes credentials to a file iff it doesn't exist.
|
|
|
|
write_creds_file() {
|
|
|
|
local creds="$1"
|
|
|
|
local file="$2"
|
|
|
|
|
|
|
|
if [ ! -f "$file" ]
|
|
|
|
then
|
|
|
|
printf "%s" "$creds" > "$file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-05-20 17:25:20 +00:00
|
|
|
# setup initializes the clean, isolated environment for integration tests.
|
2015-05-18 19:44:22 +00:00
|
|
|
setup() {
|
2015-05-18 22:49:21 +00:00
|
|
|
cd "$ROOTDIR"
|
|
|
|
|
2018-07-11 18:17:17 +00:00
|
|
|
if [ ! -d "$REMOTEDIR" ]; then
|
|
|
|
mkdir "$REMOTEDIR"
|
|
|
|
fi
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2021-08-23 15:30:43 +00:00
|
|
|
echo "# Git LFS: ${LFS_BIN:-$(command -v git-lfs)}"
|
2018-07-09 21:13:09 +00:00
|
|
|
git lfs version | sed -e 's/^/# /g'
|
|
|
|
git version | sed -e 's/^/# /g'
|
2015-05-18 19:44:22 +00:00
|
|
|
|
2018-07-17 18:31:38 +00:00
|
|
|
if [ -z "$GIT_LFS_NO_TEST_COUNT" ]; then
|
|
|
|
LFSTEST_URL="$LFS_URL_FILE" \
|
|
|
|
LFSTEST_SSL_URL="$LFS_SSL_URL_FILE" \
|
|
|
|
LFSTEST_CLIENT_CERT_URL="$LFS_CLIENT_CERT_URL_FILE" \
|
|
|
|
LFSTEST_DIR="$REMOTEDIR" \
|
|
|
|
LFSTEST_CERT="$LFS_CERT_FILE" \
|
|
|
|
LFSTEST_CLIENT_CERT="$LFS_CLIENT_CERT_FILE" \
|
|
|
|
LFSTEST_CLIENT_KEY="$LFS_CLIENT_KEY_FILE" \
|
2018-09-17 18:41:43 +00:00
|
|
|
LFSTEST_CLIENT_KEY_ENCRYPTED="$LFS_CLIENT_KEY_FILE_ENCRYPTED" \
|
2018-07-17 18:31:38 +00:00
|
|
|
lfstest-count-tests increment
|
|
|
|
fi
|
2017-01-24 14:53:43 +00:00
|
|
|
|
|
|
|
wait_for_file "$LFS_URL_FILE"
|
|
|
|
wait_for_file "$LFS_SSL_URL_FILE"
|
|
|
|
wait_for_file "$LFS_CLIENT_CERT_URL_FILE"
|
|
|
|
wait_for_file "$LFS_CERT_FILE"
|
|
|
|
wait_for_file "$LFS_CLIENT_CERT_FILE"
|
|
|
|
wait_for_file "$LFS_CLIENT_KEY_FILE"
|
2018-09-17 18:41:43 +00:00
|
|
|
wait_for_file "$LFS_CLIENT_KEY_FILE_ENCRYPTED"
|
2017-01-24 14:53:43 +00:00
|
|
|
|
|
|
|
LFS_CLIENT_CERT_URL=`cat $LFS_CLIENT_CERT_URL_FILE`
|
2015-05-26 15:39:04 +00:00
|
|
|
|
2015-07-30 02:03:57 +00:00
|
|
|
# Set up the initial git config and osx keychain if applicable
|
|
|
|
HOME="$TESTHOME"
|
2018-07-11 16:42:28 +00:00
|
|
|
if [ ! -d "$HOME" ]; then
|
|
|
|
mkdir "$HOME"
|
|
|
|
fi
|
2018-07-12 17:39:39 +00:00
|
|
|
|
|
|
|
if [ ! -f $HOME/.gitconfig ]; then
|
2018-07-09 21:13:09 +00:00
|
|
|
git lfs install --skip-repo
|
|
|
|
git config --global credential.usehttppath true
|
|
|
|
git config --global credential.helper lfstest
|
|
|
|
git config --global user.name "Git LFS Tests"
|
|
|
|
git config --global user.email "git-lfs@example.com"
|
|
|
|
git config --global http.sslcainfo "$LFS_CERT_FILE"
|
|
|
|
git config --global http.$LFS_CLIENT_CERT_URL/.sslKey "$LFS_CLIENT_KEY_FILE"
|
|
|
|
git config --global http.$LFS_CLIENT_CERT_URL/.sslCert "$LFS_CLIENT_CERT_FILE"
|
|
|
|
git config --global http.$LFS_CLIENT_CERT_URL/.sslVerify "false"
|
2018-07-12 17:39:39 +00:00
|
|
|
fi | sed -e 's/^/# /g'
|
2015-05-26 15:39:04 +00:00
|
|
|
|
2015-08-04 16:06:30 +00:00
|
|
|
# setup the git credential password storage
|
2018-09-17 18:41:43 +00:00
|
|
|
local certpath="$(echo "$LFS_CLIENT_CERT_FILE" | tr / -)"
|
|
|
|
local keypath="$(echo "$LFS_CLIENT_KEY_FILE_ENCRYPTED" | tr / -)"
|
2015-08-04 16:06:30 +00:00
|
|
|
mkdir -p "$CREDSDIR"
|
2019-08-26 19:15:32 +00:00
|
|
|
write_creds_file "user:pass" "$CREDSDIR/127.0.0.1"
|
|
|
|
write_creds_file ":pass" "$CREDSDIR/--$certpath"
|
|
|
|
write_creds_file ":pass" "$CREDSDIR/--$keypath"
|
2015-08-04 16:06:30 +00:00
|
|
|
|
2018-07-09 21:13:09 +00:00
|
|
|
echo "#"
|
|
|
|
echo "# HOME: $HOME"
|
|
|
|
echo "# TMP: $TMPDIR"
|
|
|
|
echo "# CREDS: $CREDSDIR"
|
|
|
|
echo "# lfstest-gitserver:"
|
|
|
|
echo "# LFSTEST_URL=$LFS_URL_FILE"
|
|
|
|
echo "# LFSTEST_SSL_URL=$LFS_SSL_URL_FILE"
|
|
|
|
echo "# LFSTEST_CLIENT_CERT_URL=$LFS_CLIENT_CERT_URL_FILE ($LFS_CLIENT_CERT_URL)"
|
|
|
|
echo "# LFSTEST_CERT=$LFS_CERT_FILE"
|
|
|
|
echo "# LFSTEST_CLIENT_CERT=$LFS_CLIENT_CERT_FILE"
|
|
|
|
echo "# LFSTEST_CLIENT_KEY=$LFS_CLIENT_KEY_FILE"
|
2018-09-17 18:41:43 +00:00
|
|
|
echo "# LFSTEST_CLIENT_KEY_ENCRYPTED=$LFS_CLIENT_KEY_FILE_ENCRYPTED"
|
2018-07-09 21:13:09 +00:00
|
|
|
echo "# LFSTEST_DIR=$REMOTEDIR"
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# shutdown cleans the $TRASHDIR and shuts the test Git server down.
|
2015-05-18 22:49:21 +00:00
|
|
|
shutdown() {
|
2018-07-09 20:47:40 +00:00
|
|
|
# every t/t-*.sh file should cleanup its trashdir
|
2015-05-21 16:27:40 +00:00
|
|
|
[ -z "$KEEPTRASH" ] && rm -rf "$TRASHDIR"
|
2015-05-18 23:15:32 +00:00
|
|
|
|
2018-07-17 18:31:38 +00:00
|
|
|
if [ -z "$GIT_LFS_NO_TEST_COUNT" ]; then
|
|
|
|
LFSTEST_DIR="$REMOTEDIR" \
|
|
|
|
LFS_URL_FILE="$LFS_URL_FILE" \
|
|
|
|
lfstest-count-tests decrement
|
|
|
|
fi
|
2015-05-18 19:44:22 +00:00
|
|
|
}
|
2015-07-31 13:45:42 +00:00
|
|
|
|
2018-07-09 20:47:40 +00:00
|
|
|
tap_show_plan() {
|
|
|
|
local tests="$1"
|
|
|
|
|
2018-07-09 21:13:09 +00:00
|
|
|
printf "1..%i\n" "$tests"
|
2018-07-09 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 16:31:26 +00:00
|
|
|
ensure_git_version_isnt() {
|
|
|
|
local expectedComparison=$1
|
|
|
|
local version=$2
|
|
|
|
|
|
|
|
local gitVersion=$(git version | cut -d" " -f3)
|
|
|
|
|
|
|
|
set +e
|
|
|
|
compare_version $gitVersion $version
|
|
|
|
result=$?
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ $result == $expectedComparison ]]; then
|
|
|
|
echo "skip: $0 (git version $(comparison_to_operator $expectedComparison) $version)"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-31 13:45:42 +00:00
|
|
|
VERSION_EQUAL=0
|
|
|
|
VERSION_HIGHER=1
|
|
|
|
VERSION_LOWER=2
|
2015-07-31 16:31:26 +00:00
|
|
|
|
2015-07-31 13:45:42 +00:00
|
|
|
# Compare $1 and $2 and return VERSION_EQUAL / VERSION_LOWER / VERSION_HIGHER
|
|
|
|
compare_version() {
|
|
|
|
if [[ $1 == $2 ]]
|
|
|
|
then
|
|
|
|
return $VERSION_EQUAL
|
|
|
|
fi
|
|
|
|
local IFS=.
|
|
|
|
local i ver1=($1) ver2=($2)
|
|
|
|
# fill empty fields in ver1 with zeros
|
|
|
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
|
|
|
do
|
|
|
|
ver1[i]=0
|
|
|
|
done
|
|
|
|
for ((i=0; i<${#ver1[@]}; i++))
|
|
|
|
do
|
|
|
|
if [[ -z ${ver2[i]} ]]
|
|
|
|
then
|
|
|
|
# fill empty fields in ver2 with zeros
|
|
|
|
ver2[i]=0
|
|
|
|
fi
|
|
|
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
|
|
|
then
|
|
|
|
return $VERSION_HIGHER
|
|
|
|
fi
|
|
|
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
|
|
|
then
|
|
|
|
return $VERSION_LOWER
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return $VERSION_EQUAL
|
2015-07-31 16:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
comparison_to_operator() {
|
|
|
|
local comparison=$1
|
|
|
|
if [[ $1 == $VERSION_EQUAL ]]; then
|
|
|
|
echo "=="
|
|
|
|
elif [[ $1 == $VERSION_HIGHER ]]; then
|
|
|
|
echo ">"
|
|
|
|
elif [[ $1 == $VERSION_LOWER ]]; then
|
|
|
|
echo "<"
|
|
|
|
else
|
|
|
|
echo "???"
|
|
|
|
fi
|
|
|
|
}
|
2015-08-25 16:39:33 +00:00
|
|
|
|
2016-10-08 14:59:17 +00:00
|
|
|
# Calculate the object ID from the string passed as the argument
|
2015-09-21 17:50:22 +00:00
|
|
|
calc_oid() {
|
2016-10-08 17:00:30 +00:00
|
|
|
printf "$1" | $SHASUM | cut -f 1 -d " "
|
2015-09-21 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 14:59:17 +00:00
|
|
|
# Calculate the object ID from the file passed as the argument
|
|
|
|
calc_oid_file() {
|
2016-10-08 17:00:30 +00:00
|
|
|
$SHASUM "$1" | cut -f 1 -d " "
|
2016-10-08 14:59:17 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 16:39:33 +00:00
|
|
|
# Get a date string with an offset
|
|
|
|
# Args: One or more date offsets of the form (regex) "[+-]\d+[dmyHM]"
|
|
|
|
# e.g. +1d = 1 day forward from today
|
|
|
|
# -5y = 5 years before today
|
|
|
|
# Example call:
|
|
|
|
# D=$(get_date +1y +1m -5H)
|
|
|
|
# returns date as string in RFC3339 format ccyy-mm-ddThh:MM:ssZ
|
|
|
|
# note returns in UTC time not local time hence Z and not +/-
|
|
|
|
get_date() {
|
|
|
|
# Wrapped because BSD (inc OSX) & GNU 'date' functions are different
|
|
|
|
# on Windows under Git Bash it's GNU
|
|
|
|
if date --version >/dev/null 2>&1 ; then # GNU
|
|
|
|
ARGS=""
|
|
|
|
for var in "$@"
|
|
|
|
do
|
|
|
|
# GNU offsets are more verbose
|
|
|
|
unit=${var: -1}
|
|
|
|
val=${var:0:${#var}-1}
|
|
|
|
case "$unit" in
|
|
|
|
d) unit="days" ;;
|
|
|
|
m) unit="months" ;;
|
|
|
|
y) unit="years" ;;
|
|
|
|
H) unit="hours" ;;
|
|
|
|
M) unit="minutes" ;;
|
|
|
|
esac
|
|
|
|
ARGS="$ARGS $val $unit"
|
|
|
|
done
|
|
|
|
date -d "$ARGS" -u +%Y-%m-%dT%TZ
|
|
|
|
else # BSD
|
|
|
|
ARGS=""
|
|
|
|
for var in "$@"
|
|
|
|
do
|
|
|
|
ARGS="$ARGS -v$var"
|
|
|
|
done
|
|
|
|
date $ARGS -u +%Y-%m-%dT%TZ
|
|
|
|
fi
|
2015-09-09 20:18:51 +00:00
|
|
|
}
|
2015-10-16 12:28:34 +00:00
|
|
|
|
2015-10-23 08:21:49 +00:00
|
|
|
# escape any instance of '\' with '\\' on Windows
|
|
|
|
escape_path() {
|
|
|
|
local unescaped="$1"
|
2016-10-08 16:47:33 +00:00
|
|
|
if [ $IS_WINDOWS -eq 1 ]; then
|
2015-10-22 13:34:44 +00:00
|
|
|
printf '%s' "${unescaped//\\/\\\\}"
|
|
|
|
else
|
|
|
|
printf '%s' "$unescaped"
|
|
|
|
fi
|
2015-10-23 08:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# As native_path but escape all backslash characters to "\\"
|
|
|
|
native_path_escaped() {
|
|
|
|
local unescaped=$(native_path "$1")
|
2015-10-26 22:25:31 +00:00
|
|
|
escape_path "$unescaped"
|
2015-10-22 13:34:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:23:27 +00:00
|
|
|
# native_path_list_separator prints the operating system-specific path list
|
|
|
|
# separator.
|
|
|
|
native_path_list_separator() {
|
|
|
|
if [ "$IS_WINDOWS" -eq 1 ]; then
|
|
|
|
printf ";";
|
|
|
|
else
|
|
|
|
printf ":";
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-30 19:07:14 +00:00
|
|
|
# canonical_path prints the native path name in a canonical form, as if
|
|
|
|
# realpath(3) were called on it.
|
|
|
|
canonical_path() {
|
|
|
|
printf "%s" "$(lfstest-realpath "$(native_path "$1")")"
|
|
|
|
}
|
|
|
|
|
|
|
|
# canonical_path_escaped prints the native path name in a canonical form, as if
|
|
|
|
# realpath(3) were called on it, and then escapes it.
|
|
|
|
canonical_path_escaped() {
|
|
|
|
printf "%s" "$(escape_path "$(lfstest-realpath "$(native_path "$1")")")"
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:31:06 +00:00
|
|
|
cat_end() {
|
|
|
|
if [ $IS_WINDOWS -eq 1 ]; then
|
|
|
|
printf '^M$'
|
|
|
|
else
|
|
|
|
printf '$'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:58:18 +00:00
|
|
|
# Compare 2 lists which are newline-delimited in a string, ignoring ordering and blank lines
|
|
|
|
contains_same_elements() {
|
|
|
|
# Remove blank lines then sort
|
2018-07-25 21:29:50 +00:00
|
|
|
diff -u <(printf '%s' "$1" | grep -v '^$' | sort) <(printf '%s' "$2" | grep -v '^$' | sort)
|
2015-10-21 09:58:18 +00:00
|
|
|
}
|
2015-10-22 11:49:48 +00:00
|
|
|
|
|
|
|
is_stdin_attached() {
|
|
|
|
test -t0
|
|
|
|
echo $?
|
2015-10-26 22:25:31 +00:00
|
|
|
}
|
2015-10-26 23:12:15 +00:00
|
|
|
|
|
|
|
has_test_dir() {
|
|
|
|
if [ -z "$GIT_LFS_TEST_DIR" ]; then
|
|
|
|
echo "No GIT_LFS_TEST_DIR. Skipping..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
2018-04-27 06:33:29 +00:00
|
|
|
|
|
|
|
add_symlink() {
|
|
|
|
local src=$1
|
|
|
|
local dest=$2
|
|
|
|
|
|
|
|
prefix=`git rev-parse --show-prefix`
|
|
|
|
hashsrc=`printf "$src" | git hash-object -w --stdin`
|
|
|
|
|
|
|
|
git update-index --add --cacheinfo 120000 "$hashsrc" "$prefix$dest"
|
|
|
|
git checkout -- "$dest"
|
|
|
|
}
|
2021-05-14 17:52:39 +00:00
|
|
|
|
|
|
|
urlify() {
|
|
|
|
if [ "$IS_WINDOWS" -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "$1" | sed -e 's,\\,/,g' -e 's,:,%3a,g' -e 's, ,%20,g'
|
|
|
|
else
|
|
|
|
echo "$1"
|
|
|
|
fi
|
|
|
|
}
|
2021-05-14 17:56:24 +00:00
|
|
|
|
|
|
|
setup_pure_ssh() {
|
|
|
|
export PATH="$ROOTDIR/t/scutiger/bin:$PATH"
|
|
|
|
if ! command -v git-lfs-transfer >/dev/null 2>&1
|
|
|
|
then
|
2021-10-07 20:59:47 +00:00
|
|
|
if [ -z "$CI" ] || [ -n "$TEST_SKIP_LFS_TRANSFER" ]
|
2021-05-14 17:56:24 +00:00
|
|
|
then
|
|
|
|
echo "No git-lfs-transfer. Skipping..."
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "No git-lfs-transfer. Failing.."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
elif [ "$GIT_DEFAULT_HASH" = sha256 ]
|
|
|
|
then
|
|
|
|
# Scutiger's git-lfs-transfer uses libgit2, which doesn't yet do SHA-256
|
|
|
|
# repos.
|
|
|
|
echo "Using SHA-256 repositories. Skipping..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
2021-05-14 18:33:44 +00:00
|
|
|
|
|
|
|
ssh_remote() {
|
|
|
|
local reponame="$1"
|
|
|
|
local destination=$(urlify "$(canonical_path "$REMOTEDIR/$reponame.git")")
|
|
|
|
# Prepend a slash iff it lacks one. Windows compatibiity.
|
|
|
|
[ -z "${destination##/*}" ] || destination="/$destination"
|
|
|
|
echo "ssh://git@127.0.0.1$destination"
|
|
|
|
}
|
2021-05-14 19:23:14 +00:00
|
|
|
|
|
|
|
# Create a pkt-line message from s, which is an argument string to printf(1).
|
|
|
|
pktize() {
|
|
|
|
local s="$1"
|
|
|
|
local len=$(printf "$s" | wc -c)
|
|
|
|
printf "%04x$s" $((len + 4))
|
|
|
|
}
|
|
|
|
|
|
|
|
pktize_text() {
|
|
|
|
local s="$1"
|
|
|
|
pktize "$s"'\n'
|
|
|
|
}
|
|
|
|
|
|
|
|
pktize_delim() {
|
|
|
|
printf '0001'
|
|
|
|
}
|
|
|
|
|
|
|
|
pktize_flush() {
|
|
|
|
printf '0000'
|
|
|
|
}
|