From 5ce975c6021a0b11062c547acb6c26c96a34a8c5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 8 Mar 2023 20:02:52 -0700 Subject: [PATCH] fix: fetching history for pr made from a fork with checkout set to the target repository (#1007) --- diff-sha.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index b4049c3d..50ae2c3c 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -188,8 +188,14 @@ else if [[ "$IS_SHALLOW" == "true" ]]; then echo "Fetching remote refs..." - # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_PULL_REQUEST_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null + + if [[ "$GITHUB_EVENT_HEAD_REPO_FORK" != "true" ]]; then + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_PULL_REQUEST_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null + else + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS -u --progress origin "+refs/heads/$TARGET_BRANCH:refs/remotes/origin/$TARGET_BRANCH" "+refs/heads/$CURRENT_BRANCH*:refs/remotes/origin/$CURRENT_BRANCH*" 1>/dev/null + fi if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" != "true" ]]; then echo "::debug::Fetching remote target branch..."