2024-01-26 00:48:55 +03:00
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
2024-06-04 16:25:03 +03:00
set -o nounset
2024-01-26 00:48:55 +03:00
2024-06-04 16:25:03 +03:00
if ((${NO_SYNC:-0})); then
2024-05-30 17:24:42 +03:00
exit 0
2024-01-26 00:48:55 +03:00
fi
2024-05-30 17:24:42 +03:00
PKG_SUBDIR="$(realpath --canonicalize-missing "pkg/$DISTRIBUTION" --relative-to "$PWD")"
2024-07-02 23:27:01 +03:00
if [[ -d "$PKG_SUBDIR/.git" ]]; then
if [[ "$(git -C "$PKG_SUBDIR" rev-parse HEAD)" == "$GIT_COMMIT" ]]; then
exit 0
fi
# If work is being done on the packaging rules in a separate branch, don't touch the checkout.
2024-07-03 23:18:07 +03:00
if ! git -C "$PKG_SUBDIR" merge-base --is-ancestor HEAD "origin/$GIT_BRANCH"; then
2024-07-03 14:19:34 +03:00
EXIT_STATUS=$?
if [[ $EXIT_STATUS -eq 1 ]]; then
exit 0
else
exit $EXIT_STATUS
fi
2024-07-02 23:27:01 +03:00
fi
2024-05-30 17:24:42 +03:00
fi
if [[ ! -e "$PKG_SUBDIR" ]] || [[ -z "$(ls --almost-all "$PKG_SUBDIR")" ]]; then
2024-06-06 14:23:17 +03:00
# The repository on Salsa has the full upstream sources, so it's a waste of
# space to redownload and duplicate everything, so do a sparse checkout as
# we only need the packaging directory anyway.
if [[ -n "${GIT_SUBDIR:-}" ]]; then
sparse=(--no-checkout --filter=tree:0)
else
sparse=()
fi
2024-06-06 02:14:37 +03:00
git clone "$GIT_URL" --branch "$GIT_BRANCH" "${sparse[@]}" "$PKG_SUBDIR"
if [[ -n "${GIT_SUBDIR:-}" ]]; then
# --no-cone is needed to check out only one top-level directory
git -C "$PKG_SUBDIR" sparse-checkout set --no-cone "${GIT_SUBDIR:-}"
fi
2024-05-30 17:24:42 +03:00
else
git -C "$PKG_SUBDIR" remote set-url origin "$GIT_URL"
git -C "$PKG_SUBDIR" fetch origin "$GIT_BRANCH"
fi
git -C "$PKG_SUBDIR" -c advice.detachedHead=false checkout "$GIT_COMMIT"