2024-01-25 22:48:55 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
set -e
|
2024-06-04 15:25:03 +02:00
|
|
|
set -o nounset
|
2024-01-25 22:48:55 +01:00
|
|
|
|
2024-07-11 16:09:15 +02:00
|
|
|
if ((${NO_SYNC:-0})) || ((${NO_BUILD:-0})); then
|
2024-05-30 16:24:42 +02:00
|
|
|
exit 0
|
2024-01-25 22:48:55 +01:00
|
|
|
fi
|
2024-05-30 16:24:42 +02:00
|
|
|
|
2024-07-22 10:22:48 +02:00
|
|
|
if [[ -d "pkg/$PKG_SUBDIR/.git" ]]; then
|
2024-09-20 15:58:32 +02:00
|
|
|
if [[ "$(git -C "pkg/$PKG_SUBDIR" rev-parse HEAD 2>/dev/null)" == "$GIT_COMMIT" ]]; then
|
2024-07-02 22:27:01 +02:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2024-10-02 10:50:59 +02:00
|
|
|
if [[ -n "$(git -C "pkg/$PKG_SUBDIR" status --porcelain)" ]]; then
|
2025-03-21 14:30:34 +01:00
|
|
|
echo "pkg/$PKG_SUBDIR is dirty, not checking out commit $GIT_COMMIT" >&2
|
2024-10-02 10:50:59 +02:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2024-07-22 10:22:48 +02:00
|
|
|
if ! git -C "pkg/$PKG_SUBDIR" show-ref --quiet "origin/$GIT_BRANCH"; then
|
|
|
|
|
git -C "pkg/$PKG_SUBDIR" remote set-url origin "$GIT_URL"
|
|
|
|
|
git -C "pkg/$PKG_SUBDIR" fetch origin "$GIT_BRANCH"
|
2024-07-12 15:33:49 +02:00
|
|
|
fi
|
|
|
|
|
|
2024-07-02 22:27:01 +02:00
|
|
|
# If work is being done on the packaging rules in a separate branch, don't touch the checkout.
|
2025-09-03 11:25:57 +02:00
|
|
|
if [[ -z "$(git -C "pkg/$PKG_SUBDIR" branch --remotes --list "origin/*" --contains HEAD)" ]]; then
|
|
|
|
|
echo "Currently checked out pkg/$PKG_SUBDIR commit is not part of any origin branch, not checking out commit $GIT_COMMIT" >&2
|
|
|
|
|
exit 0
|
2024-07-02 22:27:01 +02:00
|
|
|
fi
|
2024-05-30 16:24:42 +02:00
|
|
|
fi
|
|
|
|
|
|
2024-07-22 10:22:48 +02:00
|
|
|
if [[ ! -e "pkg/$PKG_SUBDIR" ]] || [[ -z "$(ls --almost-all "pkg/$PKG_SUBDIR")" ]]; then
|
2024-06-06 13:23:17 +02: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-07-22 10:22:48 +02:00
|
|
|
git clone "$GIT_URL" --branch "$GIT_BRANCH" "${sparse[@]}" "pkg/$PKG_SUBDIR"
|
2024-06-06 00:14:37 +01:00
|
|
|
if [[ -n "${GIT_SUBDIR:-}" ]]; then
|
|
|
|
|
# --no-cone is needed to check out only one top-level directory
|
2024-07-22 10:22:48 +02:00
|
|
|
git -C "pkg/$PKG_SUBDIR" sparse-checkout set --no-cone "${GIT_SUBDIR:-}"
|
2024-06-06 00:14:37 +01:00
|
|
|
fi
|
2024-09-20 15:58:32 +02:00
|
|
|
elif ! git -C "pkg/$PKG_SUBDIR" cat-file -e "$GIT_COMMIT^{commit}" 2>/dev/null; then
|
2024-07-22 10:22:48 +02:00
|
|
|
git -C "pkg/$PKG_SUBDIR" remote set-url origin "$GIT_URL"
|
|
|
|
|
git -C "pkg/$PKG_SUBDIR" fetch origin "$GIT_BRANCH"
|
2024-05-30 16:24:42 +02:00
|
|
|
fi
|
|
|
|
|
|
2024-07-22 10:22:48 +02:00
|
|
|
git -C "pkg/$PKG_SUBDIR" -c advice.detachedHead=false checkout "$GIT_COMMIT"
|