From 3e92344b74d916a704374134f8b515ab3c628cc1 Mon Sep 17 00:00:00 2001 From: minottic Date: Mon, 25 Nov 2024 11:23:25 +0100 Subject: [PATCH] Simplify git setup by exiting on .git presence --- entrypoints/setup_git.sh | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/entrypoints/setup_git.sh b/entrypoints/setup_git.sh index 6b6ddac3..4ea357f6 100755 --- a/entrypoints/setup_git.sh +++ b/entrypoints/setup_git.sh @@ -2,25 +2,21 @@ [ -e ".finished" ] && return 0 -apk update && apk add git - -git remote || INIT=true +ls .git && return 0 echo "${GITHUB_REPO}" | grep -q "#" && TAG="${GITHUB_REPO#*#}" || TAG= -if [ "${INIT}" ] +apk update && apk add git +git init +chown -R "$(find . -maxdepth 1 -exec ls -ld {} + | awk '{print $3":"$4}' | tail -n1)" .git +git config --global --add safe.directory "${PWD}" +REPO="${GITHUB_REPO%%#*}" +git remote add origin "${REPO}" +git fetch +DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') +git reset --hard origin/"${DEFAULT_BRANCH}" +git clean -fd +if [ -n "${TAG}" ] then - git init - chown -R "$(find . -maxdepth 1 -exec ls -ld {} + | awk '{print $3":"$4}' | tail -n1)" .git - git config --global --add safe.directory "${PWD}" - REPO="${GITHUB_REPO%%#*}" - git remote add origin "${REPO}" - git fetch - DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') - git reset --hard origin/"${DEFAULT_BRANCH}" - git clean -fd - if [ -n "${TAG}" ] - then - git checkout "${TAG}" - fi + git checkout "${TAG}" fi