From a5164ab012257f827a1e70500ae934b4f5a17a68 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 28 Apr 2020 18:54:00 -0400 Subject: [PATCH] handle empty branch --- posix/clone-commit | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/posix/clone-commit b/posix/clone-commit index 641a9ca..358ecaf 100755 --- a/posix/clone-commit +++ b/posix/clone-commit @@ -10,6 +10,19 @@ if [ ! -d .git ]; then git remote add origin ${DRONE_REMOTE_URL} fi +# 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 + git checkout -qf ${DRONE_COMMIT_SHA} + exit 0 +fi + set -e set -x