/* * JGit doesn't have ls-remote command independent from repository yet. * That way, we have a hack here: if http response asked for a password, then the url is at least valid and existant, and we consider * that the test passed. */ private boolean test(String url) { final GitLineHandlerPasswordRequestAware handler = new GitLineHandlerPasswordRequestAware(myProject, new File("."), GitCommand.LS_REMOTE); handler.setRemoteProtocol(url); handler.addParameters(url, "master"); GitTask task = new GitTask(myProject, handler, GitBundle.message("clone.testing", url)); GitTaskResult result = task.executeModal(); boolean authFailed = handler.hadAuthRequest(); return result.isOK() || authFailed; }
private GitFetchResult fetchNatively( @NotNull VirtualFile root, @NotNull GitRemote remote, @Nullable String branch) { final GitLineHandlerPasswordRequestAware h = new GitLineHandlerPasswordRequestAware(myProject, root, GitCommand.FETCH); h.addProgressParameter(); if (GitVersionSpecialty.SUPPORTS_FETCH_PRUNE.existsIn(myVcs.getVersion())) { h.addParameters("--prune"); } String remoteName = remote.getName(); h.addParameters(remoteName); if (branch != null) { h.addParameters(getFetchSpecForBranch(branch, remoteName)); } final GitTask fetchTask = new GitTask(myProject, h, "Fetching " + remote.getFirstUrl()); fetchTask.setProgressIndicator(myProgressIndicator); fetchTask.setProgressAnalyzer(new GitStandardProgressAnalyzer()); GitFetchPruneDetector pruneDetector = new GitFetchPruneDetector(); h.addLineListener(pruneDetector); final AtomicReference<GitFetchResult> result = new AtomicReference<GitFetchResult>(); fetchTask.execute( true, false, new GitTaskResultHandlerAdapter() { @Override protected void onSuccess() { result.set(GitFetchResult.success()); } @Override protected void onCancel() { LOG.info("Cancelled fetch."); result.set(GitFetchResult.cancel()); } @Override protected void onFailure() { LOG.info("Error fetching: " + h.errors()); if (!h.hadAuthRequest()) { myErrors.addAll(h.errors()); } else { myErrors.add(new VcsException("Authentication failed")); } result.set(GitFetchResult.error(myErrors)); } }); result.get().addPruneInfo(pruneDetector.getPrunedRefs()); return result.get(); }