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>
This commit is contained in:
Yuxuan 'fishy' Wang 2016-03-11 11:44:49 -08:00
parent cff546b0cb
commit 0ecb016d7d
1 changed files with 41 additions and 11 deletions

View File

@ -54,6 +54,7 @@
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 @@
* @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 interface RemoteReader {
* 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 RepoCommand setTargetBranch(String branch) {
}
/**
* 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.
@ -354,6 +357,26 @@ public RepoCommand setProgressMonitor(final ProgressMonitor monitor) {
return this;
}
/**
* 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>
@ -452,22 +475,29 @@ public RevCommit call() throws GitAPIException {
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);