2015-05-18 19:44:22 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
# $ assert_pointer "master" "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
|
|
|
|
2015-05-22 22:11:44 +00:00
|
|
|
tree=$(git ls-tree -lr "$ref")
|
|
|
|
gitblob=$(echo "$tree" | grep "$path" | cut -f 3 -d " ")
|
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
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/objects/$oid" \
|
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
|
|
|
-H "Accept: application/vnd.git-lfs+json" 2>&1 |
|
|
|
|
tee http.log
|
|
|
|
|
|
|
|
grep "404 Not Found" http.log
|
2015-05-18 22:49:21 +00:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
curl -v "$GITSERVER/$reponame.git/info/lfs/objects/$oid" \
|
|
|
|
-u "user:pass" \
|
|
|
|
-o http.json \
|
|
|
|
-H "Accept: application/vnd.git-lfs+json" 2>&1 |
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# pointer returns a string Git LFS pointer file.
|
|
|
|
#
|
|
|
|
# $ pointer abc-some-oid 123
|
|
|
|
# > version ...
|
2015-05-18 22:49:21 +00:00
|
|
|
pointer() {
|
|
|
|
local oid=$1
|
|
|
|
local size=$2
|
|
|
|
printf "version https://git-lfs.github.com/spec/v1
|
|
|
|
oid sha256:%s
|
|
|
|
size %s
|
|
|
|
" "$oid" "$size"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
while [ $n -lt 10 ]; do
|
2015-05-18 19:44:22 +00:00
|
|
|
if [ -s $filename ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 0.5
|
2015-05-18 19:58:58 +00:00
|
|
|
n=`expr $n + 1`
|
2015-05-18 19:44:22 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:54:15 +00:00
|
|
|
# setup_remote_repo intializes a bare Git repository that is accessible through
|
|
|
|
# the test Git server. The `pwd` is set to the repository's directory, in case
|
|
|
|
# further commands need to be run. This server is running for every test in a
|
|
|
|
# script/integration run, so every test file should setup its own remote
|
|
|
|
# repository to avoid conflicts.
|
|
|
|
#
|
|
|
|
# $ 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-05-19 22:54:15 +00:00
|
|
|
# clone_repo clones a repository from the test Git server to the subdirectory
|
|
|
|
# $dir under $TRASHDIR. setup_remote_repo() needs to be run first.
|
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-05-18 22:49:21 +00:00
|
|
|
echo "$out"
|
2015-05-18 19:44:22 +00:00
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
|
2015-05-21 20:48:02 +00:00
|
|
|
rm -rf "$REMOTEDIR"
|
|
|
|
mkdir "$REMOTEDIR"
|
2015-05-18 22:49:21 +00:00
|
|
|
|
2015-06-19 16:58:30 +00:00
|
|
|
if [ -z "$SKIPCOMPILE" ] && [ -z "$LFS_BIN" ]; then
|
2015-05-21 17:51:40 +00:00
|
|
|
echo "compile git-lfs for $0"
|
2015-06-07 15:40:35 +00:00
|
|
|
script/bootstrap || {
|
|
|
|
return $?
|
|
|
|
}
|
2015-05-21 17:51:40 +00:00
|
|
|
fi
|
|
|
|
|
2015-07-06 17:21:50 +00:00
|
|
|
echo "Git LFS: ${LFS_BIN:-$(which git-lfs)}"
|
2015-05-26 15:39:04 +00:00
|
|
|
git lfs version
|
2015-06-19 16:59:45 +00:00
|
|
|
git version
|
2015-05-18 19:44:22 +00:00
|
|
|
|
2015-05-21 17:51:40 +00:00
|
|
|
if [ -z "$SKIPCOMPILE" ]; then
|
|
|
|
for go in test/cmd/*.go; do
|
|
|
|
go build -o "$BINPATH/$(basename $go .go)" "$go"
|
|
|
|
done
|
|
|
|
fi
|
2015-05-18 19:44:22 +00:00
|
|
|
|
2015-05-21 21:01:35 +00:00
|
|
|
echo "tmp dir: $TMPDIR"
|
|
|
|
echo "remote git dir: $REMOTEDIR"
|
2015-05-18 22:49:21 +00:00
|
|
|
echo "LFSTEST_URL=$LFS_URL_FILE LFSTEST_DIR=$REMOTEDIR lfstest-gitserver"
|
2015-06-19 16:59:45 +00:00
|
|
|
echo
|
2015-05-18 23:29:29 +00:00
|
|
|
LFSTEST_URL="$LFS_URL_FILE" LFSTEST_DIR="$REMOTEDIR" lfstest-gitserver > "$REMOTEDIR/gitserver.log" 2>&1 &
|
2015-05-26 15:39:04 +00:00
|
|
|
|
|
|
|
mkdir $HOME
|
2015-06-28 12:48:59 +00:00
|
|
|
git lfs init
|
|
|
|
git config --global credential.helper lfstest
|
|
|
|
git config --global user.name "Git LFS Tests"
|
|
|
|
git config --global user.email "git-lfs@example.com"
|
|
|
|
grep "git-lfs clean" "$REMOTEDIR/home/.gitconfig" > /dev/null || {
|
|
|
|
echo "global git config should be set in $REMOTEDIR/home"
|
|
|
|
ls -al "$REMOTEDIR/home"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
cp "$HOME/.gitconfig" "$HOME/.gitconfig-backup"
|
2015-05-26 15:39:04 +00:00
|
|
|
|
2015-07-24 11:54:43 +00:00
|
|
|
if [[ `git config --system credential.helper | grep osxkeychain` == "osxkeychain" ]]
|
|
|
|
then
|
|
|
|
# Only OS X will encounter this
|
|
|
|
# We can't disable osxkeychain and it gets called on store as well as ours,
|
|
|
|
# reporting "A keychain cannot be found to store.." errors because the test
|
|
|
|
# user env has no keychain; so create one
|
|
|
|
# Note deliberately not using $HOME in case anything goes wrong overriding that,
|
|
|
|
# we do not want to stomp on the user's main keychain by accident!
|
|
|
|
security create-keychain -p pass $REMOTEDIR/home/Library/Keychains/login.keychain
|
|
|
|
fi
|
|
|
|
|
2015-05-18 22:49:21 +00:00
|
|
|
wait_for_file "$LFS_URL_FILE"
|
|
|
|
}
|
|
|
|
|
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() {
|
2015-05-21 16:27:40 +00:00
|
|
|
# every test/test-*.sh file should cleanup its trashdir
|
|
|
|
[ -z "$KEEPTRASH" ] && rm -rf "$TRASHDIR"
|
2015-05-18 23:15:32 +00:00
|
|
|
|
2015-05-19 21:13:21 +00:00
|
|
|
if [ "$SHUTDOWN_LFS" != "no" ]; then
|
2015-05-21 16:27:40 +00:00
|
|
|
# only cleanup test/remote after script/integration done OR a single
|
|
|
|
# test/test-*.sh file is run manually.
|
2015-05-19 21:13:21 +00:00
|
|
|
if [ -s "$LFS_URL_FILE" ]; then
|
|
|
|
curl "$(cat "$LFS_URL_FILE")/shutdown"
|
|
|
|
fi
|
2015-07-24 11:54:43 +00:00
|
|
|
|
|
|
|
if [[ `git config --system credential.helper | grep osxkeychain` == "osxkeychain" ]]
|
|
|
|
then
|
|
|
|
# explicitly clean up keychain to make sure search list doesn't look for it
|
|
|
|
# Note deliberately not using $HOME in case anything goes wrong overriding that,
|
|
|
|
# we do not want to stomp on the user's main keychain by accident!
|
|
|
|
security delete-keychain $REMOTEDIR/home/Library/Keychains/login.keychain
|
|
|
|
fi
|
|
|
|
|
2015-06-24 20:38:10 +00:00
|
|
|
[ -z "$KEEPTRASH" ] && rm -rf "$REMOTEDIR"
|
2015-07-24 11:54:43 +00:00
|
|
|
|
2015-05-18 23:57:43 +00:00
|
|
|
fi
|
2015-07-24 11:54:43 +00:00
|
|
|
|
2015-05-18 19:44:22 +00:00
|
|
|
}
|