Skip to content

Commit 18d298d

Browse files
committed
[SCM-530] Add support for git submodules to git SCM provider
1 parent 3d8c62b commit 18d298d

File tree

1 file changed

+34
-1
lines changed
  • maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkout

1 file changed

+34
-1
lines changed

maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitCheckOutCommand.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public ScmResult executeCommand(ScmProviderRepository repo, ScmFileSet fileSet,
7070
ScmVersion version = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
7171
boolean binary = parameters.getBoolean(CommandParameter.BINARY, false);
7272
boolean shallow = parameters.getBoolean(CommandParameter.SHALLOW, false);
73+
boolean recursive = parameters.getBoolean(CommandParameter.RECURSIVE, false);
7374

7475
GitScmProviderRepository repository = (GitScmProviderRepository) repo;
7576

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

139+
if (recursive) {
140+
// and now lets do the git-submodule update
141+
Commandline clSubmoduleUpdate = createSubmoduleUpdateCommand(fileSet.getBasedir());
142+
143+
exitCode = GitCommandLineUtils.execute(clSubmoduleUpdate, stdout, stderr);
144+
if (exitCode != 0) {
145+
return new CheckOutScmResult(
146+
clSubmoduleUpdate.toString(),
147+
"The git-submodule update command failed.",
148+
stderr.getOutput(),
149+
false);
150+
}
151+
lastCommandLine = clSubmoduleUpdate.toString();
152+
}
153+
138154
// and now search for the files
139155
GitListConsumer listConsumer = new GitListConsumer(fileSet.getBasedir(), ScmFileStatus.CHECKED_IN);
140156

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

159+
if (recursive) {
160+
clList.createArg().setValue("--recurse-submodules");
161+
}
162+
143163
exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr);
144164
if (exitCode != 0) {
145165
return new CheckOutScmResult(
@@ -164,6 +184,19 @@ public static Commandline createCommandLine(
164184
return cl;
165185
}
166186

187+
/**
188+
* create a git-submodule update command
189+
*/
190+
Commandline createSubmoduleUpdateCommand(File workingDirectory) {
191+
Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(workingDirectory, "submodule");
192+
193+
cl.createArg().setValue("update");
194+
cl.createArg().setValue("--init");
195+
cl.createArg().setValue("--recursive");
196+
197+
return cl;
198+
}
199+
167200
/**
168201
* create a git-clone repository command
169202
*/
@@ -184,7 +217,7 @@ private Commandline createCloneCommand(
184217
cl.createArg().setValue("1");
185218
}
186219

187-
if (version != null && (version instanceof ScmBranch)) {
220+
if (version instanceof ScmBranch) {
188221

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

0 commit comments

Comments
 (0)