2023-10-01 16:54:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -x
|
2018-08-08 21:43:53 +00:00
|
|
|
|
|
|
|
FLAGS=""
|
2023-10-01 16:54:37 +00:00
|
|
|
if [[ -n "${PLUGIN_DEPTH}" ]]; then
|
2018-08-08 21:43:53 +00:00
|
|
|
FLAGS="--depth=${PLUGIN_DEPTH}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d .git ]; then
|
|
|
|
git init
|
2023-10-01 16:54:37 +00:00
|
|
|
git remote add origin "${DRONE_REMOTE_URL}"
|
2018-08-08 21:43:53 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-28 22:54:00 +00:00
|
|
|
# the branch may be empty for certain event types,
|
|
|
|
# such as github deployment events. If the branch
|
|
|
|
# is empty we checkout the sha directly. Note that
|
|
|
|
# we intentially omit depth flags to avoid failed
|
|
|
|
# clones due to lack of history.
|
|
|
|
if [[ -z "${DRONE_COMMIT_BRANCH}" ]]; then
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
git fetch origin
|
2023-10-01 16:54:37 +00:00
|
|
|
git checkout --quiet --force "${DRONE_COMMIT_SHA}"
|
2020-04-28 22:54:00 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-10-29 14:18:31 +00:00
|
|
|
# the commit sha may be empty for builds that are
|
|
|
|
# manually triggered in Harness CI Enterprise. If
|
2020-10-29 14:27:49 +00:00
|
|
|
# the commit is empty we clone the branch.
|
2020-10-29 10:37:40 +00:00
|
|
|
if [[ -z "${DRONE_COMMIT_SHA}" ]]; then
|
|
|
|
set -e
|
|
|
|
set -x
|
2023-10-01 16:54:37 +00:00
|
|
|
git fetch "${FLAGS}" origin "+refs/heads/${DRONE_COMMIT_BRANCH}:"
|
|
|
|
git checkout -b "${DRONE_COMMIT_BRANCH}" "origin/${DRONE_COMMIT_BRANCH}"
|
2020-10-29 10:37:40 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-08-08 21:43:53 +00:00
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2023-10-01 16:54:37 +00:00
|
|
|
git fetch "${FLAGS}" origin "+refs/heads/${DRONE_COMMIT_BRANCH}:"
|
|
|
|
git checkout "${DRONE_COMMIT_SHA}" -b "${DRONE_COMMIT_BRANCH}"
|