public void testIsBare_CreateRepositoryFromArbitraryGitDir()
throws Exception {
File gitDir = getFile("workdir");
- assertTrue(new FileRepository(gitDir).isBare());
+ Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
+ assertTrue(repo.isBare());
}
@Test
public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
- Repository repo = new FileRepository(gitDir);
+ Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir");
assertGitdirPath(repo, "workdir", Constants.DOT_GIT);
public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir()
throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
- Repository repo = new FileRepository(gitDir);
+ Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
String workdir = repo.getWorkTree().getName();
assertEquals(workdir, "workdir");
}
@Test
public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
File gitDir = getFile("workdir");
- try {
- new FileRepository(gitDir).getWorkTree();
+ try (Repository repo = new FileRepository(gitDir)) {
+ repo.getWorkTree();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
@Test
public void testExceptionThrown_BareRepoGetIndex() throws Exception {
File gitDir = getFile("workdir");
- try {
- new FileRepository(gitDir).readDirCache();
+ try (Repository repo = new FileRepository(gitDir)) {
+ repo.readDirCache();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
@Test
public void testExceptionThrown_BareRepoGetIndexFile() throws Exception {
File gitDir = getFile("workdir");
- try {
- new FileRepository(gitDir).getIndexFile();
+ try (Repository repo = new FileRepository(gitDir)) {
+ repo.getIndexFile();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected