Skip to content

feat: add sparse checkout support - #3903

Merged
mcncl merged 11 commits into
mainfrom
SUP-6409/sparse_checkout
Jun 12, 2026
Merged

feat: add sparse checkout support#3903
mcncl merged 11 commits into
mainfrom
SUP-6409/sparse_checkout

Conversation

@mcncl

@mcncl mcncl commented May 7, 2026

Copy link
Copy Markdown
Contributor

Description

This adds sparse checkout support to the agent via BUILDKITE_GIT_SPARSE_CHECKOUT_PATHS, allowing checkout to materialize only selected paths in the working tree.

It also handles reused checkout directories safely by reconfiguring sparse checkout when paths change, and disabling sparse checkout when a later job does not request it.

Changes

  • adds git-sparse-checkout-paths support to agent start and bootstrap
  • propagates BUILDKITE_GIT_SPARSE_CHECKOUT_PATHS through the agent/bootstrap environment
  • runs Executor.setupSparseCheckout after fetch and before checkout
  • disables sparse checkout and restores a full checkout when later jobs on the same checkout dir do not request sparse paths
  • extracts sparse checkout logic and tests into focused files:
    • internal/job/checkout_sparse.go
    • internal/job/checkout_sparse_test.go

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Disclosures / Credits

I used Codex to assist with writing this change. The core function (non _test.go) changes were implemented by me, I then used Codex to assist with writing the Test functions.

I used Amp to check the changes, which it highlighted a couple of issues with (fixed) and a missing test case (added).

Comment thread internal/job/checkout.go Outdated
Comment thread agent/job_runner.go Outdated
@mcncl
mcncl force-pushed the SUP-6409/sparse_checkout branch from 318d9ef to 163cbea Compare May 7, 2026 05:00
@mcncl
mcncl marked this pull request as ready for review May 7, 2026 05:08
@mcncl
mcncl requested review from a team as code owners May 7, 2026 05:08

@DrJosh9000 DrJosh9000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first reaction is "why not _Git_SparseCheckoutPaths", but I'm not fussed

Comment thread clicommand/global.go Outdated
@mcncl

mcncl commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@DrJosh9000 thats a fair call and removes any chance of ambiguity

Copy link
Copy Markdown
Contributor

@mcncl - do not merge these changes into main. These changes should be merged into the branch feat/git-checkout-features

@mcncl
mcncl force-pushed the SUP-6409/sparse_checkout branch from 163cbea to 9e93039 Compare May 7, 2026 23:11
@mcncl
mcncl changed the base branch from main to feat/git-checkout-features May 7, 2026 23:12

@zhming0 zhming0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some suggestions re code organization, increase signal-to-noise ratio on integration test and adding an e2e test. 🙏🏿

so far no blocker, but I plan to take another look later 👀

Comment thread agent/job_runner.go
Comment thread internal/job/integration/checkout_integration_test.go Outdated
Comment thread internal/job/checkout.go
Comment thread internal/job/checkout_test.go
Comment thread internal/job/checkout.go Outdated
@mcncl
mcncl changed the base branch from feat/git-checkout-features to main June 1, 2026 00:34
@mcncl
mcncl force-pushed the SUP-6409/sparse_checkout branch from f844882 to a93473e Compare June 1, 2026 02:18
@mcncl mcncl added the feature New user-facing feature! label Jun 1, 2026
Comment thread agent/job_runner.go
@quinn-diesel

Copy link
Copy Markdown
Contributor

hey @mcncl i think there's one things to fix up with the lint and we can get this merged

@mcncl

mcncl commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@quinn-diesel cheers mate. Ran out of time today but will get this sorted first thing

@mcncl
mcncl requested a review from Copilot June 12, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds git sparse checkout (cone mode) support to the Buildkite agent/executor via BUILDKITE_GIT_SPARSE_CHECKOUT_PATHS, including handling reuse of checkout directories by reconfiguring or disabling sparse checkout appropriately, and updating integration/unit tests to cover the new behavior.

Changes:

  • Add a new executor/agent config surface (--git-sparse-checkout-paths, BUILDKITE_GIT_SPARSE_CHECKOUT_PATHS) and propagate it through agent → bootstrap → executor.
  • Run sparse checkout setup after fetch and before checkout; disable sparse checkout when not requested.
  • Skip submodule initialization when sparse checkout is active, and add coverage in unit/integration tests.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/job/integration/checkout_integration_test.go Adds sparse checkout integration coverage (basic behavior, reconfigure existing checkout dir, disable/restore full tree, and submodule skip behavior).
internal/job/integration/checkout_git_mirrors_integration_test.go Adds sparse checkout coverage when using git mirrors.
internal/job/config.go Adds GitSparseCheckoutPaths to executor config mapped from BUILDKITE_GIT_SPARSE_CHECKOUT_PATHS.
internal/job/config_test.go Extends env→config mapping test to include sparse checkout paths.
internal/job/checkout.go Invokes sparse checkout setup in the checkout flow; skips submodule init when sparse checkout is active.
internal/job/checkout_sparse.go Introduces sparse-checkout enable/disable logic, git version gating, and “reuse checkout dir” safety behavior.
internal/job/checkout_sparse_test.go Adds unit tests for sparse checkout path cleaning, git version parsing, enable/disable flows, and fallbacks.
clicommand/global.go Adds --git-sparse-checkout-paths CLI flag shared across commands.
clicommand/bootstrap.go Wires sparse checkout paths into bootstrap config and executor config construction.
clicommand/agent_start.go Wires sparse checkout paths into agent start config and runtime agent configuration.
agent/job_runner.go Propagates sparse checkout paths into the bootstrap/job environment.
agent/agent_configuration.go Adds GitSparseCheckoutPaths to runtime agent configuration struct.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/job/config.go
Comment thread internal/job/config_test.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mcncl
mcncl merged commit 78f27fe into main Jun 12, 2026
4 checks passed
@mcncl
mcncl deleted the SUP-6409/sparse_checkout branch June 12, 2026 02:05
@buildkate buildkate mentioned this pull request Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New user-facing feature!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants