JGit checkout fails if refspec has leading spaces - #1788
Open
akash-manna-sky wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Hi @MarkEWaite, could you please review this PR? |
There was a problem hiding this comment.
Pull request overview
This pull request fixes JGit checkout/fetch/clone behavior when refspec strings include leading/trailing whitespace (e.g., a leading space before +), by trimming whitespace in refspec handling so JGit behaves more like CLI git. It adds shared trimming helpers and extends coverage with focused unit and integration-style tests for fetch/clone with whitespace-surrounded refspecs.
Changes:
- Add
trimRefSpec/trimRefSpecshelpers to normalize whitespace around refspec source/destination. - Apply trimming in JGit and CLI implementations when consuming refspecs (fetch/clone/push).
- Add new tests validating trimming behavior and verifying fetch/clone succeed with whitespace-surrounded refspecs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/jenkinsci/plugins/gitclient/LegacyCompatibleGitAPIImpl.java | Adds shared refspec whitespace-trimming helpers (String/RefSpec/list). |
| src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java | Trims provided refspecs before JGit fetch/clone operations consume them. |
| src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java | Trims refspecs before constructing CLI git arguments for fetch/clone/push. |
| src/test/java/org/jenkinsci/plugins/gitclient/RefSpecTrimTest.java | Adds unit tests for trimming behavior and JGit misparse regression. |
| src/test/java/org/jenkinsci/plugins/gitclient/GitClientFetchTest.java | Adds regression test to ensure fetch works with whitespace-surrounded refspecs. |
| src/test/java/org/jenkinsci/plugins/gitclient/GitClientCloneTest.java | Adds regression test to ensure clone stores trimmed refspecs and fetches expected branches. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
JGit checkout fails if refspec has leading spaces
Fixes #1663
Testing done
Submitter checklist