diff options
5 files changed, 30 insertions, 6 deletions
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 --- /dev/null +++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage 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 @@ -147,6 +147,16 @@ public class ApplyCommandTest extends RepositoryTestCase { } @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"); assertEquals(1, result.getUpdatedFiles().size()); 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 bde450f99d..8fbf83954c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java @@ -223,12 +223,16 @@ public class ApplyCommand extends GitCommand<ApplyResult> { pos++; break; case '-': - if (!newLines.get(hh.getNewStartLine() - 1 + pos).equals( - hunkLine.substring(1))) { - throw new PatchApplyException(MessageFormat.format( - JGitText.get().patchApplyException, hh)); + if (hh.getNewStartLine() == 0) { + newLines.clear(); + } else { + if (!newLines.get(hh.getNewStartLine() - 1 + pos) + .equals(hunkLine.substring(1))) { + throw new PatchApplyException(MessageFormat.format( + JGitText.get().patchApplyException, hh)); + } + newLines.remove(hh.getNewStartLine() - 1 + pos); } - newLines.remove(hh.getNewStartLine() - 1 + pos); break; case '+': newLines.add(hh.getNewStartLine() - 1 + pos, @@ -250,7 +254,9 @@ public class ApplyCommand extends GitCommand<ApplyResult> { // still there! sb.append(l).append('\n'); } - sb.deleteCharAt(sb.length() - 1); + if (sb.length() > 0) { + sb.deleteCharAt(sb.length() - 1); + } FileWriter fw = new FileWriter(f); fw.write(sb.toString()); fw.close(); |