Skip to content

feat: support sparse + shallow git clones - #481

Draft
GavinPJK wants to merge 5 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/sparse-clone
Draft

feat: support sparse + shallow git clones#481
GavinPJK wants to merge 5 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/sparse-clone

Conversation

@GavinPJK

@GavinPJK GavinPJK commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Add --sparse-checkout and --sparse-checkout-pattern flags to promote, applying to both cluster and application repositories:
    • Add a default sparse-checkout pattern set (helmfile.yaml, helmfiles/, .jx/, env/) used when no explicit patterns are given
    • Derive and add the sparse-checkout pattern for file/kpt promote rules at runtime, since those rules write to arbitrary paths not covered by the defaults
    • Fall back to a full clone when the git server does not support sparse checkout
    • Disable shallow cloning for forks, which must rebase against full upstream history
  • Add unit tests and integration tests

Context

Fully cloning the environment and application repositories is slow and wasteful when:

  • a promotion only touches a handful of files
  • the full git history is not needed

A sparse checkout fetches only the paths a promotion needs (default: helmfile.yaml, helmfiles/, .jx/, env/), while a shallow clone ignores the git history from the fetched branch. Enabling these enables faster release steps, particularly for larger repos with large commit histories.

There are exceptions to this that need to be handled with care, namely:

  • file/kpt rules that write to arbitrary paths - checkout these paths in addition to specified sparse paths
  • base branch is not the default - ignore shallow clone
  • forks require a full history - do a full clone
  • some git servers don't support sparse checkouts - do a full clone

@jenkins-x-bot

Copy link
Copy Markdown
Contributor

Hi @GavinPJK. Thanks for your PR.

I'm waiting for a jenkins-x-plugins member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the jenkins-x/lighthouse repository.

@jenkins-x-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
The changes made require 1 more approval(s).
To complete the pull request process, please assign msvticket
You can assign the PR to them by writing /assign @msvticket in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@GavinPJK

GavinPJK commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

/cc @msvticket @Skisocks @mentlak0

@Skisocks

Copy link
Copy Markdown
Member

/ok-to-test

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds optional sparse-checkout and shallow-clone behavior to jx promote to reduce clone size/time, with special handling for file/kpt promotion rules and additional test coverage.

Changes:

  • Add --sparse-checkout / --sparse-checkout-pattern flags and thread sparse-checkout settings into environment/dev-env cloning.
  • Implement default sparse-checkout patterns for environment repos, plus runtime expansion for file/kpt rule target paths.
  • Add unit + integration tests validating sparse vs full clone promotion output and shallow-clone behavior.

Reviewed changes

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

Show a summary per file
File Description
pkg/promote/promote.go Adds CLI flags and enables dev-env sparse clone behavior.
pkg/promote/pr.go Derives/expands sparse-checkout patterns for file/kpt rules during promotion.
pkg/promote/pr_internal_test.go Unit tests for deriving sparse patterns from promote specs.
pkg/environments/types.go Adds SparseCheckout option to environment PR options.
pkg/environments/gitops.go Implements sparse clone w/ default patterns + shallow-clone rules + fallback to full clone.
pkg/envctx/env_context.go Adds SparseCheckout toggle to dev environment context.
pkg/envctx/load.go Switches dev-env clone to sparse clone of versionStream/ when enabled.
pkg/promote/promote_integration_test.go Adds integration tests comparing sparse vs full promotion output and shallow behavior.

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

Comment thread pkg/envctx/load.go
Comment on lines +94 to 102
var cloneDir string
if e.SparseCheckout {
cloneDir, err = gitclient.SparseCloneToDir(gitter, gitCloneURL, "", true, "/versionStream/")
} else {
cloneDir, err = gitclient.CloneToDir(gitter, gitCloneURL, "")
}
if err != nil {
return fmt.Errorf("failed to clone URL %s: %w", gitCloneURL, err)
}
Comment thread pkg/promote/pr.go
Comment on lines +133 to +138
// git sparse-checkout add appends the pattern and re-applies it to the working
// tree, lazily fetching the now-included blobs from the (blobless) clone
if _, err := o.Gitter.Command(dir, "sparse-checkout", "add", pattern); err != nil {
return fmt.Errorf("failed to expand sparse checkout with file/kpt rule path %q in dir %s: %w", pattern, dir, err)
}
log.Logger().Infof("expanded sparse checkout to include file/kpt rule path %s", pattern)

@msvticket msvticket 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.

Configuring sparse checkout exclusively with command line argument is potentially problematic since it means that the step needs to be overridden in the pipeline.

And if a user does that any changes we do jx3-pipeline-catalog wont go through to that user. I'd prefer if this was configured in .jx/settings.yaml.

@GavinPJK

Copy link
Copy Markdown
Contributor Author

/retest

@GavinPJK

Copy link
Copy Markdown
Contributor Author

Configuring sparse checkout exclusively with command line argument is potentially problematic since it means that the step needs to be overridden in the pipeline.

And if a user does that any changes we do jx3-pipeline-catalog wont go through to that user. I'd prefer if this was configured in .jx/settings.yaml.

I see - I will look at adding something like gitCheckoutOptions to jx-api to make it configurable.

I'll set this as a draft in the meantime.

@GavinPJK
GavinPJK marked this pull request as draft July 23, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants