diff --git a/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java b/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java index f5077d4bc764..7ae48528db7d 100644 --- a/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java +++ b/plugins/git4idea/src/git4idea/checkout/GitCheckoutProvider.java @@ -29,6 +29,7 @@ import git4idea.actions.BasicAction; import git4idea.commands.GitCommandResult; import git4idea.i18n.GitBundle; import git4idea.jgit.GitHttpAdapter; +import git4idea.ui.GitUIUtil; import git4idea.update.GitFetchResult; import git4idea.update.GitFetcher; import org.jetbrains.annotations.NotNull; @@ -119,8 +120,7 @@ public class GitCheckoutProvider implements CheckoutProvider { if (result.success()) { return true; } - GitVcs.IMPORTANT_ERROR_NOTIFICATION.createNotification("Clone failed", result.getErrorOutputAsHtmlString(), NotificationType.ERROR, null) - .notify(project.isDefault() ? null : project); + GitUIUtil.notify(GitVcs.IMPORTANT_ERROR_NOTIFICATION, project, "Clone failed", result.getErrorOutputAsHtmlString(), NotificationType.ERROR, null); return false; } diff --git a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java index f4c947ebc396..933dbe39a6ce 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUIUtil.java +++ b/plugins/git4idea/src/git4idea/ui/GitUIUtil.java @@ -17,6 +17,7 @@ package git4idea.ui; import com.intellij.ide.ui.ListCellRendererWrapper; import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -56,21 +57,28 @@ public class GitUIUtil { * A private constructor for utility class */ private GitUIUtil() { } - - public static void notifyMessages(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection messages) { + + public static void notify(@NotNull NotificationGroup group, @NotNull Project project, @Nullable String title, @Nullable String description, @NotNull NotificationType type, @Nullable NotificationListener listener) { + // title can't be null, but can be empty; description can't be neither null, nor empty if (title == null) { title = ""; } + if (StringUtil.isEmptyOrSpaces(description)) { + description = title; + title = ""; + } + // if both title and description were empty, then it is a problem in the calling code => let assertion notify about that. + assert description != null : "description is null after StringUtil.isEmptyOrSpaces(). title: " + title; + group.createNotification(title, description, type, listener).notify(project.isDefault() ? null : project); + } + + public static void notifyMessages(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection messages) { String desc = (description != null ? description.replace("\n", "
") : ""); if (messages != null && !messages.isEmpty()) { desc += "
" + StringUtil.join(messages, "
"); } - if (StringUtil.isEmptyOrSpaces(desc)) { - desc = StringUtil.isEmptyOrSpaces(title) ? "Error" : title; // description is not allowed to be empty, title is => moving title text to description - title = ""; - } NotificationGroup group = important ? GitVcs.IMPORTANT_ERROR_NOTIFICATION : GitVcs.NOTIFICATION_GROUP_ID; - group.createNotification(title, desc, type, null).notify(project.isDefault() ? null : project); + notify(group, project, title, desc, type, null); } public static void notifyMessage(Project project, @Nullable String title, @Nullable String description, NotificationType type, boolean important, @Nullable Collection errors) {