aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2009-12-09 09:54:08 +0100
committerShawn O. Pearce <spearce@spearce.org>2009-12-28 15:58:47 -0800
commiteb63bfc1b82ce21516b211df45069cbea87b7eee (patch)
treedc8e63302d0eadcedacb933bfda2d8ebc5b46d90 /org.eclipse.jgit.test
parent5b13adcea97c19750ebfd5be226c48bb646708cf (diff)
downloadjgit-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.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java157
1 files changed, 156 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
index d1dfdf4fae..e29e9e7214 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
- * Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2007-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
@@ -78,6 +78,161 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals(23, HEAD.length());
}
+ public void test000_openRepoBadArgs() throws IOException {
+ try {
+ new Repository(null, null);
+ fail("Must pass either GIT_DIR or GIT_WORK_TREE");
+ } catch (IllegalArgumentException e) {
+ assertEquals(
+ "Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor",
+ e.getMessage());
+ }
+ }
+
+ /**
+ * Check the default rules for looking up directories and files within a
+ * repo when the gitDir is given.
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_default_gitDirSet() throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(theDir, null);
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(repo1Parent, r.getWorkDir());
+ assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+ assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
+ }
+
+ /**
+ * Check that we can pass both a git directory and a work tree
+ * repo when the gitDir is given.
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(theDir, repo1Parent.getParentFile());
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(repo1Parent.getParentFile(), r.getWorkDir());
+ assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+ assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
+ }
+
+ /**
+ * Check the default rules for looking up directories and files within a
+ * repo when the workTree is given.
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_default_workDirSet() throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(null, repo1Parent);
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(repo1Parent, r.getWorkDir());
+ assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+ assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
+ }
+
+ /**
+ * Check that worktree config has an effect, given absolute path.
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_default_absolute_workdirconfig()
+ throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ File workdir = new File(trash.getParentFile(), "rw");
+ workdir.mkdir();
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.getConfig().setString("core", null, "worktree",
+ workdir.getAbsolutePath());
+ repo1initial.getConfig().save();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(theDir, null);
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(workdir, r.getWorkDir());
+ assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+ assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
+ }
+
+ /**
+ * Check that worktree config has an effect, given a relative path.
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_default_relative_workdirconfig()
+ throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ File workdir = new File(trash.getParentFile(), "rw");
+ workdir.mkdir();
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.getConfig()
+ .setString("core", null, "worktree", "../../rw");
+ repo1initial.getConfig().save();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(theDir, null);
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(workdir, r.getWorkDir());
+ assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+ assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
+ }
+
+ /**
+ * Check that the given index file is honored and the alternate object
+ * directories too
+ *
+ * @throws IOException
+ */
+ public void test000_openrepo_alternate_index_file_and_objdirs()
+ throws IOException {
+ File repo1Parent = new File(trash.getParentFile(), "r1");
+ File indexFile = new File(trash, "idx");
+ File objDir = new File(trash, "../obj");
+ File[] altObjDirs = new File[] { db.getObjectsDirectory() };
+ Repository repo1initial = new Repository(new File(repo1Parent, ".git"));
+ repo1initial.create();
+ repo1initial.close();
+
+ File theDir = new File(repo1Parent, ".git");
+ Repository r = new Repository(theDir, null, objDir, altObjDirs,
+ indexFile);
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(theDir.getParentFile(), r.getWorkDir());
+ assertEqualsPath(indexFile, r.getIndexFile());
+ assertEqualsPath(objDir, r.getObjectsDirectory());
+ assertNotNull(r.mapCommit("6db9c2ebf75590eef973081736730a9ea169a0c4"));
+ // Must close or the default repo pack files created by this test gets
+ // locked via the alternate object directories on Windows.
+ r.close();
+ }
+
+ protected void assertEqualsPath(File expected, File actual)
+ throws IOException {
+ assertEquals(expected.getCanonicalPath(), actual.getCanonicalPath());
+ }
+
public void test002_WriteEmptyTree() throws IOException {
// One of our test packs contains the empty tree object. If the pack is
// open when we create it we won't write the object file out as a loose