From 410a8e15e0c69b76fed25a42b0fa659c1a44ce73 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 5 Mar 2015 14:02:11 +0300 Subject: [PATCH] [git] IDEA-92750 handle exceptions in case of incorrect git output --- .../src/git4idea/merge/GitPullDialog.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java index 1839f31d5e18..f01a2083980e 100644 --- a/plugins/git4idea/src/git4idea/merge/GitPullDialog.java +++ b/plugins/git4idea/src/git4idea/merge/GitPullDialog.java @@ -140,14 +140,15 @@ public class GitPullDialog extends DialogWrapper { }); if (!result.isNull() && result.get().success()) { - return ContainerUtil.mapNotNull(result.get().getOutput(), new Function() { - @Override - public String fun(@NotNull String line) { - if (StringUtil.isEmptyOrSpaces(line)) return null; - String shortRemoteName = line.trim().substring(line.indexOf(GitBranch.REFS_HEADS_PREFIX) + GitBranch.REFS_HEADS_PREFIX.length()); - return remote.getName() + "/" + shortRemoteName; - } - }); + try { + return parseRemoteBranches(remote, result.get().getOutput()); + } + catch (Exception e) { + LOG.error("Couldn't parse ls-remote output: [" + result.get().getOutput() + "]", e); + Messages.showErrorDialog(this.getRootPane(), "Couldn't parse ls-remote output", + "Couldn't get the remote branches list from " + remote.getName()); + return null; + } } else { String message = result.isNull() ? "" : result.get().getErrorOutputAsJoinedString(); @@ -156,6 +157,18 @@ public class GitPullDialog extends DialogWrapper { } } + @NotNull + private static List parseRemoteBranches(@NotNull final GitRemote remote, @NotNull List lsRemoteOutputLines) { + return ContainerUtil.mapNotNull(lsRemoteOutputLines, new Function() { + @Override + public String fun(@NotNull String line) { + if (StringUtil.isEmptyOrSpaces(line)) return null; + String shortRemoteName = line.trim().substring(line.indexOf(GitBranch.REFS_HEADS_PREFIX) + GitBranch.REFS_HEADS_PREFIX.length()); + return remote.getName() + "/" + shortRemoteName; + } + }); + } + private void validateDialog() { String selectedRemote = getRemote(); if (StringUtil.isEmptyOrSpaces(selectedRemote)) {