website-build: Enable to use specific revisions for git repositories.

This for instance enable users to manually override the revisions to
test branches of git repositories.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
This commit is contained in:
Denis 'GNUtoo' Carikli 2023-10-11 14:12:08 +02:00 committed by Adrien 'neox' Bourmault
parent dc6e1f32c1
commit 0ef17277de
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
1 changed files with 10 additions and 0 deletions

View File

@ -52,19 +52,29 @@ sync_repo()
dst_path="$1" dst_path="$1"
src_uri="$2" src_uri="$2"
src_path="$3" src_path="$3"
src_revision="$4"
if [ -z "${src_path}" ] && [ ! -d "${dst_path}" ] ; then if [ -z "${src_path}" ] && [ ! -d "${dst_path}" ] ; then
git clone "${src_uri}" "${dst_path}" git clone "${src_uri}" "${dst_path}"
git -C "${dst_path}" checkout "${src_revision}"
elif [ ! -d "${dst_path}" ] ; then elif [ ! -d "${dst_path}" ] ; then
mkdir -p "$(dirname ${dst_path})" mkdir -p "$(dirname ${dst_path})"
cp -a "${src_path}" "${dst_path}" cp -a "${src_path}" "${dst_path}"
if [ -n "${src_revision}" ] ; then
git -C "${dst_path}" checkout "${src_revision}"
fi
elif [ -z "${src_path}" ] ; then elif [ -z "${src_path}" ] ; then
git -C "${dst_path}" remote get-url origin || \
git -C "${dst_path}" remote add origin "${src_uri}"
git -C "${dst_path}" remote set-url origin "${src_uri}" git -C "${dst_path}" remote set-url origin "${src_uri}"
git -C "${dst_path}" clean -dfx git -C "${dst_path}" clean -dfx
git -C "${dst_path}" pull --rebase git -C "${dst_path}" pull --rebase
else else
rm -rf "${dst_path}" rm -rf "${dst_path}"
cp -a "${src_path}" "${dst_path}" cp -a "${src_path}" "${dst_path}"
if [ -n "${src_revision}" ] ; then
git -C "${dst_path}" checkout "${src_revision}"
fi
fi fi
} }