aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-03-10 19:26:39 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-05-26 00:38:00 +0200
commit1126f26d21b3aadf364af09c79d27d39de5e9bb9 (patch)
tree5e733d0115cc4ed604de370b917149ecd8a45e17 /org.eclipse.jgit/src/org/eclipse
parent2a0295ccfd1cf8dcb1067575f38c86f430285cda (diff)
downloadjgit-1126f26d21b3aadf364af09c79d27d39de5e9bb9.tar.gz
jgit-1126f26d21b3aadf364af09c79d27d39de5e9bb9.zip
ApplyCommand: fix "no newline at end" detection
Check the last line of the last hunk of a file, not the last line of the whole patch. Note that C git only checks that this line starts with "\ " and is at least 12 characters long because of possible different texts when non- English messages are used. Change-Id: I0db81699eb3e99ed7b536a3e2b8dc97df1f58a89 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
index f649c5fdeb..583767af3f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
@@ -742,7 +742,11 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
return false;
}
HunkHeader lastHunk = hunks.get(hunks.size() - 1);
- RawText lhrt = new RawText(lastHunk.getBuffer());
+ byte[] buf = new byte[lastHunk.getEndOffset()
+ - lastHunk.getStartOffset()];
+ System.arraycopy(lastHunk.getBuffer(), lastHunk.getStartOffset(), buf,
+ 0, buf.length);
+ RawText lhrt = new RawText(buf);
return lhrt.getString(lhrt.size() - 1)
.equals("\\ No newline at end of file"); //$NON-NLS-1$
}