feat: skip merge-base check for non shallow clones and fallback to using --fork-point
This commit is contained in:
parent
43835a2749
commit
ac07453ae9
36
diff-sha.sh
36
diff-sha.sh
@ -152,20 +152,6 @@ else
|
|||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
git fetch $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH"
|
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
|
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
|
fi
|
||||||
|
|
||||||
echo "::debug::Getting HEAD SHA..."
|
echo "::debug::Getting HEAD SHA..."
|
||||||
@ -196,6 +182,28 @@ else
|
|||||||
echo "::debug::Current SHA: $CURRENT_SHA"
|
echo "::debug::Current SHA: $CURRENT_SHA"
|
||||||
fi
|
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 [[ -z $INPUT_BASE_SHA ]]; then
|
||||||
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
|
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
|
||||||
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
|
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user