示例#1
0
 @NotNull
 private GitFetchResult fetchAll(
     @NotNull GitRepository repository, @NotNull GitFetchResult fetchResult) {
   for (GitRemote remote : repository.getRemotes()) {
     String url = remote.getFirstUrl();
     if (url == null) {
       LOG.error("URL is null for remote " + remote.getName());
       continue;
     }
     if (GitHttpAdapter.shouldUseJGit(url)) {
       GitFetchResult res = GitHttpAdapter.fetch(repository, remote, url, null);
       res.addPruneInfo(fetchResult.getPrunedRefs());
       fetchResult = res;
       myErrors.addAll(fetchResult.getErrors());
       if (!fetchResult.isSuccess()) {
         break;
       }
     } else {
       GitFetchResult res = fetchNatively(repository.getRoot(), remote, null);
       res.addPruneInfo(fetchResult.getPrunedRefs());
       fetchResult = res;
       if (!fetchResult.isSuccess()) {
         break;
       }
     }
   }
   return fetchResult;
 }
示例#2
0
  @NotNull
  private static FetchParams getFetchParams(@NotNull GitRepository repository) {
    GitLocalBranch currentBranch = repository.getCurrentBranch();
    if (currentBranch == null) {
      // fetching current branch is called from Update Project and Push, where branch tracking is
      // pre-checked
      String message = "Current branch can't be null here. \nRepository: " + repository;
      LOG.error(message);
      return new FetchParams(GitFetchResult.error(new Exception(message)));
    }
    GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
    if (trackInfo == null) {
      String message =
          "Tracked info is null for branch " + currentBranch + "\n Repository: " + repository;
      LOG.error(message);
      return new FetchParams(GitFetchResult.error(new Exception(message)));
    }

    GitRemote remote = trackInfo.getRemote();
    String url = remote.getFirstUrl();
    if (url == null) {
      String message = "URL is null for remote " + remote.getName();
      LOG.error(message);
      return new FetchParams(GitFetchResult.error(new Exception(message)));
    }

    return new FetchParams(remote, trackInfo.getRemoteBranch(), url);
  }
示例#3
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();
  }
示例#4
0
 @NotNull
 public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName) {
   GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
   if (repository == null) {
     return logError("Repository can't be null for " + root, myRepositoryManager.toString());
   }
   GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
   if (remote == null) {
     return logError("Couldn't find remote with the name " + remoteName, null);
   }
   String url = remote.getFirstUrl();
   if (url == null) {
     return logError("URL is null for remote " + remote.getName(), null);
   }
   return fetchRemote(repository, remote, url);
 }
 private String getFetchUrl(@NotNull final GitRemote gitRemote) {
   return gitRemote.getFirstUrl();
 }