Skip to content

Commit e47d327

Browse files
gnodetclaude
andcommitted
ci: progressively deepen fetch for merge-base reachability
Instead of a fixed --depth=200 fetch that can miss the merge base for long-lived or stale branches, try 200 → 1000 → unshallow until git merge-base succeeds. Most PRs resolve at depth 200 (no extra cost); only old branches need the deeper fetches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8feb3d6 commit e47d327

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

.github/workflows/pr-build-main.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,24 @@ jobs:
8484
if: ${{ !inputs.skip_full_build }}
8585
run: |
8686
# Scalpel needs the merge base between HEAD and the base branch.
87-
# The checkout is depth=1, so deepen both sides for merge-base reachability.
88-
git fetch --deepen=200 2>/dev/null || true
89-
git fetch --no-tags --depth=200 origin "${GITHUB_BASE_REF:-main}:refs/remotes/origin/${GITHUB_BASE_REF:-main}"
87+
# The checkout is depth=1, so we progressively deepen until the
88+
# merge base is reachable: 200 → 1000 → full history.
89+
BASE_REF="${GITHUB_BASE_REF:-main}"
90+
for depth in 200 1000; do
91+
git fetch --deepen=$depth 2>/dev/null || true
92+
git fetch --no-tags --depth=$depth origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}"
93+
if git merge-base HEAD "origin/${BASE_REF}" >/dev/null 2>&1; then
94+
echo "Merge base reachable at depth $depth"
95+
break
96+
fi
97+
echo "Merge base not reachable at depth $depth, deepening..."
98+
done
99+
# If still not reachable, fetch full history as last resort
100+
if ! git merge-base HEAD "origin/${BASE_REF}" >/dev/null 2>&1; then
101+
echo "Merge base still not reachable, fetching full history"
102+
git fetch --unshallow 2>/dev/null || true
103+
git fetch --no-tags origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}"
104+
fi
90105
- id: install-packages
91106
uses: ./.github/actions/install-packages
92107
- id: install-mvnd

0 commit comments

Comments
 (0)