/* * 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(); }
private static void doRebaseCurrentBranch( @NotNull final Project project, @NotNull final VirtualFile root, @NotNull final ProgressIndicator indicator) { final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project); final GitRebaser rebaser = new GitRebaser(project, ServiceManager.getService(Git.class), indicator); final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.REBASE); handler.addParameters("upstream/master"); final GitRebaseProblemDetector rebaseConflictDetector = new GitRebaseProblemDetector(); handler.addLineListener(rebaseConflictDetector); final GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root); handler.addLineListener(untrackedFilesDetector); GitTask pullTask = new GitTask(project, handler, "Rebasing from upstream/master"); pullTask.setProgressIndicator(indicator); pullTask.setProgressAnalyzer(new GitStandardProgressAnalyzer()); pullTask.execute( true, false, new GitTaskResultHandlerAdapter() { @Override protected void onSuccess() { root.refresh(false, true); repositoryManager.updateRepository(root); GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork"); } @Override protected void onFailure() { GitUpdateResult result = rebaser.handleRebaseFailure( handler, root, rebaseConflictDetector, untrackedFilesDetector); repositoryManager.updateRepository(root); if (result == GitUpdateResult.NOTHING_TO_UPDATE || result == GitUpdateResult.SUCCESS || result == GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS) { GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork"); } } }); }
protected void performRemoteGitTask(final GitLineHandler handler, String title) throws ServerRuntimeException { final GitTask task = new GitTask(myProject, handler, title); task.setProgressAnalyzer(new GitStandardProgressAnalyzer()); final Semaphore semaphore = new Semaphore(); semaphore.down(); final Ref<ServerRuntimeException> errorRef = new Ref<ServerRuntimeException>(); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { task.execute( false, false, new GitTaskResultHandlerAdapter() { @Override protected void run(GitTaskResult result) { super.run(result); semaphore.up(); } @Override protected void onFailure() { for (VcsException error : handler.errors()) { myLoggingHandler.println(error.toString()); if (errorRef.isNull()) { errorRef.set(new ServerRuntimeException(error)); } } } }); } }); semaphore.waitFor(); if (!errorRef.isNull()) { throw errorRef.get(); } }
protected GitUpdateResult doUpdate() { LOG.info("doUpdate "); String remoteBranch = getRemoteBranchToMerge(); final GitLineHandler rebaseHandler = new GitLineHandler(myProject, myRoot, GitCommand.REBASE); rebaseHandler.addParameters(remoteBranch); final GitRebaseProblemDetector rebaseConflictDetector = new GitRebaseProblemDetector(); rebaseHandler.addLineListener(rebaseConflictDetector); GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(myRoot); rebaseHandler.addLineListener(untrackedFilesDetector); GitTask rebaseTask = new GitTask(myProject, rebaseHandler, "Rebasing"); rebaseTask.setProgressIndicator(myProgressIndicator); rebaseTask.setProgressAnalyzer(new GitStandardProgressAnalyzer()); final AtomicReference<GitUpdateResult> updateResult = new AtomicReference<GitUpdateResult>(); final AtomicBoolean failure = new AtomicBoolean(); rebaseTask.executeInBackground( true, new GitTaskResultHandlerAdapter() { @Override protected void onSuccess() { updateResult.set(GitUpdateResult.SUCCESS); } @Override protected void onCancel() { cancel(); updateResult.set(GitUpdateResult.CANCEL); } @Override protected void onFailure() { failure.set(true); } }); if (failure.get()) { updateResult.set( handleRebaseFailure(rebaseHandler, rebaseConflictDetector, untrackedFilesDetector)); } return updateResult.get(); }