From 3c09e980cb7c60615d7fa89a257596ba5e949a5e Mon Sep 17 00:00:00 2001 From: Markus Duft Date: Mon, 9 Jul 2012 12:47:52 +0200 Subject: [PATCH] Make ApplyCommand create missing parent directories for new files Otherwise applying will fail with a FileNotFoundException, because File.createNewFile() fails with missing parents. Contains change & according test. Change-Id: I970522b549b8bb260ca6720da11f12c57ee8a492 Signed-off-by: Chris Aniszczyk --- .../tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch | Bin 0 -> 125 bytes .../org/eclipse/jgit/api/ApplyCommandTest.java | 8 ++++++++ .../src/org/eclipse/jgit/api/ApplyCommand.java | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch new file mode 100644 index 0000000000000000000000000000000000000000..09867f3be927b387f7ffeed80777566e5f79ccac GIT binary patch literal 125 zcmYL>u@1s83 zg}QGjwK?t&b41nSG*Rv5Z|IM4G(Vs8n?(e{d<}hRjhOkrNeQBZg5z*NO2jj9Cce@K Dt=u3~ literal 0 HcmV?d00001 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 16c0a9b44..3c38edb86 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 @@ -111,6 +111,14 @@ public void testAddA2() throws Exception { b.getString(0, b.size(), false)); } + @Test + public void testAddA1Sub() throws Exception { + ApplyResult result = init("A1_sub", false, false); + assertEquals(1, result.getUpdatedFiles().size()); + assertEquals(new File(db.getWorkTree(), "sub/A1"), result + .getUpdatedFiles().get(0)); + } + @Test public void testDeleteD() throws Exception { ApplyResult result = init("D", true, false); 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 32abf86ed..e6070eccf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java @@ -167,6 +167,8 @@ private File getFile(String path, boolean create) File f = new File(getRepository().getWorkTree(), path); if (create) try { + File parent = f.getParentFile(); + FileUtils.mkdirs(parent, true); FileUtils.createNewFile(f); } catch (IOException e) { throw new PatchApplyException(MessageFormat.format(