summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMarkus Duft2012-07-09 06:47:52 (EDT)
committer Chris Aniszczyk2012-07-16 12:04:30 (EDT)
commit3c09e980cb7c60615d7fa89a257596ba5e949a5e (patch)
tree770af038f3f0d56da0b15d45860c9eaf28ea306d
parent0e285fbb8c3dd200d65a6fef59eb750c54764fb8 (diff)
downloadjgit-3c09e980cb7c60615d7fa89a257596ba5e949a5e.zip
jgit-3c09e980cb7c60615d7fa89a257596ba5e949a5e.tar.gz
jgit-3c09e980cb7c60615d7fa89a257596ba5e949a5e.tar.bz2
Make ApplyCommand create missing parent directories for new filesrefs/changes/73/6673/3
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 <zx@twitter.com>
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java2
3 files changed, 19 insertions, 0 deletions
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 0000000..09867f3
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/A1_sub.patch
@@ -0,0 +1,9 @@
+diff --git a/sub/A1 b/sub/A1
+new file mode 100644
+index 0000000..de98044
+--- /dev/null
++++ b/sub/A1
+@@ -0,0 +1,3 @@
++a
++b
++c
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 16c0a9b..3c38edb 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
@@ -112,6 +112,14 @@ public class ApplyCommandTest extends RepositoryTestCase {
}
@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);
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 32abf86..e6070ec 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 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
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(