diff options
author | Yuxuan 'fishy' Wang <fishywang@google.com> | 2016-03-11 11:44:49 -0800 |
---|---|---|
committer | Yuxuan 'fishy' Wang <fishywang@google.com> | 2016-03-11 14:20:24 -0800 |
commit | 0ecb016d7db42ab83584cab3c1554d4d28cc5062 (patch) | |
tree | 8bf443678751f53c41d3370bd737d4ad5df71761 | |
parent | cff546b0cbcdbaaa8757c94f25e845e81bd633be (diff) | |
download | jgit-0ecb016d7db42ab83584cab3c1554d4d28cc5062.tar.gz jgit-0ecb016d7db42ab83584cab3c1554d4d28cc5062.zip |
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 <fishywang@google.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java | 52 |
1 files 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 ff9f233aa5..1e4a1b2d85 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<RevCommit> { - private String path; private String uri; private String groups; @@ -114,6 +114,7 @@ public class RepoCommand extends GitCommand<RevCommit> { private RemoteReader callback; private InputStream inputStream; private IncludedFileReader includedReader; + private boolean ignoreRemoteFailures = false; private List<RepoProject> bareProjects; private Git git; @@ -137,9 +138,11 @@ public class RepoCommand extends GitCommand<RevCommit> { * 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<RevCommit> { } /** - * Set whether the branch name should be recorded in .gitmodules + * Set whether the branch name should be recorded in .gitmodules. * <p> * Submodule entries in .gitmodules can include a "branch" field * to indicate what remote branch each submodule tracks. @@ -355,6 +358,26 @@ public class RepoCommand extends GitCommand<RevCommit> { } /** + * Set whether to skip projects whose commits don't exist remotely. + * <p> + * When set to true, we'll just skip the manifest entry and continue + * on to the next one. + * <p> + * When set to false (default), we'll throw an error when remote + * failures occur. + * <p> + * 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. * <p> * For non-bare repositories, the current user will be used and this will be @@ -452,22 +475,29 @@ public class RepoCommand extends GitCommand<RevCommit> { 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); |