Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip merge-base check for non shallow clones and fallback to using --fork-point #798

Merged
merged 5 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
uses: ./
continue-on-error: true
with:
base_sha: "4554456"
sha: "4554456"

- name: Show output
run: |
Expand All @@ -319,7 +319,7 @@ jobs:
continue-on-error: true
with:
files: action.yml
base_sha: "4554456"
sha: "4554456"

- name: Show output
run: |
Expand Down
37 changes: 22 additions & 15 deletions diff-sha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,8 @@ 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 --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

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..."
Expand Down Expand Up @@ -196,6 +182,27 @@ 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
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))

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

if [[ $depth -gt $max_depth ]]; then
echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and HEAD"
exit 1
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
Expand Down