From 12b635043506211fe9c873f14fc8e03546d6081d Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Fri, 26 Nov 2010 08:29:48 +0100 Subject: [PATCH] RebaseCommand: trim line endings when reading files In order to enable interoperability with the command line, we need to remove line feeds when reading the files. Change-Id: Ie2f5799037a60243bb4fac52346908ff85c0ce5d Signed-off-by: Mathias Kinzler --- .../src/org/eclipse/jgit/api/RebaseCommand.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 0938ec105..f92459041 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -396,6 +396,7 @@ public class RebaseCommand extends GitCommand { FileOutputStream fos = new FileOutputStream(file); try { fos.write(content.getBytes("UTF-8")); + fos.write('\n'); } finally { fos.close(); } @@ -458,8 +459,12 @@ public class RebaseCommand extends GitCommand { } private String readFile(File directory, String fileName) throws IOException { - return RawParseUtils - .decode(IO.readFully(new File(directory, fileName))); + byte[] content = IO.readFully(new File(directory, fileName)); + // strip off the last LF + int end = content.length; + while (0 < end && content[end - 1] == '\n') + end--; + return RawParseUtils.decode(content, 0, end); } private void checkoutCommit(RevCommit commit) throws IOException {