Skip to content

Commit

Permalink
Merge pull request #806 from tj-actions/fix/bug-with-retrieving-the-l…
Browse files Browse the repository at this point in the history
…ast-remote-commit

fix: bug with retrieving the last remote commit
  • Loading branch information
repo-ranger[bot] committed Nov 15, 2022
2 parents 3ebdc42 + e447432 commit ef0a290
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/sync-release-version.yml
@@ -1,8 +1,5 @@
name: Update release version.
on:
push:
tags:
- '**'
release:
types: [published]

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -27,6 +27,8 @@ jobs:
uses: actions/checkout@v3
- name: shellcheck
uses: reviewdog/action-shellcheck@v1.15
with:
github_token: ${{ secrets.PAT_TOKEN }}

test-multiple-repositories:
name: Test with multiple repositories
Expand Down Expand Up @@ -929,7 +931,7 @@ jobs:
with:
branch: ${{ steps.branch-name.outputs.base_ref_branch }}
workflow_id: 'test.yml'
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.PAT_TOKEN }}
- name: Run changed-files with a custom base sha
if: github.event_name == 'pull_request' && github.event.action != 'closed'
id: changed-files-custom-base-sha
Expand Down
17 changes: 8 additions & 9 deletions diff-sha.sh
Expand Up @@ -187,11 +187,8 @@ else
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE

if ! git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; then
PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
fi

if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
# shellcheck disable=SC2046
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=$?
Expand All @@ -214,16 +211,18 @@ else
depth=$INPUT_FETCH_DEPTH
max_depth=$INPUT_MAX_FETCH_DEPTH

while [ -z "$( git merge-base --fork-point "$TARGET_BRANCH" "$CURRENT_SHA" )" ] || [ -z "$(git merge-base "$TARGET_BRANCH" "$CURRENT_SHA")" ] || [ -z "$(git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" | head -1)" ]; do
depth=$((depth + 300))
while ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" 1>/dev/null; do
echo "Fetching $depth commits..."

# shellcheck disable=SC2086
git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" HEAD;
git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" "$CURRENT_SHA";

if [[ $depth -gt $max_depth ]]; then
echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and HEAD"
echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA"
exit 1
fi

depth=$((depth + 300))
done
else
echo "::debug::Not a shallow clone, skipping merge-base check."
Expand Down

0 comments on commit ef0a290

Please sign in to comment.