ソースを参照

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>
tags/v4.3.0.201603230630-rc1
Yuxuan 'fishy' Wang 8年前
コミット
0ecb016d7d
1個のファイルの変更41行の追加11行の削除
  1. 41
    11
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java

+ 41
- 11
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java ファイルの表示

import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand; import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.SubmoduleAddCommand; import org.eclipse.jgit.api.SubmoduleAddCommand;
* @since 3.4 * @since 3.4
*/ */
public class RepoCommand extends GitCommand<RevCommit> { public class RepoCommand extends GitCommand<RevCommit> {

private String path; private String path;
private String uri; private String uri;
private String groups; private String groups;
private RemoteReader callback; private RemoteReader callback;
private InputStream inputStream; private InputStream inputStream;
private IncludedFileReader includedReader; private IncludedFileReader includedReader;
private boolean ignoreRemoteFailures = false;


private List<RepoProject> bareProjects; private List<RepoProject> bareProjects;
private Git git; private Git git;
* The URI of the remote repository * The URI of the remote repository
* @param ref * @param ref
* The ref (branch/tag/etc.) to read * 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 * @throws GitAPIException
*/ */
@Nullable
public ObjectId sha1(String uri, String ref) throws GitAPIException; public ObjectId sha1(String uri, String ref) throws GitAPIException;


/** /**
} }


/** /**
* Set whether the branch name should be recorded in .gitmodules
* Set whether the branch name should be recorded in .gitmodules.
* <p> * <p>
* Submodule entries in .gitmodules can include a "branch" field * Submodule entries in .gitmodules can include a "branch" field
* to indicate what remote branch each submodule tracks. * to indicate what remote branch each submodule tracks.
return this; 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. * Set the author/committer for the bare repository commit.
* <p> * <p>
for (RepoProject proj : bareProjects) { for (RepoProject proj : bareProjects) {
String name = proj.getPath(); String name = proj.getPath();
String nameUri = proj.getName(); 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; ObjectId objectId;
if (ObjectId.isId(proj.getRevision())) {
if (ObjectId.isId(proj.getRevision())
&& !ignoreRemoteFailures) {
objectId = ObjectId.fromString(proj.getRevision()); objectId = ObjectId.fromString(proj.getRevision());
} else { } else {
objectId = callback.sha1(nameUri, proj.getRevision()); 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 // can be branch or tag
cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$
proj.getRevision()); 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.setObjectId(objectId);
dcEntry.setFileMode(FileMode.GITLINK); dcEntry.setFileMode(FileMode.GITLINK);
builder.add(dcEntry); builder.add(dcEntry);

読み込み中…
キャンセル
保存