diff --git a/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 b/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 index 9ff18288e..32231a942 100644 --- a/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 +++ b/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 @@ -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; @@ -134,11 +135,30 @@ && new File(fileSet.getBasedir(), ".git").exists() lastCommandLine = gitCheckout.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 gitList = GitListCommand.createCommandLine(repository, fileSet.getBasedir()); + if (recursive) { + gitList.createArg().setValue("--recurse-submodules"); + } + exitCode = GitCommandLineUtils.execute(gitList, listConsumer, stderr); if (exitCode != 0) { return new CheckOutScmResult( @@ -163,6 +183,19 @@ public static Commandline createCommandLine( return gitCheckout; } + /** + * create a git-submodule update command + */ + Commandline createSubmoduleUpdateCommand(File workingDirectory) { + Commandline gitSubmoduleUpdate = GitCommandLineUtils.getBaseGitCommandLine(workingDirectory, "submodule"); + + gitSubmoduleUpdate.createArg().setValue("update"); + gitSubmoduleUpdate.createArg().setValue("--init"); + gitSubmoduleUpdate.createArg().setValue("--recursive"); + + return gitSubmoduleUpdate; + } + /** * create a git-clone repository command */ @@ -183,7 +216,7 @@ private Commandline createCloneCommand( gitClone.createArg().setValue("1"); } - if (version != null && (version instanceof ScmBranch)) { + if (version instanceof ScmBranch) { gitClone.createArg().setValue("--branch"); diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitExeCheckOutCommandRecursiveTest.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitExeCheckOutCommandRecursiveTest.java new file mode 100644 index 000000000..6bcf7a8e8 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitExeCheckOutCommandRecursiveTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.scm.provider.git.gitexe.command.checkout; + +import java.io.File; +import java.util.Collections; + +import org.apache.maven.scm.ScmFileSet; +import org.apache.maven.scm.ScmTestCase; +import org.apache.maven.scm.ScmVersion; +import org.apache.maven.scm.command.checkout.CheckOutScmResult; +import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils; +import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; +import org.apache.maven.scm.repository.ScmRepository; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.Commandline; +import org.junit.Before; +import org.junit.Test; + +import static org.apache.maven.scm.provider.git.GitScmTestUtils.GIT_COMMAND_LINE; +import static org.junit.Assert.assertEquals; + +/** + * @author Wen Wu + * + */ +public class GitExeCheckOutCommandRecursiveTest extends ScmTestCase { + private File workingDirectory; + + private File repo; + + private ScmRepository scmRepository; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + workingDirectory = new File("target/checkout-recursive"); + FileUtils.deleteDirectory(workingDirectory); + repo = new File("src/test/resources/repository_submodule"); + + scmRepository = getScmManager() + .makeScmRepository( + "scm:git:" + repo.toPath().toAbsolutePath().toUri().toASCIIString()); + } + + @Test + public void testCheckoutNoBranch() throws Exception { + checkScmPresence(GIT_COMMAND_LINE); + CheckOutScmResult result = checkoutRepo(false); + + assertEquals(5, result.getCheckedOutFiles().size()); + + // git submodule set-url sub-prj file:///... + Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( + workingDirectory, + "submodule", + (GitScmProviderRepository) scmRepository.getProviderRepository(), + Collections.emptyMap()); + + String repoUrl = repo.toPath().toAbsolutePath().toUri().toASCIIString(); + cl.createArg().setValue("set-url"); + cl.createArg().setValue("sub-prj"); + cl.createArg().setValue(repoUrl); + + CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); + CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); + GitCommandLineUtils.execute(cl, stdout, stderr); + + result = checkoutRepo(true); + assertEquals(9, result.getCheckedOutFiles().size()); + } + + protected CheckOutScmResult checkoutRepo(boolean recursive) throws Exception { + CheckOutScmResult result = + getScmManager().checkOut(scmRepository, new ScmFileSet(workingDirectory), (ScmVersion) null, recursive); + + assertResultIsSuccess(result); + return result; + } +} diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/HEAD b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/config b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/config new file mode 100644 index 000000000..c53d818dd --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/config @@ -0,0 +1,5 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + ignorecase = true diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/description b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/description new file mode 100644 index 000000000..c6f25e80b --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/description @@ -0,0 +1 @@ +Unnamed repository; edit this file to name it for gitweb. diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/hooks/.gitkeep b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/hooks/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/info/exclude b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/info/exclude new file mode 100644 index 000000000..2c87b72df --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/info/exclude @@ -0,0 +1,6 @@ +# git-ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/HEAD b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/HEAD new file mode 100644 index 000000000..04e5fc908 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/HEAD @@ -0,0 +1,4 @@ +0000000000000000000000000000000000000000 c51dcd33e7b71897603c203b5e0afc1d75f70051 Mark Struberg 1196106917 +0100 +c51dcd33e7b71897603c203b5e0afc1d75f70051 baa229a9193371fad604444f64c4f26f8ff702f3 Mark Struberg 1197041894 +0100 push +baa229a9193371fad604444f64c4f26f8ff702f3 1d308c3b92eb0df9c0dc76436d50edfd0ca41d18 Mark Struberg 1197042012 +0100 push +92f139dfec4d1dfb79c3cd2f94e83bf13129668b 021d26a81797f675c66ee7f875dcb4255caa6a84 wuwen 1688375554 +0800 push diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/heads/master b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/heads/master new file mode 100644 index 000000000..04e5fc908 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/heads/master @@ -0,0 +1,4 @@ +0000000000000000000000000000000000000000 c51dcd33e7b71897603c203b5e0afc1d75f70051 Mark Struberg 1196106917 +0100 +c51dcd33e7b71897603c203b5e0afc1d75f70051 baa229a9193371fad604444f64c4f26f8ff702f3 Mark Struberg 1197041894 +0100 push +baa229a9193371fad604444f64c4f26f8ff702f3 1d308c3b92eb0df9c0dc76436d50edfd0ca41d18 Mark Struberg 1197042012 +0100 push +92f139dfec4d1dfb79c3cd2f94e83bf13129668b 021d26a81797f675c66ee7f875dcb4255caa6a84 wuwen 1688375554 +0800 push diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/remotes/origin/master b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/remotes/origin/master new file mode 100644 index 000000000..6cb21b122 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/logs/refs/remotes/origin/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 c51dcd33e7b71897603c203b5e0afc1d75f70051 Mark Struberg 1196106917 +0100 clone: from /home/msx/tmp/maven-git/repository/.git diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/02/1d26a81797f675c66ee7f875dcb4255caa6a84 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/02/1d26a81797f675c66ee7f875dcb4255caa6a84 new file mode 100644 index 000000000..d908a9e26 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/02/1d26a81797f675c66ee7f875dcb4255caa6a84 @@ -0,0 +1,2 @@ +xA + E AhJUƙbRR% AWֹigå":M b#G0xꅻM'W,$.B#[.yJĮQ"YBYaomG?dշ ?p?}hwmC0yI_M4Fb&E6eDx9U:}/@dTJ_͎[~‡}Ƕ}jP \ No newline at end of file diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/ba/cd4ee105073117b30e5dcdba5150373b6b53c6 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/ba/cd4ee105073117b30e5dcdba5150373b6b53c6 new file mode 100644 index 000000000..fe99cd8b9 Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/ba/cd4ee105073117b30e5dcdba5150373b6b53c6 differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c3/8b0351660113545db270ba6918cc22a9eb17ce b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c3/8b0351660113545db270ba6918cc22a9eb17ce new file mode 100644 index 000000000..bb5b1d508 Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c3/8b0351660113545db270ba6918cc22a9eb17ce differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c5/1dcd33e7b71897603c203b5e0afc1d75f70051 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c5/1dcd33e7b71897603c203b5e0afc1d75f70051 new file mode 100644 index 000000000..ec76cb09f Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/c5/1dcd33e7b71897603c203b5e0afc1d75f70051 differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/dc/4204852765c12f398ef4a5fbcabf23cf17a183 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/dc/4204852765c12f398ef4a5fbcabf23cf17a183 new file mode 100644 index 000000000..2234dd6df Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/dc/4204852765c12f398ef4a5fbcabf23cf17a183 differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/f7/1429f9ff9214a546b438c611ae942c9cf5a49e b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/f7/1429f9ff9214a546b438c611ae942c9cf5a49e new file mode 100644 index 000000000..b543850b6 Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/f7/1429f9ff9214a546b438c611ae942c9cf5a49e differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fd/39fa3de0f63bc5c78eca219e74e0a8531bd3e6 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fd/39fa3de0f63bc5c78eca219e74e0a8531bd3e6 new file mode 100644 index 000000000..1497fffc0 Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fd/39fa3de0f63bc5c78eca219e74e0a8531bd3e6 differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fe/a16119a5b4ec0562d4f65b4237314250773bf8 b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fe/a16119a5b4ec0562d4f65b4237314250773bf8 new file mode 100644 index 000000000..6c36970db Binary files /dev/null and b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/objects/fe/a16119a5b4ec0562d4f65b4237314250773bf8 differ diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/heads/master b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/heads/master new file mode 100644 index 000000000..2446bcb8d --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/heads/master @@ -0,0 +1 @@ +021d26a81797f675c66ee7f875dcb4255caa6a84 diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/HEAD b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/HEAD new file mode 100644 index 000000000..6efe28fff --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +ref: refs/remotes/origin/master diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/master b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/master new file mode 100644 index 000000000..b1c9092ec --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_submodule/refs/remotes/origin/master @@ -0,0 +1 @@ +c51dcd33e7b71897603c203b5e0afc1d75f70051