From 80fa5f39f9d3b742e34b4baad019d917ff19f318 Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Fri, 15 Apr 2016 14:37:32 -0700 Subject: Fix ApplyCommand when result of patch is an empty file Such hunks are identifiable by a zero value for "new start line". Prior to the fix, JGit throws and ArrayIndexOutOfBoundsException on such patches. Change-Id: I4f3deb5e5f41a08af965fcc178d678c77270cddb Signed-off-by: Jonathan Schneider Signed-off-by: Matthias Sohn --- org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch | 7 +++++++ .../tst-rsrc/org/eclipse/jgit/diff/W_PostImage | 0 .../tst-rsrc/org/eclipse/jgit/diff/W_PreImage | 1 + .../tst/org/eclipse/jgit/api/ApplyCommandTest.java | 10 ++++++++++ 4 files changed, 18 insertions(+) create mode 100644 org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch create mode 100644 org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage create mode 100644 org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch new file mode 100644 index 0000000000..cfecb8c5c4 --- /dev/null +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch @@ -0,0 +1,7 @@ +diff --git a/W b/W +index a3648a1..2d44096 100644 +--- a/W ++++ b/W +@@ -1 +0,0 @@ +-a +\ No newline at end of file \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage new file mode 100644 index 0000000000..e69de29bb2 diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage new file mode 100644 index 0000000000..2e65efe2a1 --- /dev/null +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java index 239c844c33..f2b5b3ba95 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java @@ -146,6 +146,16 @@ public class ApplyCommandTest extends RepositoryTestCase { b.getString(0, b.size(), false)); } + @Test + public void testModifyW() throws Exception { + ApplyResult result = init("W"); + assertEquals(1, result.getUpdatedFiles().size()); + assertEquals(new File(db.getWorkTree(), "W"), + result.getUpdatedFiles().get(0)); + checkFile(new File(db.getWorkTree(), "W"), + b.getString(0, b.size(), false)); + } + @Test public void testModifyX() throws Exception { ApplyResult result = init("X"); -- cgit v1.2.3