From ac07453ae902f9fceaa802bbddb9fc7c33e3e240 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 11 Nov 2022 07:28:34 -0700 Subject: [PATCH 1/5] feat: skip merge-base check for non shallow clones and fallback to using --fork-point --- diff-sha.sh | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 3c1762a5..3a8680f9 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -152,20 +152,6 @@ else # shellcheck disable=SC2086 git fetch $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true - - depth=$INPUT_FETCH_DEPTH - - while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do - # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" HEAD; - depth=$((depth * 10)) - max_depth=$INPUT_MAX_FETCH_DEPTH - - if [[ $depth -gt $max_depth ]]; then - echo "::error::Unable to find merge-base between $TARGET_BRANCH and HEAD." - exit 1 - fi - done fi echo "::debug::Getting HEAD SHA..." @@ -196,6 +182,28 @@ else echo "::debug::Current SHA: $CURRENT_SHA" fi + if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then + if [[ -f .git/shallow ]]; then + depth=$INPUT_FETCH_DEPTH + + while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" HEAD; + depth=$((depth * 10)) + max_depth=$INPUT_MAX_FETCH_DEPTH + + if [[ $depth -gt $max_depth ]]; then + if [ -z "$(git merge-base --fork-point "$TARGET_BRANCH" HEAD)" ]; then + echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and HEAD" + exit 1 + fi + fi + done + else + echo "::debug::Not a shallow clone, skipping merge-base check." + fi + fi + if [[ -z $INPUT_BASE_SHA ]]; then if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then PREVIOUS_SHA=$GITHUB_EVENT_BEFORE From c21087a6bb221974446adb4acf5f2dfe145637a6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 11 Nov 2022 07:33:01 -0700 Subject: [PATCH 2/5] updated test --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fedd5d55..ad97ea35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -299,7 +299,7 @@ jobs: uses: ./ continue-on-error: true with: - base_sha: "4554456" + sha: "4554456" - name: Show output run: | @@ -319,7 +319,7 @@ jobs: continue-on-error: true with: files: action.yml - base_sha: "4554456" + sha: "4554456" - name: Show output run: | From 2e4e6363923a537f9acbc4ec0ba5fd9caa9bfa46 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 11 Nov 2022 07:39:00 -0700 Subject: [PATCH 3/5] Updated the retrieving the merge-base --- diff-sha.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 3a8680f9..85137c35 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -185,18 +185,17 @@ else if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then if [[ -f .git/shallow ]]; then depth=$INPUT_FETCH_DEPTH + max_depth=$INPUT_MAX_FETCH_DEPTH + + while [ -z "$( git merge-base --fork-point "$TARGET_BRANCH" HEAD )" ] || [ -z "$(git merge-base "$TARGET_BRANCH" HEAD)" ]; do + depth=$((depth + 300)) - while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do # shellcheck disable=SC2086 git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" HEAD; - depth=$((depth * 10)) - max_depth=$INPUT_MAX_FETCH_DEPTH if [[ $depth -gt $max_depth ]]; then - if [ -z "$(git merge-base --fork-point "$TARGET_BRANCH" HEAD)" ]; then - echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and HEAD" - exit 1 - fi + echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and HEAD" + exit 1 fi done else From 56a01f8a9ec6d46dc6d54e879691e39174ddc996 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 11 Nov 2022 07:44:25 -0700 Subject: [PATCH 4/5] Update arguments --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 85137c35..0a9034f7 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -150,7 +150,7 @@ else if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" + git fetch -u $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true fi From 443b6c32e773943887c9a272038053754d28946d Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 11 Nov 2022 07:47:09 -0700 Subject: [PATCH 5/5] Show progress --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 0a9034f7..60f440cd 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -150,7 +150,7 @@ else if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then # shellcheck disable=SC2086 - git fetch -u $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" + git fetch -u --progress $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true fi