Skip to content

fix(ci): unshallow repo before merge in post-checkout hook#7037

Merged
ycombinator merged 2 commits into
elastic:mainfrom
ycombinator:fix/post-checkout-sparse-clone
May 14, 2026
Merged

fix(ci): unshallow repo before merge in post-checkout hook#7037
ycombinator merged 2 commits into
elastic:mainfrom
ycombinator:fix/post-checkout-sparse-clone

Conversation

@ycombinator
Copy link
Copy Markdown
Contributor

@ycombinator ycombinator commented May 14, 2026

Problem

Follow-up to #7029, which added the sparse-checkout#v1.6.0 Buildkite plugin to catalog-info.yaml. Once merged, Buildkite updated its pipeline configuration globally, so all builds — including PRs targeting non-main branches — now use sparse checkout.

The sparse clone fetches only ~180 git objects (the .buildkite and .go-version file trees), with no commit-ancestry chain. When .buildkite/hooks/post-checkout then fetches the target branch fully and calls git merge "${BUILDKITE_COMMIT}", git cannot walk back through the truncated history to find the common ancestor and fails with:

fatal: refusing to merge unrelated histories

This broke all open PRs targeting non-main branches (e.g. backport PRs to 8.19 such as #7036, #7030).

Fix

Unshallow the repository before attempting the merge, so git can resolve the merge base correctly. If --unshallow fails, the clone is not shallow and full history is already present, so we just continue.

Test plan

🤖 Generated with Claude Code

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>
@ycombinator ycombinator requested a review from a team as a code owner May 14, 2026 17:46
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>
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 14, 2026

This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@ycombinator ycombinator enabled auto-merge (squash) May 14, 2026 17:50
@ycombinator ycombinator added backport-skip Skip notification from the automated backport with mergify Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog labels May 14, 2026
@ebeahan ebeahan mentioned this pull request May 14, 2026
8 tasks
@ycombinator ycombinator merged commit 76e5002 into elastic:main May 14, 2026
13 checks passed
@ycombinator ycombinator deleted the fix/post-checkout-sparse-clone branch May 14, 2026 19:35
ebeahan added a commit that referenced this pull request 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-skip Skip notification from the automated backport with mergify skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants