From fe47f7dc4cb90f70c60419239ef9e9aa1852a1bc Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 16 Nov 2022 11:29:35 -0700 Subject: [PATCH 01/10] fix: pulling current branch history --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 3cdd64ef38c..bbcca9cdd85 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -215,7 +215,7 @@ else echo "Fetching $depth commits..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" "$CURRENT_SHA"; + git fetch -u --progress $EXTRA_ARGS --deepen="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From fe3a37012f2aeb085358c28900539b133d2cdf4c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 16 Nov 2022 11:46:53 -0700 Subject: [PATCH 02/10] Update action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 1f1b9475858..8be22421ddf 100644 --- a/action.yml +++ b/action.yml @@ -78,9 +78,9 @@ inputs: required: false default: "false" fetch_depth: - description: "Limit depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." + description: "Initial depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false - default: "40" + default: "10" max_fetch_depth: description: "Maximum depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false From 3b10cebd3dfde60872124e155e6072beee48cb44 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 16 Nov 2022 21:06:22 -0700 Subject: [PATCH 03/10] 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 bbcca9cdd85..9ddfb9c0450 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -215,7 +215,7 @@ else echo "Fetching $depth commits..." # shellcheck disable=SC2086 - git fetch -u --progress $EXTRA_ARGS --deepen="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" + git fetch -u --progress $EXTRA_ARGS --depth="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From 30b9252953b1451f1d0964e563f3440936a2a13f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 08:16:17 -0700 Subject: [PATCH 04/10] Updated diff-sha.sh --- action.yml | 2 +- diff-sha.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 8be22421ddf..160846a6794 100644 --- a/action.yml +++ b/action.yml @@ -80,7 +80,7 @@ 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: "10" + default: "40" max_fetch_depth: description: "Maximum depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false diff --git a/diff-sha.sh b/diff-sha.sh index 9ddfb9c0450..69a0d9e97c0 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -191,7 +191,7 @@ else PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base --fork-point "$CURRENT_BRANCH" "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then From 6ea66cc12943e547d71e23bd15a8c7fa6db5f1db Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 08:24:46 -0700 Subject: [PATCH 05/10] Updated diff-sha.sh --- diff-sha.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 69a0d9e97c0..43897eb604a 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -5,6 +5,8 @@ set -euo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} EXTRA_ARGS="--no-tags" +PREVIOUS_SHA="" +CURRENT_SHA="" if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then EXTRA_ARGS="" @@ -191,7 +193,7 @@ else PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git merge-base --fork-point "$CURRENT_BRANCH" "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then From 61fac4da4baf4e41345262aed26ae7a7744dda33 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 08:28:46 -0700 Subject: [PATCH 06/10] Updated diff-sha.sh --- diff-sha.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 43897eb604a..acbd95f42d0 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -193,7 +193,7 @@ else PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base --fork-point "$CURRENT_BRANCH" "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then @@ -217,7 +217,9 @@ else echo "Fetching $depth commits..." # shellcheck disable=SC2086 - git fetch -u --progress $EXTRA_ARGS --depth="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" + git fetch -u --progress $EXTRA_ARGS --deepen="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" + # set up branch tracking + git branch --track "$GITHUB_REF" origin/"$CURRENT_BRANCH" 2>/dev/null || true if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From 0efacabbb5792e8411dd06aaf9b66a4c14b14442 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 12:05:17 -0700 Subject: [PATCH 07/10] Update diff-sha.sh --- diff-sha.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index acbd95f42d0..9154bff8116 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -193,7 +193,7 @@ else PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git merge-base --fork-point "$CURRENT_BRANCH" "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then @@ -217,9 +217,7 @@ else echo "Fetching $depth commits..." # shellcheck disable=SC2086 - git fetch -u --progress $EXTRA_ARGS --deepen="$depth" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" - # set up branch tracking - git branch --track "$GITHUB_REF" origin/"$CURRENT_BRANCH" 2>/dev/null || true + git fetch $EXTRA_ARGS -u --progress --deepen="$depth" if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From 2ed48aa52fce4483eead4e3388844037d9f5c359 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 12:25:27 -0700 Subject: [PATCH 08/10] Update diff-sha.sh --- diff-sha.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/diff-sha.sh b/diff-sha.sh index 9154bff8116..79c9cca8cf4 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -147,6 +147,10 @@ else echo "Running on a pull request event..." TARGET_BRANCH=$GITHUB_BASE_REF CURRENT_BRANCH=$GITHUB_HEAD_REF + + if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then + TARGET_BRANCH=$CURRENT_BRANCH + fi echo "Fetching remote refs..." From 96ce8da4f680a4b2aa8292f77b6822205fb89b4a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 12:32:34 -0700 Subject: [PATCH 09/10] 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 79c9cca8cf4..167fe8a48c8 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -221,7 +221,7 @@ else echo "Fetching $depth commits..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$depth" + git fetch $EXTRA_ARGS -u --progress --deepen="$depth" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From 7b68fcd08242de76b024a1810a1586f1922830d9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 17 Nov 2022 12:59:15 -0700 Subject: [PATCH 10/10] Update diff-sha.sh --- diff-sha.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 167fe8a48c8..2c583f281e7 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -194,10 +194,14 @@ else if ! git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; then # shellcheck disable=SC2046 - PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-parse origin/"$CURRENT_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi else PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? + + if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" 1>/dev/null 2>&1; then + PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + fi fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then