mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-16 19:27:39 +00:00
Updated to fetch the common ancestor
This commit is contained in:
parent
1ae6035162
commit
6497e8ef99
2 changed files with 29 additions and 6 deletions
|
@ -176,6 +176,7 @@ runs:
|
|||
GITHUB_EVENT_HEAD_REPO_FORK: ${{ github.event.pull_request.head.repo.fork }}
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
GITHUB_EVENT_PULL_REQUEST_COMMITS: ${{ github.event.pull_request.commits }}
|
||||
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
|
||||
GITHUB_EVENT_FORCED: ${{ github.event.forced }}
|
||||
GITHUB_REFNAME: ${{ github.ref_name }}
|
||||
|
|
34
diff-sha.sh
34
diff-sha.sh
|
@ -4,13 +4,13 @@ set -euo pipefail
|
|||
|
||||
INITIAL_COMMIT="false"
|
||||
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
|
||||
EXTRA_ARGS="--no-tags"
|
||||
EXTRA_ARGS="--no-tags --prune --no-recurse-submodules"
|
||||
PREVIOUS_SHA=""
|
||||
CURRENT_SHA=""
|
||||
DIFF="..."
|
||||
|
||||
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
|
||||
EXTRA_ARGS=""
|
||||
EXTRA_ARGS="--prune --no-recurse-submodules"
|
||||
fi
|
||||
|
||||
if [[ "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then
|
||||
|
@ -162,6 +162,28 @@ else
|
|||
# shellcheck disable=SC2086
|
||||
git fetch -u --progress $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null 2>&1
|
||||
git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 1>/dev/null 2>&1 || true
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --depth=$(( GITHUB_EVENT_PULL_REQUEST_COMMITS + 1 )) origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1
|
||||
|
||||
COMMON_ANCESTOR=$(git rev-list --first-parent --max-parents=0 --max-count=1 origin/"$CURRENT_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
|
||||
|
||||
if [[ -z "$COMMON_ANCESTOR" ]]; then
|
||||
echo "::error::Unable to locate a common ancestor for the current branch: $CURRENT_BRANCH"
|
||||
exit 1
|
||||
else
|
||||
echo "::debug::Common ancestor: $COMMON_ANCESTOR"
|
||||
fi
|
||||
|
||||
DATE=$(git log --date=iso8601 --format=%cd "${COMMON_ANCESTOR}")
|
||||
|
||||
if [[ -z "$DATE" ]]; then
|
||||
echo "::error::Unable to locate a date for the common ancestor: $COMMON_ANCESTOR"
|
||||
exit 1
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS --shallow-since="${DATE}" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null 2>&1
|
||||
echo "::debug::Date: $DATE"
|
||||
fi
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --depth="$INPUT_FETCH_DEPTH" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1
|
||||
|
@ -221,14 +243,14 @@ else
|
|||
max_depth=$INPUT_MAX_FETCH_DEPTH
|
||||
|
||||
for ((i=depth; i<max_depth; i+=depth)); do
|
||||
if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
|
||||
echo "Fetching $i commits..."
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --depth="$i" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1
|
||||
|
||||
if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if ((i >= max_depth)); then
|
||||
|
|
Loading…
Reference in a new issue