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

    Details

    • Similar Issues:

      Description

      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:

        Attachments

          Issue Links

            Activity

            ianfixes Ian Katz created issue -
            markewaite Mark Waite made changes -
            Field Original Value New Value
            Link This issue is related to JENKINS-29893 [ JENKINS-29893 ]
            markewaite Mark Waite made changes -
            Link This issue is related to JENKINS-26660 [ JENKINS-26660 ]
            markewaite Mark Waite made changes -
            Link This issue is related to JENKINS-45705 [ JENKINS-45705 ]
            markewaite Mark Waite made changes -
            Resolution Won't Do [ 10001 ]
            Status Open [ 1 ] Resolved [ 5 ]
            markewaite Mark Waite made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

              People

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

                Dates

                Created:
                Updated:
                Resolved: