Skip to content

Commit

Permalink
[SCM-530] Add support for git submodules to git SCM provider
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 committed Jul 3, 2023
1 parent 3d8c62b commit 18d298d
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public ScmResult executeCommand(ScmProviderRepository repo, ScmFileSet fileSet,
ScmVersion version = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
boolean binary = parameters.getBoolean(CommandParameter.BINARY, false);
boolean shallow = parameters.getBoolean(CommandParameter.SHALLOW, false);
boolean recursive = parameters.getBoolean(CommandParameter.RECURSIVE, false);

GitScmProviderRepository repository = (GitScmProviderRepository) repo;

Expand Down Expand Up @@ -135,11 +136,30 @@ && new File(fileSet.getBasedir(), ".git").exists()
lastCommandLine = clCheckout.toString();
}

if (recursive) {
// and now lets do the git-submodule update
Commandline clSubmoduleUpdate = createSubmoduleUpdateCommand(fileSet.getBasedir());

exitCode = GitCommandLineUtils.execute(clSubmoduleUpdate, stdout, stderr);
if (exitCode != 0) {
return new CheckOutScmResult(
clSubmoduleUpdate.toString(),
"The git-submodule update command failed.",
stderr.getOutput(),
false);
}
lastCommandLine = clSubmoduleUpdate.toString();
}

// and now search for the files
GitListConsumer listConsumer = new GitListConsumer(fileSet.getBasedir(), ScmFileStatus.CHECKED_IN);

Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());

if (recursive) {
clList.createArg().setValue("--recurse-submodules");
}

exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr);
if (exitCode != 0) {
return new CheckOutScmResult(
Expand All @@ -164,6 +184,19 @@ public static Commandline createCommandLine(
return cl;
}

/**
* create a git-submodule update command
*/
Commandline createSubmoduleUpdateCommand(File workingDirectory) {
Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(workingDirectory, "submodule");

cl.createArg().setValue("update");
cl.createArg().setValue("--init");
cl.createArg().setValue("--recursive");

return cl;
}

/**
* create a git-clone repository command
*/
Expand All @@ -184,7 +217,7 @@ private Commandline createCloneCommand(
cl.createArg().setValue("1");
}

if (version != null && (version instanceof ScmBranch)) {
if (version instanceof ScmBranch) {

cl.createArg().setValue("--branch");

Expand Down

0 comments on commit 18d298d

Please sign in to comment.