summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-02-22 13:21:49 +0900
committerMatthias Sohn <matthias.sohn@sap.com>2017-04-27 09:19:08 +0200
commit005e5feb4ecd08c4e4d141a38b9e7942accb3212 (patch)
tree686086609d3a9c559614a90c033a4965b1416bd3 /org.eclipse.jgit
parent76e86f4e48c98e742be99adff3b8b43cff94263c (diff)
downloadjgit-005e5feb4ecd08c4e4d141a38b9e7942accb3212.tar.gz
jgit-005e5feb4ecd08c4e4d141a38b9e7942accb3212.zip
Clone: add --recurse-submodules option
Add the --recurse-submodules option on the command, which causes submodules to also be initialized and updated. Add a callback interface on CloneCommand and SubmoduleUpdateCommand to them to provide progress feedback for clone operations. Change-Id: I41b1668bc0d0bdfa46a9a89882c9657ea3063fc1 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java56
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java20
2 files changed, 75 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index 4b815b439d..2deff07f1d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -58,6 +58,7 @@ import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
@@ -106,6 +107,42 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
private Collection<String> branchesToClone;
+ private Callback callback;
+
+ /**
+ * Callback for status of clone operation.
+ *
+ * @since 4.8
+ */
+ public interface Callback {
+ /**
+ * Notify initialized submodules.
+ *
+ * @param submodules
+ * the submodules
+ *
+ */
+ void initializedSubmodules(Collection<String> submodules);
+
+ /**
+ * Notify starting to clone a submodule.
+ *
+ * @param path
+ * the submodule path
+ */
+ void cloningSubmodule(String path);
+
+ /**
+ * Notify checkout of commit
+ *
+ * @param commit
+ * the id of the commit being checked out
+ * @param path
+ * the submodule path
+ */
+ void checkingOut(AnyObjectId commit, String path);
+ }
+
/**
* Create clone command with no repository set
*/
@@ -280,12 +317,18 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
private void cloneSubmodules(Repository clonedRepo) throws IOException,
GitAPIException {
SubmoduleInitCommand init = new SubmoduleInitCommand(clonedRepo);
- if (init.call().isEmpty())
+ Collection<String> submodules = init.call();
+ if (submodules.isEmpty()) {
return;
+ }
+ if (callback != null) {
+ callback.initializedSubmodules(submodules);
+ }
SubmoduleUpdateCommand update = new SubmoduleUpdateCommand(clonedRepo);
configure(update);
update.setProgressMonitor(monitor);
+ update.setCallback(callback);
if (!update.call().isEmpty()) {
SubmoduleWalk walk = SubmoduleWalk.forIndex(clonedRepo);
while (walk.next()) {
@@ -523,6 +566,17 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
return this;
}
+ /**
+ * Register a progress callback.
+ *
+ * @param callback
+ * the callback
+ * @since 4.8
+ */
+ public void setCallback(Callback callback) {
+ this.callback = callback;
+ }
+
private static void validateDirs(File directory, File gitDir, boolean bare)
throws IllegalStateException {
if (directory != null) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
index 29d5d49a45..34bfbe75b1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
@@ -89,6 +89,8 @@ public class SubmoduleUpdateCommand extends
private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+ private CloneCommand.Callback callback;
+
/**
* @param repo
*/
@@ -161,6 +163,9 @@ public class SubmoduleUpdateCommand extends
Repository submoduleRepo = generator.getRepository();
// Clone repository is not present
if (submoduleRepo == null) {
+ if (callback != null) {
+ callback.cloningSubmodule(generator.getPath());
+ }
CloneCommand clone = Git.cloneRepository();
configure(clone);
clone.setURI(url);
@@ -201,6 +206,10 @@ public class SubmoduleUpdateCommand extends
Constants.HEAD, true);
refUpdate.setNewObjectId(commit);
refUpdate.forceUpdate();
+ if (callback != null) {
+ callback.checkingOut(commit,
+ generator.getPath());
+ }
}
} finally {
submoduleRepo.close();
@@ -225,4 +234,15 @@ public class SubmoduleUpdateCommand extends
this.strategy = strategy;
return this;
}
+
+ /**
+ * Set status callback for submodule clone operation.
+ *
+ * @param callback
+ * the callback
+ * @since 4.8
+ */
+ public void setCallback(CloneCommand.Callback callback) {
+ this.callback = callback;
+ }
}