Пример #1
0
  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 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();
  }