mirror of
https://github.com/tj-actions/changed-files
synced 2025-02-20 21:01:53 +00:00
Merge pull request #810 from tj-actions/fix/pulling-current-branch-history
fix: pulling current branch history
This commit is contained in:
commit
3996bc3fde
2 changed files with 14 additions and 4 deletions
|
@ -78,7 +78,7 @@ inputs:
|
|||
required: false
|
||||
default: "false"
|
||||
fetch_depth:
|
||||
description: "Limit depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
|
||||
description: "Initial depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
|
||||
required: false
|
||||
default: "40"
|
||||
max_fetch_depth:
|
||||
|
|
16
diff-sha.sh
16
diff-sha.sh
|
@ -5,6 +5,8 @@ set -euo pipefail
|
|||
INITIAL_COMMIT="false"
|
||||
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
|
||||
EXTRA_ARGS="--no-tags"
|
||||
PREVIOUS_SHA=""
|
||||
CURRENT_SHA=""
|
||||
|
||||
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
|
||||
EXTRA_ARGS=""
|
||||
|
@ -145,6 +147,10 @@ else
|
|||
echo "Running on a pull request event..."
|
||||
TARGET_BRANCH=$GITHUB_BASE_REF
|
||||
CURRENT_BRANCH=$GITHUB_HEAD_REF
|
||||
|
||||
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
|
||||
TARGET_BRANCH=$CURRENT_BRANCH
|
||||
fi
|
||||
|
||||
echo "Fetching remote refs..."
|
||||
|
||||
|
@ -188,10 +194,14 @@ else
|
|||
|
||||
if ! git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; then
|
||||
# shellcheck disable=SC2046
|
||||
PREVIOUS_SHA=$(git rev-parse $(git branch -r --sort=-committerdate | head -1) 2>&1) && exit_status=$? || exit_status=$?
|
||||
PREVIOUS_SHA=$(git rev-parse origin/"$CURRENT_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
|
||||
fi
|
||||
else
|
||||
PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
|
||||
PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$?
|
||||
|
||||
if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||
PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then
|
||||
|
@ -215,7 +225,7 @@ else
|
|||
echo "Fetching $depth commits..."
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" "$CURRENT_SHA";
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$depth" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH"
|
||||
|
||||
if [[ $depth -gt $max_depth ]]; then
|
||||
echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA"
|
||||
|
|
Loading…
Add table
Reference in a new issue