-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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-63519] Create a better mechanism to detect node-specific git implementations #949
[JENKINS-63519] Create a better mechanism to detect node-specific git implementations #949
Conversation
In reference to the bug JENKINS-63519 which exposed an issue where the GitToolChooser is not able to determine the correct implementation if a node-specific installation is present in the system. This API is called when the system wants to recommend `cli git` and the user has chosen `jgit`. To find the right cli git, it iterates over the available installations, checks if one of them contains a property map, confirms with the node attributes (using GitUtils.resolveGitTool) and then finally suggests the right git implementation. With this change, we have added two new parameters: Node path and TaskListener. Both of them are needed for better estimation of the correct git tool present on a particular agent.
@@ -838,6 +838,8 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?, | |||
|
|||
String gitExe = getGitExe(n, listener); | |||
|
|||
GitTool gitTool = getGitTool(n, null, listener); |
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.
This was added to access the GitTool
chosen by the system instead of the git executable path for GitToolChooser.
} | ||
return recommendation; | ||
} | ||
|
||
private GitTool resolveGitToolForRecommendation(GitTool userChoice, String recommendation) { | ||
GitTool tool; | ||
if (recommendation.equals(JGitTool.MAGIC_EXENAME)) { |
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.
For repository size < 5MiB, the recommendation should be jgit/jgitapache
. This branch of logic will try to recommend jgit or jgitapache
and confirm with the system if it is enabled by the user. It would return a null if it is not enabled by the user.
@@ -209,13 +172,48 @@ private GitTool resolveGitToolForRecommendation(GitTool userChoice, String recom | |||
return null; | |||
} | |||
} else { |
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.
This branch of logic is designed for repo size > 5M.
Here two things can happen:
- if user's choice is not jgit or jgitapache, it would be a command line git tool. We would return that same choice without any concern.
- if the user's choice is jgit or jgitapache, it would look for the right command line git tool using
recommendGitToolOnAgent
.
…hoice is JGit and the size of repo> 5M For the GitToolChooser, the most difficult scenario is when the user has chosen jgit and size of repo > 5M. In this case, the system has to decide which command line git implementation will be the right implementation for that particular environment without breaking any possible use-case. With the added test cases what we want to say is (keeping the above mentioned conditions same): - if there is a node specific installation present, that will be suggested after being verified that it is actually installed in that environment. - if there is no node specific installation, the default implementation will be suggested. There is one side-effect of this implementation, if the only implementation is `jgit` in the system then that will be recommended instead of command line git. But that wouldn't affect the user since there would be no possible change in the git implementation used for the git client.
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.
Still need further review, but the javadoc update is one that can be done while other reviews are happening
@@ -48,12 +52,14 @@ | |||
* @throws IOException on error | |||
* @throws InterruptedException on error | |||
*/ | |||
public GitToolChooser(String remoteName, Item projectContext, String credentialsId, String gitExe, Boolean useJGit) throws IOException, InterruptedException { | |||
public GitToolChooser(String remoteName, Item projectContext, String credentialsId, |
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.
Please add javadoc comments for the new parameters. That will resolve the javadoc warnings below and keep the javadoc clean
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.
Done
return determineToolName(gitExe, "git"); | ||
GitTool rTool = resolveGitToolForRecommendation(tool, "git"); | ||
if (rTool == null) { | ||
return "NONE"; |
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.
This statement is never reached by the tests in GitToolChooserTest. Could it be reached reasonably by an addition of one of those tests?
return "NONE"; | |
return "NONE"; |
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 for catching this. It can't be reached because there is no possible scenario where the tool will be null. I have removed it.
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.
Need to fix the Windows path references so that the tests pass on Windows and need to switch from SystemUtils
to the isWindows()
technique that is used elsewhere in the plugin.
See MarkEWaite@3763bb3 for a proposed change.
Use isWindows() technique to maintain consistency across the plugin
@MarkEWaite In reference to the test failures on Windows, I have found an interesting test which uses the same technique which I borrowed to create a Refer to: git-plugin/src/test/java/jenkins/plugins/git/GitSCMSourceTest.java Lines 363 to 366 in be265e0
Those tests using a node specific Tool installation implementation seem to avoid Windows environment, stating those tests only run on I am assuming I do the same thing those tests are doing since this issue seems most likely a test configuration problem rather than the GitToolChooser's problem. |
@MarkEWaite In fact I just saw a recent commit from you: 6aff94f. If it is okay, I'd like to apply the same technique over here to maintain the test warning count. |
I like that idea. If others have deduced that a portion of the test framework is platform specific, it is very reasonable for us to limit ourselves to that platform. |
Two of the test cases contains a node-specific tool installation implementation which can perform an installation only on Unix based platforms. Considering that shortcoming this change limits those tests to Unix based platforms only.
Oops, tried a forced rebuild by closing and reopening the PR. |
Fix for the failing test is included in #952 . Sorry for the distraction from your fix. |
JENKINS-63519
Change the current way to suggest a git implementation, the modifications can be broadly described as:
jgit
andjgit
is not available in the system, it used to go forcli git
. We've realised that that is unnecessary. Now the GitToolChooser would recommend nothing ("NONE") if it wants to recommendjgit
orjgitapache
but it is not enabled by the user.git
whatever that may be perceived by the system, which is wrong.Now, it will return the same node-specific git tool,
git-for-windows
.jgit
as a git tool, now the GitToolChooser has the responsibility of selecting the right implementation (maybe node-specific). With the help ofrecommendGitToolOnAgent
it is able to do so.Note: The current changes have made the decision process a little complex, I'm not proud of the current design and would want to shift to a builder pattern for the initialization of the class considering the increasing number of args required to initialise GitToolChooser.
Checklist
Types of changes