31 lines
1.0 KiB
Bash
31 lines
1.0 KiB
Bash
set -euo pipefail
|
|
umask 077
|
|
export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1
|
|
|
|
running=$1
|
|
[[ $running =~ ^[0-9a-f]{40}$ ]]
|
|
ref="refs/heads/$SEIUGW_UPDATE_BRANCH"
|
|
remote="$SEIUGW_UPDATE_REMOTE"
|
|
tip=$(timeout --kill-after=1s 8s git ls-remote --exit-code --refs -- "$remote" "$ref")
|
|
tip=${tip%%$'\t'*}
|
|
[[ $tip =~ ^[0-9a-f]{40}$ ]]
|
|
if [[ $tip == "$running" ]]; then
|
|
printf 'current %s\n' "$tip"
|
|
exit 0
|
|
fi
|
|
|
|
# Check ancestry in a temporary repository. The update worker owns the live checkout.
|
|
probe=$(mktemp -d)
|
|
trap 'rm -rf -- "$probe"' EXIT
|
|
git init --quiet --bare "$probe"
|
|
timeout --kill-after=1s 18s git -C "$probe" fetch --quiet --no-tags -- "$remote" "$ref"
|
|
tip=$(git -C "$probe" rev-parse FETCH_HEAD)
|
|
if [[ $tip == "$running" ]]; then
|
|
printf 'current %s\n' "$tip"
|
|
elif git -C "$probe" cat-file -e "$running^{commit}" 2>/dev/null &&
|
|
git -C "$probe" merge-base --is-ancestor "$running" "$tip"; then
|
|
printf 'available %s\n' "$tip"
|
|
else
|
|
printf 'incompatible %s\n' "$tip"
|
|
fi
|