From 744fdd40e742dac4cb1b080e8a8396af5db11f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20-=20Le=20Filament?= <theo@le-filament.com> Date: Mon, 12 Aug 2024 13:59:14 +0200 Subject: [PATCH] feat(build): remove module directory when already exists and improve git repo cloning --- get_addons | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/get_addons b/get_addons index b3e52d4..6f5bb5b 100644 --- a/get_addons +++ b/get_addons @@ -5,6 +5,7 @@ set -e ODOO_ROOT_DIR=${ODOO_ROOT_DIR:-'/opt/odoo'} SAVE_COMMITS_DIR=${SAVE_COMMITS_DIR:-'/opt/odoo_commits'} SAVE_COMMITS_FILENAME=${SAVE_COMMITS_FILENAME:-'custom_addons'} +TMP_REPO_PATH='/tmp/repo' save_commit() { repo="$1" @@ -22,18 +23,36 @@ dst="$1" shift modules="$@" -git clone --filter=tree:0 "${repo}" /tmp/repo -git -C /tmp/repo checkout "${ref}" +set +e +git clone --branch "${ref}" --filter=tree:0 "${repo}" "${TMP_REPO_PATH}" +if [ "$?" != 0 ]; then + git clone --filter=tree:0 "${repo}" "${TMP_REPO_PATH}" + if [ "$?" != 0 ]; then + git clone --single-branch --branch "${ref}" --depth 1 "${repo}" "${TMP_REPO_PATH}" + if [ "$?" != 0 ]; then + git clone "${repo}" "${TMP_REPO_PATH}" + fi + fi +fi +set -e + +git -C "${TMP_REPO_PATH}" checkout "${ref}" commit="$(git -C /tmp/repo rev-parse HEAD)" if [ -n "$modules" ]; then for module in $modules; do + if [ -d "${ODOO_ROOT_DIR}/${dst}/${module}" ]; then + rm -r "${ODOO_ROOT_DIR}/${dst}/${module}" + fi mv "/tmp/repo/${module}" "${ODOO_ROOT_DIR}/${dst}/" save_commit "$repo" "$commit" "$module" "$dst" done else module="$(basename $dst)" + if [ -d "${ODOO_ROOT_DIR}/${dst}" ]; then + rm -r "${ODOO_ROOT_DIR}/${dst}" + fi mkdir -p "/${ODOO_ROOT_DIR}/${dst}" - mv /tmp/repo/* "${ODOO_ROOT_DIR}/${dst}/" + mv ${TMP_REPO_PATH}/* "${ODOO_ROOT_DIR}/${dst}/" save_commit "$repo" "$commit" "$module" "$dst" fi -rm -r /tmp/repo +rm -r "${TMP_REPO_PATH}" -- GitLab