fix: diff generation for PR checkouts
actions/checkout for PRs only fetches refs/pull/N/head into FETCH_HEAD. Remote tracking branches (origin/main) don't exist. Fix: explicit refspec fetch (refs/heads/main:refs/remotes/origin/main) with fallback to GITEA_BASE_REF / GITHUB_BASE_REF for the target branch. Also removed --filter=blob:none which could cause empty diffs. Added diagnostic logging for base ref and file stats.
This commit is contained in:
@@ -73,15 +73,35 @@ echo "::endgroup::"
|
|||||||
# ─── Phase 2: Generate diff ───────────────────────────────────────────────────
|
# ─── Phase 2: Generate diff ───────────────────────────────────────────────────
|
||||||
echo "::group::Generate diff"
|
echo "::group::Generate diff"
|
||||||
|
|
||||||
# Ensure we have full history (runner may have done a shallow checkout)
|
# actions/checkout for PRs only fetches the PR ref (refs/pull/N/head).
|
||||||
git fetch --unshallow --filter=blob:none origin 2>/dev/null || true
|
# It does NOT create remote tracking branches like origin/main.
|
||||||
git fetch origin main 2>/dev/null || git fetch origin master 2>/dev/null || true
|
# We must explicitly fetch the base branch.
|
||||||
|
|
||||||
BASE="origin/main"
|
# Unshallow if needed (fetch-depth: 0 already does this, but be safe)
|
||||||
if ! git rev-parse --verify "$BASE" >/dev/null 2>&1; then
|
git fetch --unshallow origin 2>/dev/null || true
|
||||||
|
|
||||||
|
# Fetch base branch with explicit refspec to ensure origin/main exists
|
||||||
|
if git fetch origin refs/heads/main:refs/remotes/origin/main 2>/dev/null; then
|
||||||
|
BASE="origin/main"
|
||||||
|
elif git fetch origin refs/heads/master:refs/remotes/origin/master 2>/dev/null; then
|
||||||
BASE="origin/master"
|
BASE="origin/master"
|
||||||
|
else
|
||||||
|
# Fallback: try Gitea/GitHub event context for the target branch
|
||||||
|
TARGET_BRANCH="${GITEA_BASE_REF:-${GITHUB_BASE_REF:-}}"
|
||||||
|
if [ -n "${TARGET_BRANCH}" ] && git fetch origin "refs/heads/${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" 2>/dev/null; then
|
||||||
|
BASE="origin/${TARGET_BRANCH}"
|
||||||
|
else
|
||||||
|
echo "::warning::Could not fetch base branch. Trying origin/HEAD."
|
||||||
|
git fetch origin 2>/dev/null || true
|
||||||
|
BASE="origin/HEAD"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Base ref: ${BASE} -> $(git rev-parse --short "${BASE}" 2>/dev/null || echo 'NOT FOUND')"
|
||||||
|
echo "HEAD: $(git rev-parse --short HEAD)"
|
||||||
|
echo "Files changed:"
|
||||||
|
git diff --stat "${BASE}...HEAD" 2>/dev/null | tail -3 || echo "(could not stat diff)"
|
||||||
|
|
||||||
# Build exclude pathspecs
|
# Build exclude pathspecs
|
||||||
EXCLUDE_ARGS=""
|
EXCLUDE_ARGS=""
|
||||||
for pattern in $PI_EXCLUDE; do
|
for pattern in $PI_EXCLUDE; do
|
||||||
|
|||||||
Reference in New Issue
Block a user