diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2009-12-09 09:54:08 +0100 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2009-12-28 15:58:47 -0800 |
commit | eb63bfc1b82ce21516b211df45069cbea87b7eee (patch) | |
tree | dc8e63302d0eadcedacb933bfda2d8ebc5b46d90 /org.eclipse.jgit.pgm | |
parent | 5b13adcea97c19750ebfd5be226c48bb646708cf (diff) | |
download | jgit-eb63bfc1b82ce21516b211df45069cbea87b7eee.tar.gz jgit-eb63bfc1b82ce21516b211df45069cbea87b7eee.zip |
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 <robin.rosenberg@dewire.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 18cf8be467..b4c5660a6d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -49,15 +49,20 @@ import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.eclipse.jgit.awtui.AwtAuthenticator; import org.eclipse.jgit.awtui.AwtSshSessionFactory; import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.pgm.opt.SubcommandHandler; import org.eclipse.jgit.util.CachedAuthenticator; +import org.eclipse.jgit.util.SystemReader; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.ExampleMode; @@ -158,13 +163,50 @@ public class Main { final TextBuiltin cmd = subcommand; if (cmd.requiresRepository()) { + if (gitdir == null) { + String gitDirEnv = SystemReader.getInstance().getenv(Constants.GIT_DIR_KEY); + if (gitDirEnv != null) + gitdir = new File(gitDirEnv); + } if (gitdir == null) gitdir = findGitDir(); + + File gitworktree; + String gitWorkTreeEnv = SystemReader.getInstance().getenv(Constants.GIT_WORK_TREE_KEY); + if (gitWorkTreeEnv != null) + gitworktree = new File(gitWorkTreeEnv); + else + gitworktree = null; + + File indexfile; + String indexFileEnv = SystemReader.getInstance().getenv(Constants.GIT_INDEX_KEY); + if (indexFileEnv != null) + indexfile = new File(indexFileEnv); + else + indexfile = null; + + File objectdir; + String objectDirEnv = SystemReader.getInstance().getenv(Constants.GIT_OBJECT_DIRECTORY_KEY); + if (objectDirEnv != null) + objectdir = new File(objectDirEnv); + else + objectdir = null; + + File[] altobjectdirs; + String altObjectDirEnv = SystemReader.getInstance().getenv(Constants.GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY); + if (altObjectDirEnv != null) { + String[] parserdAltObjectDirEnv = altObjectDirEnv.split(File.pathSeparator); + altobjectdirs = new File[parserdAltObjectDirEnv.length]; + for (int i = 0; i < parserdAltObjectDirEnv.length; i++) + altobjectdirs[i] = new File(parserdAltObjectDirEnv[i]); + } else + altobjectdirs = null; + if (gitdir == null || !gitdir.isDirectory()) { System.err.println("error: can't find git directory"); System.exit(1); } - cmd.init(new Repository(gitdir), gitdir); + cmd.init(new Repository(gitdir, gitworktree, objectdir, altobjectdirs, indexfile), gitdir); } else { cmd.init(null, gitdir); } @@ -177,12 +219,21 @@ public class Main { } private static File findGitDir() { - File current = new File(".").getAbsoluteFile(); + Set<String> ceilingDirectories = new HashSet<String>(); + String ceilingDirectoriesVar = SystemReader.getInstance().getenv( + Constants.GIT_CEILING_DIRECTORIES_KEY); + if (ceilingDirectoriesVar != null) { + ceilingDirectories.addAll(Arrays.asList(ceilingDirectoriesVar + .split(File.pathSeparator))); + } + File current = new File("").getAbsoluteFile(); while (current != null) { final File gitDir = new File(current, ".git"); if (gitDir.isDirectory()) return gitDir; current = current.getParentFile(); + if (ceilingDirectories.contains(current.getPath())) + break; } return null; } |