Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322866 - Automagic detection of GIT_DIR fails
Summary: Automagic detection of GIT_DIR fails
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 0.9.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 0.9.0   Edit
Assignee: Christian Halstrick CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 01:26 EDT by Ketan Padegaonkar CLA
Modified: 2010-12-03 16:52 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ketan Padegaonkar CLA 2010-08-17 01:26:44 EDT
rev 11c5c9 of jgit.

I'd expect that running 'jgit log' on the command line would behave in a (mostly) similar way with 'git log' with respect to detection of the .git directory.

Specifically, the javadoc for RepositoryBuilder#findGitDir(File) mentions that '[it] Starts from the supplied directory path and scans up through the parent directory tree until a Git repository is found'. However it does not quite behave in the way that it documents.

This is because ceilingDirectories is null/empty at the time this method is called.

storm:~/projects/dev/jgit git (master)$ java -jar org.eclipse.jgit.pgm/target/jgit-cli.jar log > /dev/null

As expected, everything is fine, and there is no error.

Now lets do the same in a sub dir:

storm:~/projects/dev/jgit/org.eclipse.jgit.pgm git (master)$ java -jar target/jgit-cli.jar log > /dev/null
java.lang.NullPointerException
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.findGitDir(BaseRepositoryBuilder.java:417)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.findGitDir(BaseRepositoryBuilder.java:387)
	at org.eclipse.jgit.pgm.Main.execute(Main.java:166)
	at org.eclipse.jgit.pgm.Main.main(Main.java:99)

Here is a failing test case that can reproduce the error, that you may add to the jgit test suite.

public class RepositoryBuilderTest extends LocalDiskRepositoryTestCase {

	public void testShouldAutomagicallyDetectGitDirectory() throws Exception {
		FileRepository repository = createWorkRepository();
		File subDir = new File(repository.getDirectory(), "sub-dir");
		subDir.mkdir();
		assertEquals(repository.getDirectory(), new RepositoryBuilder().findGitDir(subDir));
	}

}
Comment 1 Shawn Pearce CLA 2010-12-03 16:52:40 EST
Fixed by change I64205bb0315a725dfa523ccff1796de50f465162