Option to fetch the base branch during checkout, not just for pipeline upload's if_changed diff
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 378
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 74
Description
## Is your feature request related to a problem? Please describe.
A job's checkout fetches `refs/pull/N/head` plus the commit (or the commit alone for a branch build). None of those update a branch's remote-tracking ref, so `refs/remotes/origin/` in a reused checkout directory holds whatever an earlier build left there — stale by an unbounded amount, with nothing in the log to say so.
`--fetch-diff-base` / `BUILDKITE_FETCH_DIFF_BASE` solves this for `buildkite-agent pipeline upload`'s own `if_changed` diff. Anything else in the job that asks what changed — a pipeline generator, a test selector, a script running `git merge-base HEAD origin/main` — still reads the stale ref. A stale base only ever widens a diff, so nothing fails and nobody notices.
The fix today is per step: a plugin, or an explicit `git fetch` in the command. Every new step has to remember it, and a step that forgot looks identical to one that didn't.
## Describe the solution you'd like
An agent-level option, off by default, that fetches the base branch during checkout so every job in the build starts from its current tip: `--git-fetch-base-branch` / `BUILDKITE_GIT_FETCH_BASE_BRANCH`, on `agent start` and `bootstrap`.
## Describe alternatives you've considered
- `BUILDKITE_GIT_FETCH_FLAGS`: flags land before `--`, so it cannot add a refspec.
- `BUILDKITE_REFSPEC`: replaces the PR fetch rather than adding to it.
- `--fetch-diff-base`: scoped to `pipeline upload`, and only to the diff it computes itself.
## Affiliation (optional)
Altana.
## Additional context
Happy to send a PR — I have one ready.
Contributor guide
Research direction
Start at the agent start and bootstrap checkout paths, then read the existing --fetch-diff-base handling and Git refspec construction. Trace how CLI options and BUILDKITE_* environment variables are wired into checkout. Done means an off-by-default base-branch fetch is available through both entry points and updates the base remote-tracking ref for reused checkouts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, go
- Domain
- ci-cd, devops
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100