Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1603,18 +1603,30 @@ public void submoduleReset(boolean recursive, boolean hard) throws GitException,
* Cleans submodules
*/
@Override
public void submoduleClean(boolean recursive) throws GitException, InterruptedException {
public void submoduleClean(boolean recursive, boolean cleanSubmodule) throws GitException, InterruptedException {
submoduleReset(true, true);
ArgumentListBuilder args = new ArgumentListBuilder();
args.add("submodule", "foreach");
if (recursive) {
args.add("--recursive");
}
args.add("git clean -fdx");
String cmd = "git clean -fdx";
if (cleanSubmodule) cmd = "git clean -ffdx";
args.add(cmd);

launchCommand(args);
}

/**
* {@inheritDoc}
*
* Cleans submodules
*/
@Override
public void submoduleClean(boolean recursive) throws GitException, InterruptedException {
this.submoduleClean(recursive, false);
}

/**
* {@inheritDoc}
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,16 @@ void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference
*/
void submoduleClean(boolean recursive) throws GitException, InterruptedException;

/**
* submoduleClean.
*
* @param recursive a boolean.
* @param cleanSubmodule flag to add extra -f
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleClean(boolean recursive, boolean cleanSubmodule) throws GitException, InterruptedException;

/**
* submoduleInit.
*
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2324,19 +2324,25 @@ private Iterable<JGitAPIImpl> submodules() throws IOException {

/** {@inheritDoc} */
@Override
public void submoduleClean(boolean recursive) throws GitException {
public void submoduleClean(boolean recursive, boolean cleanSubmodule) throws GitException {
try {
for (JGitAPIImpl sub : submodules()) {
sub.clean();
sub.clean(cleanSubmodule);
if (recursive) {
sub.submoduleClean(true);
sub.submoduleClean(true, cleanSubmodule);
}
}
} catch (IOException e) {
throw new GitException(e);
}
}

/** {@inheritDoc} */
@Override
public void submoduleClean(boolean recursive) throws GitException {
this.submoduleClean(recursive, false);
}

/**
* Update submodules.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,11 @@ public void submoduleClean(boolean recursive) throws GitException, InterruptedEx
}

/** {@inheritDoc} */
@Override
public void submoduleClean(boolean recursive, boolean cleanSubmodule) throws GitException, InterruptedException {
proxy.submoduleClean(recursive, cleanSubmodule);
}

/** {@inheritDoc} */
public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException, InterruptedException {
proxy.setupSubmoduleUrls(rev, listener);
}
Expand Down