From 9e0389c5ae77268cde15245c675363ea919f8d46 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:04:31 -0700 Subject: [PATCH] feat: add support for pulling more history --- diff-sha.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/diff-sha.sh b/diff-sha.sh index cb17a364..290fd7b2 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -239,6 +239,32 @@ else else PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$? fi + + if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then + if [[ -f .git/shallow ]]; then + depth=$INPUT_FETCH_DEPTH + max_depth=$INPUT_MAX_FETCH_DEPTH + + for ((i=0; i/dev/null 2>&1; then + break + fi + + echo "Fetching $i commits..." + + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS -u --progress --deepen="$i" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" + done + + if ((i >= max_depth)); then + echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_BRANCH with: $PREVIOUS_SHA$DIFF$CURRENT_SHA" + exit 1 + fi + else + echo "::debug::Not a shallow clone, skipping merge-base check." + fi + fi + echo "::debug::Target branch: $TARGET_BRANCH" echo "::debug::Current branch: $CURRENT_BRANCH"