Bug 535333 - Repository.isBare() return true for empty repository
Summary: Repository.isBare() return true for empty repository
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-30 08:00 EDT by Cong-Xin Qiu CLA
Modified: 2018-05-30 08:02 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cong-Xin Qiu CLA 2018-05-30 08:00:08 EDT
public class GitRepositoryTest {
	
	@Rule public TemporaryFolder folder = new TemporaryFolder();

	@Test
	public void testBuild() throws IOException {
		
		File directory = folder.newFolder("repo");
		
		FileRepositoryBuilder builder = new FileRepositoryBuilder();
		Repository jGitRepository = builder.setGitDir(directory).readEnvironment().findGitDir().build();
		
		// print nothing
		for (File file : directory.listFiles()) {
			System.out.println(file);
		}
		
		// JGit return isBare() true value even if the folder is empty
		assertTrue(jGitRepository.isBare());
	}
}
Comment 1 Cong-Xin Qiu CLA 2018-05-30 08:02:50 EDT
May consider implement it through `git rev-parse --is-bare-repository`, which may be safer.