Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify git setup by exiting on .git presence #385

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
minottic marked this conversation as resolved.
Show resolved Hide resolved
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