Skip to content

Commit 83186f8

Browse files
committed
fix: Make netlify-fetch immune to stale cached release branches
Production builds failed with antora unable to find a commit on release-26.7: the branch had been force-pushed after creation, the old tip only survived as a local ref in the netlify build cache, and the loop's ref update had failed silently (background auto-gc can race the ref update; -q swallowed the error and the loop continued). - Branch list from git ls-remote instead of the cached remote-tracking refs (which make expanded before the fetch even ran, so a brand-new release branch was invisible to its first build). - gc.auto=0 inside the loop, no more silent failures: set -e aborts the build at the failing command instead of surfacing as a missing-object error from antora much later. - git fetch --all --prune keeps the remote-tracking refs honest.
1 parent 1f51229 commit 83186f8

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ netlify-fetch:
6363
# netlify messes with some files, restore everything to how it was:
6464
git reset --hard
6565
# fetch, because netlify does caching and we want to get the latest commits
66-
git fetch --all
67-
for remote in $(shell git branch -r | grep -E 'release[/-]'); do \
68-
branch="$${remote#origin/}"; \
69-
git fetch -q origin "+refs/heads/$$branch:refs/heads/$$branch"; \
70-
git checkout -q "$$branch" -- ':(exclude)ui' . ; \
66+
git fetch --all --prune
67+
# The branch list comes from the remote so it is current even on the first
68+
# build after a new release branch appears (the cached remote-tracking refs
69+
# lag behind). Auto-gc is disabled inside the loop: a background gc can
70+
# race the ref updates and silently leave a stale local branch behind,
71+
# which only surfaces much later as a missing-object error from antora.
72+
# Failures abort the build immediately instead.
73+
set -e; for branch in $$(git ls-remote --heads origin | sed 's|.*refs/heads/||' | grep -E 'release[/-]'); do \
74+
git -c gc.auto=0 fetch origin "+refs/heads/$$branch:refs/heads/$$branch"; \
75+
git -c gc.auto=0 checkout -q "$$branch" -- ':(exclude)ui' . ; \
7176
done
7277
# restore the working tree of the current commit and drop files that
7378
# only exist on other branches (ignored files like node_modules stay)

0 commit comments

Comments
 (0)