-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-38699] Limit CLI git operations to the workspace #692
Conversation
src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java
Outdated
Show resolved
Hide resolved
The JGit implementation of hasGitRepo() always ignored parent directories. The CLI git impelementation of hasGitRepo() ignored parent directories if the workspace did not contain a '.git' directory. If the workspace contains an empty '.git' directory, then CLI git will search parent directories. That's a strange behavior, but I'd rather not learn by hard experience which implementations depend on that strange behavior. Introduces a new API, hasGitRepo(boolean checkParentDirectories). The JENKINS-38996 fix will require a new release of the git plugint that depends on this release of the git client plugin and uses the new API to avoid the poor behavior of the existing hasGitRepo() implementation.
Already checking directory existence earlier in method and cannot use the hasGitRepo method for bare repositories because it requires a subdirectory named '.git'.
Thanks @MarkEWaite for getting involved and providing a new functionality. But JENKINS-38699 issue still persists as the git-plugin currently uses the |
Thanks @arpoch . Yes, that's what will be needed. I'm preparing that change now with a series of interactive and automated tests to confirm that JENKINS-38699 is resolved. As far as I can tell from reading the git plugin code, all the cases of The behavior of |
I completely agree on replacing |
@arpoch See jenkinsci/git-plugin#1064 for the proposed change to git plugin |
I searched for |
JENKINS-38699 - Validate .git directory with --resolve-git-dir
As the validation of a git repository presently is checked using
git rev-parse --is-inside-work-tree
but if the .git directory is corrupted then current repository's parent directories are searched for a valid .git directory. To limit/confine the traversal,--is-inside-work-tree
is replaced by--resolve-git-dir
which check if path to the .git directory of the current git repository is valid.Checklist
Types of changes
What types of changes does your code introduce?
Further comments
Switched from the original implementation as a breaking change to instead add a new API that allows the caller to define if parent directories should be searched for a git repository. Retains the existing behavior for the CLI git implementation (searching parent directories if the workspace contains a
.git
directory) and the existing behavior of the JGit implementation (never searching parent directories). Retains the previous implementation and includes a statement in the javadoc about the behavioral difference between the CLI git and JGit implementations ofhasGitRepo()
.