summaryrefslogtreecommitdiff
path: root/git/test/test_repo.py
diff options
context:
space:
mode:
authorTimothy B. Hartman <tbhartman@gmail.com>2017-02-24 13:39:49 -0500
committerTimothy B. Hartman <tbhartman@gmail.com>2017-02-24 14:32:25 -0500
commit8dfa1685aac22a83ba1f60d1b2d52abf5a3d842f (patch)
tree69402c2eb610c60daf989aa5669c06e9b1affbcb /git/test/test_repo.py
parentb197de0ccc0faf8b4b3da77a46750f39bf7acdb3 (diff)
downloadgitpython-8dfa1685aac22a83ba1f60d1b2d52abf5a3d842f.tar.gz
check for GIT_WORK_TREE
Diffstat (limited to 'git/test/test_repo.py')
-rw-r--r--git/test/test_repo.py29
1 files changed, 29 insertions, 0 deletions
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
+