Community
Participate
Working Groups
I am testing some plugins in Eclipse. Many tests clone a github repository. Before run of a test using same repository, I perform clean up of git folder by recursive removal of files programmatically. Unfortunately I was not able to delete it successfully because some PACK files in .git/objects/pack cannot be deleted. It is happening only on Windows. I found a thread on stackoverflow http://stackoverflow.com/questions/19191727/pack-file-from-git-repo-cant-be-deleted-using-file-delete-method which lead me to thread http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg01961.html. But even attempt to set packed Git MMAP to false has not solved the problem.
Typically you have this problem if you don't close the repositories and the end of your test. This leads to the situation that JGit still has FileHandles open on packfiles and only on windows this leads to the situation that the packfiles can't be deleted. I would concentrate on one of your tests which fails and make sure that the repos are closed. This became easier to achieve since Git classes became autocloseable. E.g. like in this class: try (Git git = Git.init().setDirectory(tmp.toFile()).call()) { System.out.println("Repo created in " + tmp); Files.write(tmp.resolve("a"), "a".getBytes()); git.add().addFilepattern("a").call(); git.commit().setMessage("add a").call(); } finally { Files.walkFileTree(tmp, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } (https://raw.githubusercontent.com/chalstrick/chrisFiles/master/git/java/src/Template_createRepoInTmp.java)