Skip to content

Commit

Permalink
Simplify git setup by exiting on .git presence
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Nov 26, 2024
1 parent 3465ed7 commit 3e92344
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions entrypoints/setup_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e92344

Please sign in to comment.