Skip to content

Commit

Permalink
Merge pull request #29 from weierophinney/hotfix/pull_request_branch
Browse files Browse the repository at this point in the history
Ensure pull request branch name does not cause collisions
  • Loading branch information
weierophinney committed Apr 20, 2021
2 parents 4f21db5 + ac9c9d4 commit 5f70dd5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ set -e
function checkout {
local REF=
local LOCAL_BRANCH=
local LOCAL_BRANCH_NAME=
local BASE_BRANCH=

if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
return
fi

LOCAL_BRANCH_NAME=$GITHUB_HEAD_REF

case $GITHUB_EVENT_NAME in
pull_request)
REF=$GITHUB_REF
Expand All @@ -21,6 +24,8 @@ function checkout {
echo "Missing head or base ref env variables; aborting"
exit 1
fi

LOCAL_BRANCH_NAME=pull/${LOCAL_BRANCH_NAME}
;;
push)
REF=${GITHUB_REF/refs\/heads\//}
Expand Down Expand Up @@ -54,9 +59,9 @@ function checkout {
echo "Checking out branch ${BASE_BRANCH}"
git checkout ${BASE_BRANCH}
echo "Fetching target ref ${REF}"
git fetch origin ${REF}:${GITHUB_HEAD_REF}
echo "Checking out target ref to ${GITHUB_HEAD_REF}"
git checkout ${GITHUB_HEAD_REF}
git fetch origin ${REF}:${LOCAL_BRANCH_NAME}
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
git checkout ${LOCAL_BRANCH_NAME}
fi
}

Expand Down

0 comments on commit 5f70dd5

Please sign in to comment.