From 9e0389c5ae77268cde15245c675363ea919f8d46 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:04:31 -0700 Subject: [PATCH 1/5] 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" From bb675e1715dee2d01b8b12daa1122c5580070018 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:05:54 -0700 Subject: [PATCH 2/5] Update action.yml --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 483c70fc..310ccec8 100644 --- a/action.yml +++ b/action.yml @@ -88,7 +88,6 @@ inputs: description: "Maximum depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false default: "5000" - deprecationMessage: "This input is deprecated and will be removed in a future release." since_last_remote_commit: description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events." required: true From a1a2be24bd7f1ebaaf35a8979d2e54d8c017d66e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:17:48 -0700 Subject: [PATCH 3/5] Update diff-sha.sh --- diff-sha.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 290fd7b2..5fd11e19 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -253,10 +253,10 @@ else echo "Fetching $i commits..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$i" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" + git fetch $EXTRA_ARGS -u --progress --depth="$i" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1 done - if ((i >= max_depth)); then + 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 From 9dc80210cfea593a0c2f4e81b5a3c3c7dbc3ca5c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:32:25 -0700 Subject: [PATCH 4/5] Update diff-sha.sh --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 5fd11e19..752705a2 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -253,7 +253,7 @@ else echo "Fetching $i commits..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --depth="$i" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1 + git fetch $EXTRA_ARGS -u --progress --deepen="$i" origin $TARGET_BRANCH $CURRENT_SHA 1>/dev/null 2>&1 done if ((i > max_depth)); then From 7a06bb7247828d94fa8b21755264634fc036e65d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 14 Dec 2022 08:49:41 -0700 Subject: [PATCH 5/5] Update action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 310ccec8..0e21d02f 100644 --- a/action.yml +++ b/action.yml @@ -83,11 +83,11 @@ inputs: fetch_depth: description: "Initial depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false - default: "40" + default: "50" max_fetch_depth: description: "Maximum depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false - default: "5000" + default: "6000" since_last_remote_commit: description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events." required: true