indexState(db2, CONTENT));
}
+ @Test
+ public void testCheckoutOfFileWithInexistentParentDir() throws Exception {
+ File a = writeTrashFile("dir/a.txt", "A");
+ writeTrashFile("dir/b.txt", "A");
+ git.add().addFilepattern("dir/a.txt").addFilepattern("dir/b.txt")
+ .call();
+ git.commit().setMessage("Added dir").call();
+
+ File dir = new File(db.getWorkTree(), "dir");
+ FileUtils.delete(dir, FileUtils.RECURSIVE);
+
+ git.checkout().addPath("dir/a.txt").call();
+ assertTrue(a.exists());
+ }
+
@Test
public void testDetachedHeadOnCheckout() throws JGitInternalException,
IOException, GitAPIException {
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
+import org.eclipse.jgit.util.FileUtils;
/**
* Checkout a branch to the working tree
public void apply(DirCacheEntry ent) {
ent.setObjectId(blobId);
ent.setFileMode(mode);
+ File file = new File(workTree, ent.getPathString());
+ File parentDir = file.getParentFile();
try {
- DirCacheCheckout.checkoutEntry(repo, new File(
- workTree, ent.getPathString()), ent, r);
+ FileUtils.mkdirs(parentDir, true);
+ DirCacheCheckout.checkoutEntry(repo, file, ent, r);
} catch (IOException e) {
throw new JGitInternalException(
MessageFormat.format(