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:
Tonye Jack 2023-02-06 18:25:06 -07:00 committed by GitHub
parent 2c684aedfa
commit 210cc839c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View file

@ -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: |

View file

@ -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