3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-17 13:47:20 +00:00

Update diff-sha.sh

This commit is contained in:
Tonye Jack 2022-11-03 06:18:03 -06:00 committed by GitHub
parent b9e70f7821
commit 4054514874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,28 +67,6 @@ else
echo "::debug::Current SHA: $CURRENT_SHA"
fi
function deepenShallowCloneToFindCommit() {
local base_ref="$1"
local diff="$2"
local ref="$3"
local target_branch="$4"
local depth=20
local max_depth=$INPUT_MAX_FETCH_DEPTH
while ! git diff "$base_ref$diff$ref" &>/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 + 20))."
exit 1
fi
git fetch --no-tags -u --progress --depth="$depth" origin "$target_branch":"$target_branch"
done
}
if [[ -z $GITHUB_BASE_REF ]]; then
echo "Running on a push event..."
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} && exit_status=$? || exit_status=$?
@ -140,9 +118,6 @@ if [[ -z $GITHUB_BASE_REF ]]; then
echo "::debug::Target branch $TARGET_BRANCH..."
echo "::debug::Current branch $CURRENT_BRANCH..."
echo "::debug::Fetching previous commit SHA: $PREVIOUS_SHA"
deepenShallowCloneToFindCommit "$PREVIOUS_SHA" ".." "$CURRENT_SHA" "$TARGET_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=$?
@ -172,9 +147,6 @@ else
echo "::debug::Target branch: $TARGET_BRANCH"
echo "::debug::Current branch: $CURRENT_BRANCH"
echo "::debug::Fetching previous commit SHA: $PREVIOUS_SHA"
deepenShallowCloneToFindCommit "$PREVIOUS_SHA" "..." "$CURRENT_SHA" "$TARGET_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=$?