From 0ecb016d7db42ab83584cab3c1554d4d28cc5062 Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Fri, 11 Mar 2016 11:44:49 -0800 Subject: [PATCH] Add ignoreRemoteFailures option to RepoCommand With ignoreRemoteFailures set to true, we can ignore remote failures (e.g. the branch of a project described in the manifest file does not exist), skip that project and continue to the next one, instead of fail the whole operation. Change-Id: I8b3765713599e34f1411f9bbc7f575ec7c2384e0 Signed-off-by: Yuxuan 'fishy' Wang --- .../org/eclipse/jgit/gitrepo/RepoCommand.java | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index ff9f233aa..1e4a1b2d8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -54,6 +54,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.GitCommand; import org.eclipse.jgit.api.SubmoduleAddCommand; @@ -103,7 +104,6 @@ import org.eclipse.jgit.util.FileUtils; * @since 3.4 */ public class RepoCommand extends GitCommand { - private String path; private String uri; private String groups; @@ -114,6 +114,7 @@ public class RepoCommand extends GitCommand { private RemoteReader callback; private InputStream inputStream; private IncludedFileReader includedReader; + private boolean ignoreRemoteFailures = false; private List bareProjects; private Git git; @@ -137,9 +138,11 @@ public class RepoCommand extends GitCommand { * The URI of the remote repository * @param ref * The ref (branch/tag/etc.) to read - * @return the sha1 of the remote repository + * @return the sha1 of the remote repository, or null if the ref does + * not exist. * @throws GitAPIException */ + @Nullable public ObjectId sha1(String uri, String ref) throws GitAPIException; /** @@ -318,7 +321,7 @@ public class RepoCommand extends GitCommand { } /** - * Set whether the branch name should be recorded in .gitmodules + * Set whether the branch name should be recorded in .gitmodules. *

* Submodule entries in .gitmodules can include a "branch" field * to indicate what remote branch each submodule tracks. @@ -354,6 +357,26 @@ public class RepoCommand extends GitCommand { return this; } + /** + * Set whether to skip projects whose commits don't exist remotely. + *

+ * When set to true, we'll just skip the manifest entry and continue + * on to the next one. + *

+ * When set to false (default), we'll throw an error when remote + * failures occur. + *

+ * Not implemented for non-bare repositories. + * + * @param ignore Whether to ignore the remote failures. + * @return this command + * @since 4.3 + */ + public RepoCommand setIgnoreRemoteFailures(boolean ignore) { + this.ignoreRemoteFailures = ignore; + return this; + } + /** * Set the author/committer for the bare repository commit. *

@@ -452,22 +475,29 @@ public class RepoCommand extends GitCommand { for (RepoProject proj : bareProjects) { String name = proj.getPath(); String nameUri = proj.getName(); - cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$ - cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$ - // create gitlink - DirCacheEntry dcEntry = new DirCacheEntry(name); ObjectId objectId; - if (ObjectId.isId(proj.getRevision())) { + if (ObjectId.isId(proj.getRevision()) + && !ignoreRemoteFailures) { objectId = ObjectId.fromString(proj.getRevision()); } else { objectId = callback.sha1(nameUri, proj.getRevision()); - if (recordRemoteBranch) + if (objectId == null) { + if (ignoreRemoteFailures) { + continue; + } + throw new RemoteUnavailableException(nameUri); + } + if (recordRemoteBranch) { // can be branch or tag cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ proj.getRevision()); + } } - if (objectId == null) - throw new RemoteUnavailableException(nameUri); + cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$ + cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$ + + // create gitlink + DirCacheEntry dcEntry = new DirCacheEntry(name); dcEntry.setObjectId(objectId); dcEntry.setFileMode(FileMode.GITLINK); builder.add(dcEntry);