Skip to content

Commit ac9c9d4

Browse files
committed
fix: ensure pull request branch name is unique
When a pull request is made by a user and they name their branch the same name as the target branch against which the pull request is being made, we run into a conflict, which causes the checkout to fail (see https://github.com/mezzio/mezzio-helpers/pull/7/checks?check_run_id=2393994090#step:3:9). To resolve this scenario, if we detect a pull_request, we can give the local branch name a prefix, `pull/`. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 4f21db5 commit ac9c9d4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

entrypoint.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ set -e
55
function checkout {
66
local REF=
77
local LOCAL_BRANCH=
8+
local LOCAL_BRANCH_NAME=
89
local BASE_BRANCH=
910

1011
if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
1112
return
1213
fi
1314

15+
LOCAL_BRANCH_NAME=$GITHUB_HEAD_REF
16+
1417
case $GITHUB_EVENT_NAME in
1518
pull_request)
1619
REF=$GITHUB_REF
@@ -21,6 +24,8 @@ function checkout {
2124
echo "Missing head or base ref env variables; aborting"
2225
exit 1
2326
fi
27+
28+
LOCAL_BRANCH_NAME=pull/${LOCAL_BRANCH_NAME}
2429
;;
2530
push)
2631
REF=${GITHUB_REF/refs\/heads\//}
@@ -54,9 +59,9 @@ function checkout {
5459
echo "Checking out branch ${BASE_BRANCH}"
5560
git checkout ${BASE_BRANCH}
5661
echo "Fetching target ref ${REF}"
57-
git fetch origin ${REF}:${GITHUB_HEAD_REF}
58-
echo "Checking out target ref to ${GITHUB_HEAD_REF}"
59-
git checkout ${GITHUB_HEAD_REF}
62+
git fetch origin ${REF}:${LOCAL_BRANCH_NAME}
63+
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
64+
git checkout ${LOCAL_BRANCH_NAME}
6065
fi
6166
}
6267

0 commit comments

Comments
 (0)