use of org.eclipse.jgit.api.errors.InvalidRemoteException in project bazel by bazelbuild.
the class GitCloner method clone.
public static SkyValue clone(Rule rule, Path outputDirectory, ExtendedEventHandler eventHandler, Map<String, String> clientEnvironment) throws RepositoryFunctionException {
WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
if (mapper.isAttributeValueExplicitlySpecified("commit") == mapper.isAttributeValueExplicitlySpecified("tag")) {
throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "One of either commit or tag must be defined"), Transience.PERSISTENT);
}
GitRepositoryDescriptor descriptor;
String startingPoint;
try {
if (mapper.isAttributeValueExplicitlySpecified("commit")) {
startingPoint = mapper.get("commit", Type.STRING);
} else {
startingPoint = "tags/" + mapper.get("tag", Type.STRING);
}
descriptor = new GitRepositoryDescriptor(mapper.get("remote", Type.STRING), startingPoint, mapper.get("init_submodules", Type.BOOLEAN), outputDirectory);
} catch (EvalException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
}
// Setup proxy if remote is http or https
if (descriptor.remote != null && Ascii.toLowerCase(descriptor.remote).startsWith("http")) {
try {
new ProxyHelper(clientEnvironment).createProxyIfNeeded(new URL(descriptor.remote));
} catch (IOException ie) {
throw new RepositoryFunctionException(ie, Transience.TRANSIENT);
}
}
Git git = null;
try {
if (descriptor.directory.exists()) {
if (isUpToDate(descriptor)) {
return new HttpDownloadValue(descriptor.directory);
}
try {
FileSystemUtils.deleteTree(descriptor.directory);
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
}
git = Git.cloneRepository().setURI(descriptor.remote).setCredentialsProvider(new NetRCCredentialsProvider()).setDirectory(descriptor.directory.getPathFile()).setCloneSubmodules(false).setNoCheckout(true).setProgressMonitor(new GitProgressMonitor(descriptor.remote, "Cloning " + descriptor.remote, eventHandler)).call();
git.checkout().setCreateBranch(true).setName("bazel-checkout").setStartPoint(descriptor.checkout).call();
// the first level.
if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) {
git.submoduleUpdate().setProgressMonitor(new GitProgressMonitor(descriptor.remote, "Cloning submodules for " + descriptor.remote, eventHandler)).call();
}
} catch (InvalidRemoteException e) {
throw new RepositoryFunctionException(new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT);
} catch (RefNotFoundException | InvalidRefNameException e) {
throw new RepositoryFunctionException(new IOException("Invalid branch, tag, or commit: " + e.getMessage()), Transience.PERSISTENT);
} catch (GitAPIException e) {
// This is a sad attempt to actually get a useful error message out of jGit, which will bury
// the actual (useful) cause of the exception under several throws.
StringBuilder errmsg = new StringBuilder();
errmsg.append(e.getMessage());
Throwable throwable = e;
while (throwable.getCause() != null) {
throwable = throwable.getCause();
errmsg.append(" caused by " + throwable.getMessage());
}
throw new RepositoryFunctionException(new IOException("Error cloning repository: " + errmsg), Transience.PERSISTENT);
} catch (JGitInternalException e) {
// caller of the command can handle them effectively." Thanks, jgit.
throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.PERSISTENT);
} finally {
if (git != null) {
git.close();
}
}
return new HttpDownloadValue(descriptor.directory);
}
use of org.eclipse.jgit.api.errors.InvalidRemoteException in project compiler by boalang.
the class RepositoryCloner method main.
public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
String localpath = args[1];
String url = args[0];
REMOTE_URL = url;
File localPath = new File(localpath);
if (!localPath.exists())
localPath.mkdir();
// then clone
Git result = null;
try {
result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call();
// Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
result.getRepository().close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (result != null && result.getRepository() != null)
result.getRepository().close();
}
}
use of org.eclipse.jgit.api.errors.InvalidRemoteException in project compiler by boalang.
the class RepositoryCloner method clone.
public static void clone(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
// prepare a new folder for the cloned repository
String localpaths = args[1];
String url = args[0];
REMOTE_URL = url;
File localPath = new File(localpaths);
if (!localPath.exists())
localPath.mkdir();
// then clone
Git result = null;
try {
result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call();
// Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
result.getRepository().close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (result != null && result.getRepository() != null)
result.getRepository().close();
}
}
Aggregations