]> source.dussan.org Git - jgit.git/commitdiff
RebaseCommand: trim line endings when reading files 40/1940/4
authorMathias Kinzler <mathias.kinzler@sap.com>
Fri, 26 Nov 2010 07:29:48 +0000 (08:29 +0100)
committerMathias Kinzler <mathias.kinzler@sap.com>
Fri, 26 Nov 2010 11:22:40 +0000 (12:22 +0100)
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 <mathias.kinzler@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

index 0938ec10514c20f6aa57b961cc32abbde05b7886..f92459041748bb74d693055326c9cfd41664bb04 100644 (file)
@@ -396,6 +396,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                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<RebaseResult> {
        }
 
        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 {