[JENKINS-70094] Add support for partial clone - #1777
Open
serianox wants to merge 10 commits into
Open
Conversation
6 tasks
There was a problem hiding this comment.
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)toCloneCommandandFetchCommandAPIs. - Implement partial-clone filter handling in
CliGitAPIImpl(including--filterand--refetchbehavior, 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 --addfor remote..promisor and remote..partialclonefilter.--addcan create multiple values on repeated runs and make later reads ambiguous. Use a normalgit configassignment, 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"); |
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.
Closes #3771
Adds support of partial clone by providing a filterspec to a repository configuration
This PR is I think more complete than #1131.
Testing done
Added functional tests
Currently being tested in a production server with a GB-sized repository
Submitter checklist