fix: bug with finding merge-base

This commit is contained in:
Tonye Jack 2022-10-30 10:16:43 -06:00
parent 01870df0a9
commit 7f68648067

View File

@ -68,8 +68,8 @@ else
fi
function deepenShallowCloneToFindCommit() {
local ref="$1"
local target_branch="$2"
local target_branch="$1"
local ref="$2"
local depth=20
local max_depth=$INPUT_MAX_FETCH_DEPTH
@ -87,6 +87,26 @@ function deepenShallowCloneToFindCommit() {
done
}
function deepenShallowCloneToFindCommitPullRequest() {
local target_branch="$1"
local current_branch="$2"
local depth=20
local max_depth=$INPUT_MAX_FETCH_DEPTH
while ! git merge-base "$target_branch" "$current_branch" &>/dev/null; do
echo "::debug::Unable to find merge-base in shallow clone. Increasing depth to $((depth * 2))..."
depth=$((depth * 2))
if [[ $depth -gt $max_depth ]]; then
echo "::error::Unable to find merge-base in shallow clone. Please increase 'max_fetch_depth' to at least $depth."
exit 1
fi
git fetch --no-tags -u --progress --deepen="$depth" origin "$target_branch" "$current_branch"
done
}
if [[ -z $GITHUB_BASE_REF ]]; then
echo "Running on a push event..."
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} && exit_status=$? || exit_status=$?
@ -136,7 +156,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then
echo "::debug::Current branch $CURRENT_BRANCH..."
echo "::debug::Fetching previous commit SHA: $PREVIOUS_SHA"
deepenShallowCloneToFindCommit "$PREVIOUS_SHA" "$TARGET_BRANCH"
deepenShallowCloneToFindCommit "$TARGET_BRANCH" "$PREVIOUS_SHA"
echo "::debug::Verifying the previous commit SHA: $PREVIOUS_SHA"
git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?
@ -162,7 +182,7 @@ else
echo "::debug::Current branch: $CURRENT_BRANCH"
echo "::debug::Fetching previous commit SHA: $PREVIOUS_SHA"
deepenShallowCloneToFindCommit "$PREVIOUS_SHA" "$TARGET_BRANCH"
deepenShallowCloneToFindCommitPullRequest "$TARGET_BRANCH" "$CURRENT_BRANCH"
echo "::debug::Verifying the previous commit SHA: $PREVIOUS_SHA"
git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?