Skip to main content
diff options
authorRobin Rosenberg2009-12-09 08:54:08 +0000
committerShawn O. Pearce2009-12-28 23:58:47 +0000
commiteb63bfc1b82ce21516b211df45069cbea87b7eee (patch)
treedc8e63302d0eadcedacb933bfda2d8ebc5b46d90 /org.eclipse.jgit.junit/src
parent5b13adcea97c19750ebfd5be226c48bb646708cf (diff)
Recognize Git repository environment variables
This makes the jgit command line behave like the C Git implementation in the respect. These variables are not recognized in the core, though we add support to do the overrides there. Hence other users of the JGit library, like the Eclipse plugin and others, will not be affected. GIT_DIR The location of the ".git" directory. GIT_WORK_TREE The location of the work tree. GIT_INDEX_FILE The location of the index file. GIT_CEILING_DIRECTORIES A colon (semicolon on Windows) separated list of paths that which JGit will not cross when looking for the .git directory. GIT_OBJECT_DIRECTORY The location of the objects directory under which objects are stored. GIT_ALTERNATE_OBJECT_DIRECTORIES A colon (semicolon on Windows) separated list of object directories to search for objects. In addition to these we support the core.worktree config setting when the git directory is set deliberately instead of being found. Change-Id: I2b9bceb13c0f66b25e9e3cefd2e01534a286e04c Signed-off-by: Robin Rosenberg <> Signed-off-by: Shawn O. Pearce <>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
1 files changed, 22 insertions, 0 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/
index 5c8935c490..ec9b1d7ac3 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/
@@ -51,6 +51,7 @@ import;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -58,6 +59,7 @@ import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
@@ -124,6 +126,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
mockSystemReader = new MockSystemReader();
mockSystemReader.userGitConfig = new FileBasedConfig(new File(trash,
+ ceilTestDirectories(getCeilings());
final long now = mockSystemReader.getCurrentTime();
@@ -142,6 +145,25 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
+ protected List<File> getCeilings() {
+ return Collections.singletonList(trash.getParentFile().getAbsoluteFile());
+ }
+ private void ceilTestDirectories(List<File> ceilings) {
+ mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, makePath(ceilings));
+ }
+ private String makePath(List<?> objects) {
+ final StringBuilder stringBuilder = new StringBuilder();
+ for (Object object : objects) {
+ if (stringBuilder.length() > 0)
+ stringBuilder.append(File.pathSeparatorChar);
+ stringBuilder.append(object.toString());
+ }
+ return stringBuilder.toString();
+ }
protected void tearDown() throws Exception {

Back to the top