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:
parent
0e285fbb8c
commit
3c09e980cb
Binary file not shown.
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue