@Test
public void lockFailedExceptionRecovery() throws Exception {
- Git git = new Git(db);
- writeTrashFile("file.txt", "content");
- git.add().addFilepattern("file.txt").call();
- RevCommit commit1 = git.commit().setMessage("create file").call();
+ try (Git git = new Git(db)) {
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit commit1 = git.commit().setMessage("create file").call();
- assertNotNull(commit1);
- writeTrashFile("file.txt", "content2");
- git.add().addFilepattern("file.txt").call();
- assertNotNull(git.commit().setMessage("edit file").call());
+ assertNotNull(commit1);
+ writeTrashFile("file.txt", "content2");
+ git.add().addFilepattern("file.txt").call();
+ assertNotNull(git.commit().setMessage("edit file").call());
- LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
- assertTrue(lf.lock());
- try {
- git.checkout().setName(commit1.name()).call();
- fail("JGitInternalException not thrown");
- } catch (JGitInternalException e) {
- assertTrue(e.getCause() instanceof LockFailedException);
- lf.unlock();
- git.checkout().setName(commit1.name()).call();
+ LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
+ assertTrue(lf.lock());
+ try {
+ git.checkout().setName(commit1.name()).call();
+ fail("JGitInternalException not thrown");
+ } catch (JGitInternalException e) {
+ assertTrue(e.getCause() instanceof LockFailedException);
+ lf.unlock();
+ git.checkout().setName(commit1.name()).call();
+ }
}
}
}