mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-17 13:47:20 +00:00
fix: including non branch changes in diff output (#973)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
2c684aedfa
commit
210cc839c2
2 changed files with 20 additions and 5 deletions
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
|
@ -210,6 +210,7 @@ jobs:
|
|||
matrix:
|
||||
platform: [ubuntu-latest]
|
||||
fetch-depth: [1, 2]
|
||||
input-fetch_depth: [1, 50]
|
||||
|
||||
steps:
|
||||
- name: Checkout to branch
|
||||
|
@ -220,6 +221,8 @@ jobs:
|
|||
- name: Run changed-files
|
||||
id: changed-files
|
||||
uses: ./
|
||||
with:
|
||||
fetch_depth: ${{ matrix.input-fetch_depth }}
|
||||
|
||||
- name: Show output
|
||||
run: |
|
||||
|
|
22
diff-sha.sh
22
diff-sha.sh
|
@ -168,8 +168,7 @@ else
|
|||
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" != "true" ]]; then
|
||||
echo "::debug::Fetching remote target branch..."
|
||||
# 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
|
||||
git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 1>/dev/null 2>&1 || true
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH:$TARGET_BRANCH" 1>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -209,10 +208,23 @@ else
|
|||
PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA
|
||||
fi
|
||||
else
|
||||
PREVIOUS_SHA=$(git merge-base "$TARGET_BRANCH" "$CURRENT_SHA") && exit_status=$? || exit_status=$?
|
||||
PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH") && exit_status=$? || exit_status=$?
|
||||
|
||||
if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||
PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH") && exit_status=$? || exit_status=$?
|
||||
if [[ -f .git/shallow ]]; then
|
||||
# check if the merge base is in the local history
|
||||
if ! git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA"; then
|
||||
echo "::debug::Merge base is not in the local history, fetching remote target branch..."
|
||||
# Fetch more of the target branch history until the merge base is found
|
||||
for i in {1..10}; do
|
||||
# shellcheck disable=SC2086
|
||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH:$TARGET_BRANCH" 1>/dev/null
|
||||
if git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA"; then
|
||||
break
|
||||
fi
|
||||
echo "::debug::Merge base is not in the local history, fetching remote target branch again..."
|
||||
echo "::debug::Attempt $i/10"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in a new issue