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 <zx@twitter.com>
This commit is contained in:
Markus Duft 2012-07-09 12:47:52 +02:00 committed by Chris Aniszczyk
parent 0e285fbb8c
commit 3c09e980cb
3 changed files with 10 additions and 0 deletions

View File

@ -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);

View File

@ -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(