@Override protected IRemoteRepo _call() { Preconditions.checkNotNull(remote, "remote to connect to not provided"); Optional<IRemoteRepo> opRemote = RemoteResolver.newRemote(remote, remoteHints); checkArgument(opRemote.isPresent(), "Unknown remote type: " + remote.getFetchURL()); IRemoteRepo remoteRepo = opRemote.get(); try { remoteRepo.open(); } catch (RepositoryConnectionException e) { throw new IllegalStateException("Failed to connect to remote: " + e.getMessage(), e); } return remoteRepo; }
@Override protected IRemoteRepo _call() { Preconditions.checkNotNull(remote, "remote to connect to not provided"); Optional<IRemoteRepo> opRemote = RemoteResolver.newRemote(remote, remoteHints); checkArgument(opRemote.isPresent(), "Unknown remote type: " + remote.getFetchURL()); IRemoteRepo remoteRepo = opRemote.get(); try { remoteRepo.open(); } catch (RepositoryConnectionException e) { throw new IllegalStateException("Failed to connect to remote: " + e.getMessage(), e); } return remoteRepo; }
private static Ref pingRemote(Remote remote) throws Exception { Optional<IRemoteRepo> remoteRepo; try { Hints hints = Hints.readOnly(); Repository localRepo = GlobalContextBuilder.builder().build(hints).repository(); remoteRepo = RemoteResolver.newRemote(remote, null); if (!remoteRepo.isPresent()) { throw new IllegalArgumentException("Repository not found or not reachable"); } else { IRemoteRepo repo = remoteRepo.get(); try { repo.open(); Optional<Ref> head = repo.headRef(); return head.orNull(); } finally { repo.close(); } } } catch (Exception e) { throw new IllegalArgumentException("Unable to connect: " + e.getMessage(), e); } }