コード例 #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
  /**
   * Fetches all specified roots. Once a root has failed, stops and displays the notification. If
   * needed, displays the successful notification at the end.
   *
   * @param roots roots to fetch.
   * @param errorNotificationTitle if specified, this notification title will be used instead of the
   *     standard "Fetch failed". Use this when fetch is a part of a compound process.
   * @param notifySuccess if set to {@code true} successful notification will be displayed.
   * @return true if all fetches were successful, false if at least one fetch failed.
   */
  public boolean fetchRootsAndNotify(
      @NotNull Collection<GitRepository> roots,
      @Nullable String errorNotificationTitle,
      boolean notifySuccess) {
    Map<VirtualFile, String> additionalInfo = new HashMap<VirtualFile, String>();
    for (GitRepository repository : roots) {
      LOG.info("fetching " + repository);
      GitFetchResult result = fetch(repository);
      String ai = result.getAdditionalInfo();
      if (!StringUtil.isEmptyOrSpaces(ai)) {
        additionalInfo.put(repository.getRoot(), ai);
      }
      if (!result.isSuccess()) {
        Collection<Exception> errors = new ArrayList<Exception>(getErrors());
        errors.addAll(result.getErrors());
        displayFetchResult(myProject, result, errorNotificationTitle, errors);
        return false;
      }
    }
    if (notifySuccess) {
      GitUIUtil.notifySuccess(myProject, "", "Fetched successfully");
    }

    String addInfo = makeAdditionalInfoByRoot(additionalInfo);
    if (!StringUtil.isEmptyOrSpaces(addInfo)) {
      Notificator.getInstance(myProject)
          .notify(
              GitVcs.MINOR_NOTIFICATION, "Fetch details", addInfo, NotificationType.INFORMATION);
    }

    return true;
  }
コード例 #3
0
 public static void displayFetchResult(
     @NotNull Project project,
     @NotNull GitFetchResult result,
     @Nullable String errorNotificationTitle,
     @NotNull Collection<? extends Exception> errors) {
   if (result.isSuccess()) {
     GitVcs.NOTIFICATION_GROUP_ID
         .createNotification(
             "Fetched successfully" + result.getAdditionalInfo(), NotificationType.INFORMATION)
         .notify(project);
   } else if (result.isCancelled()) {
     GitVcs.NOTIFICATION_GROUP_ID
         .createNotification(
             "Fetch cancelled by user" + result.getAdditionalInfo(), NotificationType.WARNING)
         .notify(project);
   } else if (result.isNotAuthorized()) {
     String title;
     String description;
     if (errorNotificationTitle != null) {
       title = errorNotificationTitle;
       description = "Fetch failed: couldn't authorize";
     } else {
       title = "Fetch failed";
       description = "Couldn't authorize";
     }
     description += result.getAdditionalInfo();
     GitUIUtil.notifyMessage(project, title, description, NotificationType.ERROR, true, null);
   } else {
     GitVcs instance = GitVcs.getInstance(project);
     if (instance != null && instance.getExecutableValidator().isExecutableValid()) {
       GitUIUtil.notifyMessage(
           project,
           "Fetch failed",
           result.getAdditionalInfo(),
           NotificationType.ERROR,
           true,
           errors);
     }
   }
 }