git-plugin: git clean -ffxd in submodules ?

27 views
Skip to first unread message

Xavier Raynaud

unread,
Feb 5, 2025, 10:46:31 AMFeb 5
to jenkins...@googlegroups.com
Hi all,

In my Jenkinsfile, I use the checkout step to perform a git checkout.
My git repo has some submodules; which have also, themselves, submodules.

As of today, I use the following checkout extentions:
[$class: 'CleanBeforeCheckout', deleteUntrackedNestedRepositories: true ]
[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', threads: 4, timeout: 30, trackingSubmodules: false, shallow: shallow_clone, depth: 1],

The former extension runs "git clean -ffxd" before performing git checkout.
But, as far as i know, this option is not propagated to submodules: in submodules, only "git -fxd" is performed.
Therefore, some "phantom" gits repos can be left in submodules.

Is there a way to run "git clean -ffxd" in submodules ?
Is it a known issue ?

Regards,

Xavier Raynaud

Mark Waite

unread,
Feb 5, 2025, 1:59:29 PMFeb 5
to Jenkins Users
Could you perform the cleanup yourself in the Pipeline immediately before the checkout?  Something like "sh '[ -d .git ] && git submodule foreach --recursive git clean -xffd'"
 
Is it a known issue ?


https://stackoverflow.com/questions/51963783/what-is-the-workflow-to-clean-git-submodules-on-clones highlights some of the problems attempting to clean submodules on an existing clone

https://issues.jenkins.io/browse/JENKINS-60727 asks to clean the submodules of submodules
https://issues.jenkins.io/browse/JENKINS-55875 describes a failure case with submodules
More examples of those are available.  The complexities of handling submodules was one of the reasons why a Google Summer of Code project added git plugin support to the withCredentials Pipeline step.  When all else fails, you can take complete control of the checkout and perform the exact git commands that you need for your submodule configuration.

Mark Waite
Reply all
Reply to author
Forward
0 new messages