Skip to content
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] Only check for git repo in current workspace dir #1064

Merged

Conversation

MarkEWaite
Copy link
Contributor

@MarkEWaite MarkEWaite commented Apr 3, 2021

JENKINS-38699 - Only check for git repo in current workspace dir

Do not allow command line git operations to extend beyond the workspace.

Checklist

  • I have read the CONTRIBUTING doc
  • I have referenced the Jira issue related to my changes in one or more commit messages
  • I have added tests that verify my changes
  • Unit tests pass locally with my changes
  • I have added documentation as necessary
  • No Javadoc warnings were introduced with my changes
  • No spotbugs warnings were introduced with my changes
  • Documentation in README has been updated as necessary
  • Online help has been added and reviewed for any new or modified fields
  • I have interactively tested my changes
  • Any dependent changes have been merged and published in upstream modules (like git-client-plugin)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Further comments

The CliGit implementation of hasGitRepo() has the strange and surprising behavior that if a workspace contains a directory named ".git" and that directory is not a git repository (for example, an empty directory), then command line git will search upwards in the file system tree to find a git repository and will perform its operations on the repository it finds. That is the right behavior for a user running command line git. It allows them to change to different directories and have the same experience with command line git. JGit has a different behavior. It does not search upwards for a repository.

It is a dangerous behavior when deciding to run git clean or other destructive operations in a Jenkins agent workspace. If the agent workspace is damaged, then the git commands search upwards, outside the agent workspace. This change causes the git plugin to only search in the workspace, not any of the parent directories of the workspace.

The new method hasGitRepo(boolean checkParentDirectories) allows the existing CliGit implementation and the existing JGit implementation of hasGitRepo() to continue as they are, while the git plugin uses the new API to not check parent directories in any case.

Special thanks to @arpoch for patient work understanding the problem, proposing a solution to the problem, and providing tests that show the problem.

The CliGit implementation of hasGitRepo() has the strange and surprising
behavior that if a workspace contains a directory named ".git" and that
directory is not a git repository (for example, an empty directory), then
command line git will search upwards in the file system tree to find a
git repository and will perform its operations on the repository it finds.

That is the right behavior for a user running command line git.  It allows
them to change to different directories and have the same experience
with command line git.

It is a dangerous behavior when deciding to run `git clean` or other
destructive operations in a Jenkins agent workspace.  If the agent
workspace is damaged, then the git commands search upwards, outside the
agent workspace.  This change causes the git plugin to only search in
the workspace, not any of the parent directories of the workspace.

Special thanks to @arpoch for patient work understanding the problem,
proposing a solution to the problem, and providing tests that show
the problem.
@MarkEWaite MarkEWaite added the bugfix Fixes a bug - used by Release Drafter label Apr 3, 2021
pom.xml Outdated Show resolved Hide resolved
@MarkEWaite MarkEWaite merged commit 449e6ab into jenkinsci:master Apr 4, 2021
@MarkEWaite MarkEWaite deleted the do-not-search-parents-for-repo branch April 4, 2021 17:28
@MarkEWaite MarkEWaite mentioned this pull request Apr 4, 2021
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes a bug - used by Release Drafter
Projects
None yet
1 participant