assertFalse(new File(db.getWorkTree(), "dir-or-file").exists());
}
+ @Test
+ public void testHardResetWithConflicts_CreateFolder_UnstagedChanges() throws Exception {
+ setupRepository();
+
+ writeTrashFile("dir-or-file/c.txt", "content");
+ git.add().addFilepattern("dir-or-file/c.txt").call();
+ git.commit().setMessage("adding dir-or-file/c.txt").call();
+
+ FileUtils.delete(new File(db.getWorkTree(), "dir-or-file"), FileUtils.RECURSIVE);
+ writeTrashFile("dir-or-file", "content");
+
+ // bug 479266: cannot create folder "dir-or-file"
+ git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD).call();
+ assertTrue(new File(db.getWorkTree(), "dir-or-file/c.txt").exists());
+ }
+
@Test
public void testResetToNonexistingHEAD() throws JGitInternalException,
AmbiguousObjectException, IOException, GitAPIException {
}
}
+ @Test
+ public void testCheckoutWithEmptyIndexDoesntOverwrite() throws Exception {
+ try (Git git = new Git(db);
+ TestRepository<Repository> db_t = new TestRepository<>(db)) {
+ // prepare the commits
+ BranchBuilder master = db_t.branch("master");
+ RevCommit mergeCommit = master.commit()
+ .add("p/x", "headContent")
+ .message("m0").create();
+ master.commit().add("p/x", "headContent").message("m1").create();
+ git.checkout().setName("master").call();
+
+ // empty index and write unsaved data in 'p'
+ git.rm().addFilepattern("p").call();
+ writeTrashFile("p", "important data");
+
+ git.checkout().setName(mergeCommit.getName()).call();
+
+ assertEquals("", indexState(CONTENT));
+ assertEquals("important data", read("p"));
+ }
+ }
+
private static class TestFileTreeIterator extends FileTreeIterator {
// For assertions only
ObjectLoader ol = or.open(entry.getObjectId());
File f = new File(repo.getWorkTree(), entry.getPathString());
File parentDir = f.getParentFile();
+ if (parentDir.isFile()) {
+ FileUtils.delete(parentDir);
+ }
FileUtils.mkdirs(parentDir, true);
FS fs = repo.getFS();
WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);