Skip to content

[JENKINS-70094] Add support for partial clone - #1777

Open
serianox wants to merge 10 commits into
jenkinsci:masterfrom
ThalesGroup:add-partial-clone
Open

[JENKINS-70094] Add support for partial clone#1777
serianox wants to merge 10 commits into
jenkinsci:masterfrom
ThalesGroup:add-partial-clone

Conversation

@serianox

Copy link
Copy Markdown

Closes #3771
Adds support of partial clone by providing a filterspec to a repository configuration

  • performed by setting remote..promisor and remote..partialCloneFilter in the clone configuration
  • detect changes requested of the filterspec and perform --refetch as needed
  • revert to full clone if unsupported by the git implementation
  • automatically detect during checkout if the repository is a partial clone and provides credentials if needed

This PR is I think more complete than #1131.

Testing done

Added functional tests

  • test with a filter spec (on jgit, will revert to a test with a full clone)
  • test with credentials
  • test with changed filterspec

Currently being tested in a production server with a GB-sized repository

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@serianox
serianox requested a review from a team as a code owner July 10, 2026 13:09
@github-actions github-actions Bot added the tests Automated test addition or improvement label Jul 10, 2026
@MarkEWaite MarkEWaite added the enhancement Improvement or new feature label Aug 1, 2026
@MarkEWaite
MarkEWaite requested a lite review from Copilot August 14, 2026 15:05

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

Adds partial clone filter support to the git-client plugin by extending the Clone and Fetch command APIs and implementing CLI git behavior, with JGit falling back to full clone/fetch while warning. It also adds functional tests covering filter usage, filter changes, and credential use during checkout in partial-clone scenarios.

Changes:

  • Add filter(String filterSpec) to CloneCommand and FetchCommand APIs.
  • Implement partial-clone filter handling in CliGitAPIImpl (including --filter and --refetch behavior, plus checkout-time credential use for promisor remotes).
  • Add functional tests for clone/fetch filters and partial-clone checkout with credentials; add JGit warnings when filter is requested.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java Implements CLI git partial-clone filter support (fetch/clone config + checkout credential handling).
src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java Adds no-op filter() implementations that warn and fall back to full behavior under JGit.
src/main/java/org/jenkinsci/plugins/gitclient/FetchCommand.java Extends fetch API with filter(String) (needs Javadoc correction).
src/main/java/org/jenkinsci/plugins/gitclient/CloneCommand.java Extends clone API with filter(String).
src/test/java/org/jenkinsci/plugins/gitclient/GitClientFetchTest.java Adds functional tests validating fetch filter behavior and filter changes.
src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java Adds functional test validating clone filter behavior (and promisor artifacts).
src/test/java/org/jenkinsci/plugins/gitclient/CredentialsTest.java Adds functional test for checkout of partial clone that requires credentials.
Suppressed comments (2)

src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java:620

  • When CLI git is older than 2.22, this code silently skips adding --filter but still writes promisor/partialclonefilter config, which contradicts the PR intent to "revert to full clone if unsupported" and can incorrectly mark a full repo as a partial clone. Gate both args and config updates on version support and log a warning when unsupported.
                    if (isAtLeastVersion(2, 22, 0, 0)) {
                        args.add("--filter=" + filterSpec);
                    }

src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java:923

  • CloneCommand#execute uses git config --add for remote..promisor and remote..partialclonefilter. --add can create multiple values on repeated runs and make later reads ambiguous. Use a normal git config assignment, and avoid setting partial-clone config when CLI git is too old to support filters.
                if (filterSpec != null) {
                    launchCommand("config", "--add", "remote." + origin + ".promisor", "true");
                    launchCommand("config", "--add", "remote." + origin + ".partialclonefilter", filterSpec);
                }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +68 to +74
/**
* Apply an object filter to a partial clone. If unset, a full clone is performed.
*
* @param filterSpec filter of objects to be sent by the server
* @return a {@link org.jenkinsci.plugins.gitclient.CloneCommand} object.
* @since 6.7.0
*/
Comment on lines +608 to +611
if (defaultRemote != null && !defaultRemote.isEmpty()) {
currentFilterSpec =
launchCommand("config", "remote." + defaultRemote + ".partialclonefilter");
}
/** Returns true if the remote has a promisor configured for missing blobs. */
boolean hasPromisor(String name) throws GitException, InterruptedException {
try {
return launchCommand("config", "remote." + name + ".promisor").contains("true");
Comment on lines +461 to +465
private void assertPromisorFilesExist(File anotherTestGitDir) {
File pack = new File(anotherTestGitDir, ".git" + File.separator + "objects" + File.separator + "pack");
File[] promisors = pack.listFiles((dir, name) -> name.endsWith(".promisor"));
assertThat(promisors, is(not(emptyArray())));
}
git.withRepository(
(gitRepo, unusedChannel) -> gitRepo.findRef("master").getObjectId()),
"Master != HEAD");
assertEquals("master", git.withRepository((gitRepo, unusedChanel) -> gitRepo.getBranch()), "Wrong branch");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement or new feature tests Automated test addition or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-70094] Support blobless clone

3 participants