TreeCheckoutOperation implements Callable<ObjectId, IOException> { public ObjectId call() throws IOException { RevTree tree = commit.getTree(); DirCache dirCache = repo.lockDirCache(); DirCacheCheckout co = new DirCacheCheckout(repo, dirCache, tree); co.setFailOnConflict(false); if (!co.checkout()) throw new IOException("Checkout failed"); return tree; } TreeCheckoutOperation(Repository repo, RevCommit commit); ObjectId call();  }
@Test public void checkoutPreviousCommitTree() throws Exception { RevCommit commit = git.add("file.txt", "a"); git.add("file.txt", "b"); Repository repo = git.repo(); File file = new File(repo.getWorkTree(), "file.txt"); FileReader reader = new FileReader(file); assertEquals('b', (char) reader.read()); reader.close(); TreeCheckoutOperation op = new TreeCheckoutOperation(repo, commit); ObjectId tree = op.call(); assertEquals(commit.getTree(), tree); reader = new FileReader(file); assertEquals('a', (char) reader.read()); reader.close(); }