fix(ci): unshallow repo before merge in post-checkout hook#7037
Merged
ycombinator merged 2 commits intoMay 14, 2026
Conversation
The sparse-checkout Buildkite plugin (added in elastic#7029) creates a shallow clone with only a few hundred objects — enough for the pipeline files but without the full commit-ancestry chain. When the post-checkout hook then fetches the target branch and calls `git merge "${BUILDKITE_COMMIT}"`, git cannot walk back to a common ancestor and fails with "refusing to merge unrelated histories". Unshallow the repository before the merge so that git can resolve the merge base correctly. The `--depth=2147483647` fallback handles agents where the clone was not recorded as shallow by git. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If --unshallow fails the clone is not shallow, meaning full history is already present and the fallback fetch would be a no-op anyway. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
|
ebeahan
approved these changes
May 14, 2026
ebeahan
added a commit
that referenced
this pull request
May 20, 2026
* Revert "bk: run faster builds (#7029)" This reverts commit ded8d0a. * Revert "fix(ci): unshallow repo before merge in post-checkout hook (#7037)" This reverts commit 76e5002. --------- Co-authored-by: ebeahan <eric.beahan@elastic.co> Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #7029, which added the
sparse-checkout#v1.6.0Buildkite plugin tocatalog-info.yaml. Once merged, Buildkite updated its pipeline configuration globally, so all builds — including PRs targeting non-mainbranches — now use sparse checkout.The sparse clone fetches only ~180 git objects (the
.buildkiteand.go-versionfile trees), with no commit-ancestry chain. When.buildkite/hooks/post-checkoutthen fetches the target branch fully and callsgit merge "${BUILDKITE_COMMIT}", git cannot walk back through the truncated history to find the common ancestor and fails with:This broke all open PRs targeting non-
mainbranches (e.g. backport PRs to8.19such as #7036, #7030).Fix
Unshallow the repository before attempting the merge, so git can resolve the merge base correctly. If
--unshallowfails, the clone is not shallow and full history is already present, so we just continue.Test plan
8.19(e.g. [8.19](backport #7026) build(deps): bump the elastic-apm group across 1 directory with 6 updates #7036, [updatecli] update elastic stack version for testing 8.19.16-9ddb044b-SNAPSHOT #7030) pass the Buildkitepost-checkoutstep after this is merged and the same fix is backported to8.19🤖 Generated with Claude Code