Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63383

Polluted workspace -- "Clean after checkout" (git clean -fdx) won't remove git repositories in subdirectories

XMLWordPrintable

      TL;DR:

      git clean -fdx should be git clean -ffdx as per this advice

      Problem / Steps To Reproduce

      If a build creates a git repository in a subdirectory of the workspace, the option to "clean after checkout" will skip it. This is expected behavior of git that you can verify quite easily:

      # assuming we are ubuntu@jenkins-agent:/tmp/jenkins-blah/workspace/some-job
       
      some-job$ mkdir foo
      
      some-job$ cd foo
      
      some-job/foo$ git init
      Initialized empty Git repository in /tmp/jenkins-blah/workspace/some-job/foo/.git/
      
      some-job/foo$ cd .. 
      
      some-job$ git clean -fdx
      Skipping repository foo/
      
      some-job$ git clean -ffdx
      Removing foo/
      

      Expected behavior

      Git plugin cleans the workspace by removing the foo directory that has been initialized with its own git repository

      some-job$ git clean -ffdx
      Removing foo/
      

      Actual behavior

      Git plugin silently fails to clean the workspace because the git command it runs succeeds with a warning message that the directory containing another repository was skipped:

      some-job$ git clean -fdx
      Skipping repository foo/
      

      Suggested fix

      Use the -f option twice with git: git -ffdx to force removal of directories that contain git repositories.

      Possible problems with git -ffdx

      I'm not sure whether simply making this change will affect subdirectories; it shouldn't, but I haven't tested.

      Issues that are NOT this issue:

            markewaite Mark Waite
            ianfixes Ian Katz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: