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-60727 Add cleanSubmodule parameter to submoduleClean to add c… #489

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -1603,18 +1603,30 @@
* 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";

Check warning on line 1614 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1614 is only partially covered, one branch is missing
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 @@
}

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

Check warning on line 788 in src/main/java/org/jenkinsci/plugins/gitclient/RemoteGitImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 787-788 are not covered by tests

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