summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--git/repo/base.py2
-rw-r--r--git/test/test_repo.py29
3 files changed, 31 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 34cf8cb4..bf0f5e05 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -16,5 +16,6 @@ Contributors are:
-Vincent Driessen <me _at_ nvie.com>
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
+-Timothy B. Hartman <tbhartman _at_ gmail.com>
Portions derived from other open source works and are clearly marked.
diff --git a/git/repo/base.py b/git/repo/base.py
index ace5223f..b889da71 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -135,7 +135,7 @@ class Repo(object):
# removed. It's just cleaner.
if is_git_dir(curpath):
self.git_dir = curpath
- self._working_tree_dir = os.path.dirname(self.git_dir)
+ self._working_tree_dir = os.getenv('GIT_WORK_TREE', os.path.dirname(self.git_dir))
break
sm_gitpath = find_submodule_git_dir(osp.join(curpath, '.git'))
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 9ad80ee6..5dc7bbb0 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -925,3 +925,32 @@ class TestRepo(TestBase):
raise AssertionError(ex, "It's ok if TC not running from `master`.")
self.failUnlessRaises(InvalidGitRepositoryError, Repo, worktree_path)
+
+ @with_rw_directory
+ def test_git_work_tree_env(self, rw_dir):
+ """Check that we yield to GIT_WORK_TREE"""
+ # clone a repo
+ # move .git directory to a subdirectory
+ # set GIT_DIR and GIT_WORK_TREE appropriately
+ # check that repo.working_tree_dir == rw_dir
+ git = Git(rw_dir)
+ self.rorepo.clone(join_path_native(rw_dir, 'master_repo'))
+
+ repo_dir = join_path_native(rw_dir, 'master_repo')
+ old_git_dir = join_path_native(repo_dir, '.git')
+ new_subdir = join_path_native(repo_dir, 'gitdir')
+ new_git_dir = join_path_native(new_subdir, 'git')
+ os.mkdir(new_subdir)
+ os.rename(old_git_dir, new_git_dir)
+
+ oldenv = os.environ.copy()
+ os.environ['GIT_DIR'] = new_git_dir
+ os.environ['GIT_WORK_TREE'] = repo_dir
+
+ try:
+ r = Repo()
+ self.assertEqual(r.working_tree_dir, repo_dir)
+ self.assertEqual(r.working_dir, repo_dir)
+ finally:
+ os.environ = oldenv
+