mirror of
https://github.com/tj-actions/changed-files
synced 2025-01-29 13:34:51 +00:00
fix: error fetch remote ref when using fetch depth of 1 (#996)
This commit is contained in:
parent
063e674726
commit
23e3c4300c
3 changed files with 27 additions and 12 deletions
|
@ -439,16 +439,9 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get Base SHA
|
||||
id: get-base-sha
|
||||
run: |
|
||||
echo "base_sha=$(git rev-parse "$(git tag --sort=-v:refname | head -n 2 | tail -n 1)")" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v35
|
||||
with:
|
||||
base_sha: ${{ steps.get-base-sha.outputs.base_sha }}
|
||||
|
||||
- name: Get changed files in the .github folder
|
||||
id: changed-files-specific
|
||||
|
|
|
@ -187,6 +187,7 @@ runs:
|
|||
GITHUB_REF: ${{ github.ref }}
|
||||
GITHUB_SHA: ${{ github.sha }}
|
||||
GITHUB_WORKSPACE: ${{ github.workspace }}
|
||||
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
|
||||
GITHUB_EVENT_HEAD_REPO_FORK: ${{ github.event.pull_request.head.repo.fork }}
|
||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
|
|
31
diff-sha.sh
31
diff-sha.sh
|
@ -9,10 +9,12 @@ PREVIOUS_SHA=""
|
|||
CURRENT_SHA=""
|
||||
DIFF="..."
|
||||
IS_TAG="false"
|
||||
SOURCE_BRANCH=""
|
||||
|
||||
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
|
||||
IS_TAG="true"
|
||||
EXTRA_ARGS="--prune --no-recurse-submodules"
|
||||
SOURCE_BRANCH=${GITHUB_EVENT_BASE_REF#refs/heads/}
|
||||
fi
|
||||
|
||||
if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF || "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then
|
||||
|
@ -52,15 +54,27 @@ else
|
|||
echo "Valid git version found: ($GIT_VERSION)"
|
||||
fi
|
||||
|
||||
IS_SHALLOW=$(git rev-parse --is-shallow-repository) && exit_status=$? || exit_status=$?
|
||||
|
||||
if [[ $exit_status -ne 0 ]]; then
|
||||
echo "::error::Unable to determine if the repository is shallow"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
|
||||
echo "Running on a push event..."
|
||||
TARGET_BRANCH=$GITHUB_REFNAME
|
||||
CURRENT_BRANCH=$TARGET_BRANCH
|
||||
|
||||
if $(git rev-parse --is-shallow-repository); then
|
||||
if [[ "$IS_SHALLOW" == "true" ]]; then
|
||||
echo "Fetching remote refs..."
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null
|
||||
if [[ "$IS_TAG" == "false" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null
|
||||
elif [[ "$SOURCE_BRANCH" != "" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +refs/heads/"$SOURCE_BRANCH":refs/remotes/origin/"$SOURCE_BRANCH" 1>/dev/null
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
git submodule foreach git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" || true
|
||||
fi
|
||||
|
@ -102,6 +116,13 @@ if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
|
|||
echo "::error::Unable to locate a previous commit for the specified date: $INPUT_SINCE"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$IS_TAG" == "true" ]]; then
|
||||
PREVIOUS_SHA=$(git rev-parse "$(git tag --sort=-v:refname | head -n 2 | tail -n 1)") && exit_status=$? || exit_status=$?
|
||||
|
||||
if [[ -z "$PREVIOUS_SHA" ]]; then
|
||||
echo "::error::Unable to locate a previous commit for the specified tag: $GITHUB_REF"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
|
||||
PREVIOUS_SHA=""
|
||||
|
@ -162,7 +183,7 @@ else
|
|||
TARGET_BRANCH=$CURRENT_BRANCH
|
||||
fi
|
||||
|
||||
if $(git rev-parse --is-shallow-repository); then
|
||||
if [[ "$IS_SHALLOW" == "true" ]]; then
|
||||
echo "Fetching remote refs..."
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_PULL_REQUEST_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null
|
||||
|
@ -213,7 +234,7 @@ else
|
|||
else
|
||||
PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH") && exit_status=$? || exit_status=$?
|
||||
|
||||
if $(git rev-parse --is-shallow-repository); then
|
||||
if [[ "$IS_SHALLOW" == "true" ]]; then
|
||||
# check if the merge base is in the local history
|
||||
if ! git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||
echo "::debug::Merge base is not in the local history, fetching remote target branch..."
|
||||
|
|
Loading…
Reference in a new issue