From 427b9f931d9ecaa450594be881e9753fa9bbad8f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 15 Dec 2022 12:20:18 -0700 Subject: [PATCH 1/5] feat: fallback to fork-point --- diff-sha.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 752705a28c6..8d9ac33de2a 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -248,15 +248,17 @@ else for ((i=0; i/dev/null 2>&1; then break + else + PREVIOUS_SHA=$(git merge-base --fork-point "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? fi - + echo "Fetching $i commits..." # shellcheck disable=SC2086 git fetch $EXTRA_ARGS -u --progress --deepen="$i" origin $TARGET_BRANCH $CURRENT_SHA 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 07a1f5a72313438509bbf67045a003e51163bb21 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 15 Dec 2022 12:29:39 -0700 Subject: [PATCH 2/5] 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 8d9ac33de2a..82e5d5df8f2 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -249,7 +249,11 @@ else if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then break else - PREVIOUS_SHA=$(git merge-base --fork-point "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + NEW_PREVIOUS_SHA=$(git merge-base --fork-point "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + + if [[ -n "$NEW_PREVIOUS_SHA" ]]; then + PREVIOUS_SHA=$NEW_PREVIOUS_SHA + fi fi echo "Fetching $i commits..." From bfbf803f41c4c5c6848f64bd62fa733fc21fd3a6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 15 Dec 2022 12:37:34 -0700 Subject: [PATCH 3/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 82e5d5df8f2..580f151d2ef 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -245,7 +245,7 @@ else depth=$INPUT_FETCH_DEPTH max_depth=$INPUT_MAX_FETCH_DEPTH - for ((i=0; i/dev/null 2>&1; then break else From f195837047b6b34430b32594ffd8a0f45fdbdbcf Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 15 Dec 2022 13:08:16 -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 580f151d2ef..4d6efb73c9a 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -245,7 +245,7 @@ else depth=$INPUT_FETCH_DEPTH max_depth=$INPUT_MAX_FETCH_DEPTH - for ((i=0; i/dev/null 2>&1; then break else From 0dbccaa8084bc9d32e52661c0304bb7b8ce6792a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 15 Dec 2022 20:11:14 -0700 Subject: [PATCH 5/5] Update diff-sha.sh --- diff-sha.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 4d6efb73c9a..5090dd2b0d2 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -66,7 +66,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi else if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + CURRENT_SHA=$(git rev-list -n 1 HEAD) && exit_status=$? || exit_status=$? else # shellcheck disable=SC2086 git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" 1>/dev/null 2>&1 @@ -102,7 +102,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then PREVIOUS_SHA=$GITHUB_EVENT_BEFORE fi else - PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH") && exit_status=$? || exit_status=$? if [[ -z "$PREVIOUS_SHA" ]]; then if [[ "$GITHUB_EVENT_FORCED" == "false" || -z "$GITHUB_EVENT_FORCED" ]]; then @@ -199,12 +199,12 @@ else fi else if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + CURRENT_SHA=$(git rev-list -n 1 HEAD) && exit_status=$? || exit_status=$? else CURRENT_SHA=$INPUT_SHA; exit_status=$? if [[ "$CURRENT_SHA" == "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" ]]; then - CURRENT_SHA=$(git rev-list -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + CURRENT_SHA=$(git rev-list -n 1 HEAD) && exit_status=$? || exit_status=$? fi fi fi @@ -227,7 +227,7 @@ else PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then - PREVIOUS_SHA=$(git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA") && exit_status=$? || exit_status=$? fi fi @@ -249,7 +249,7 @@ else if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then break else - NEW_PREVIOUS_SHA=$(git merge-base --fork-point "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + NEW_PREVIOUS_SHA=$(git merge-base --fork-point "$PREVIOUS_SHA" "$CURRENT_SHA") && exit_status=$? || exit_status=$? if [[ -n "$NEW_PREVIOUS_SHA" ]]; then PREVIOUS_SHA=$NEW_PREVIOUS_SHA