From e365c054112cc53172098f2ea440dd124168f488 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 20 Jun 2017 01:11:40 +0300 Subject: [PATCH] [git] before 2.8.0 git for windows expects to have LF symbol as line separator in standard input instead of CRLF IDEA-174661 --- .../src/git4idea/config/GitVersionSpecialty.java | 8 ++++++++ .../git4idea/src/git4idea/history/GitLogUtil.java | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java index b497aca91b05..2e10e4b8ce6e 100644 --- a/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java +++ b/plugins/git4idea/src/git4idea/config/GitVersionSpecialty.java @@ -168,6 +168,14 @@ public enum GitVersionSpecialty { public boolean existsIn(@NotNull GitVersion version) { return version.isLaterOrEqual(new GitVersion(1, 8, 2, 0)); } + }, + + INCORRECT_SEPARATORS_IN_STDIN { + @Override + public boolean existsIn(@NotNull GitVersion version) { + // before 2.8.0 git for windows expects to have LF symbol as line separator in standard input instead of CRLF + return SystemInfo.isWindows && !version.isLaterOrEqual(new GitVersion(2, 8, 0, 0)); + } }; public abstract boolean existsIn(@NotNull GitVersion version); diff --git a/plugins/git4idea/src/git4idea/history/GitLogUtil.java b/plugins/git4idea/src/git4idea/history/GitLogUtil.java index b8855ab7aa3a..cc5612901ed7 100644 --- a/plugins/git4idea/src/git4idea/history/GitLogUtil.java +++ b/plugins/git4idea/src/git4idea/history/GitLogUtil.java @@ -356,14 +356,15 @@ public class GitLogUtil { }; GitLineHandler handler = new GitLineHandler(project, root, GitCommand.LOG, createConfigParameters(true)); + String separator = getSeparator(vcs); Ref inputError = new Ref<>(); handler.setInputProcessor(stream -> { try (OutputStreamWriter writer = new OutputStreamWriter(stream, handler.getCharset())) { for (String hash : hashes) { writer.write(hash); - writer.write(System.lineSeparator()); + writer.write(separator); } - writer.write(System.lineSeparator()); + writer.write(separator); writer.flush(); } catch (IOException e) { @@ -380,6 +381,14 @@ public class GitLogUtil { } } + @NotNull + private static String getSeparator(@NotNull GitVcs vcs) { + if (GitVersionSpecialty.INCORRECT_SEPARATORS_IN_STDIN.existsIn(vcs.getVersion())) { + return "\n"; + } + return System.lineSeparator(); + } + @NotNull public static String getNoWalkParameter(@NotNull GitVcs vcs) { return GitVersionSpecialty.NO_WALK_UNSORTED.existsIn(vcs.getVersion()) ? "--no-walk=unsorted" : "--no-walk";