/** * 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; }
@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; }