[git] before 2.8.0 git for windows expects to have LF symbol as line separator in standard input instead of CRLF

IDEA-174661
This commit is contained in:
Julia Beliaeva
2017-06-20 03:08:31 +03:00
parent 869e1f7e2c
commit e365c05411
2 changed files with 19 additions and 2 deletions
@@ -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);
@@ -356,14 +356,15 @@ public class GitLogUtil {
};
GitLineHandler handler = new GitLineHandler(project, root, GitCommand.LOG, createConfigParameters(true));
String separator = getSeparator(vcs);
Ref<Exception> 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";