Skip to content

Commit d3bd3c6

Browse files
committed
Merge branch 'git_work_tree' of https://github.com/tbhartman/GitPython into tbhartman-git_work_tree
2 parents 416daa0 + 8dfa168 commit d3bd3c6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ Contributors are:
1616
-Vincent Driessen <me _at_ nvie.com>
1717
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
1818
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
19+
-Timothy B. Hartman <tbhartman _at_ gmail.com>
1920

2021
Portions derived from other open source works and are clearly marked.

git/repo/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
135135
# removed. It's just cleaner.
136136
if is_git_dir(curpath):
137137
self.git_dir = curpath
138-
self._working_tree_dir = os.path.dirname(self.git_dir)
138+
self._working_tree_dir = os.getenv('GIT_WORK_TREE', os.path.dirname(self.git_dir))
139139
break
140140

141141
sm_gitpath = find_submodule_git_dir(osp.join(curpath, '.git'))

git/test/test_repo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,32 @@ def test_work_tree_unsupported(self, rw_dir):
925925
raise AssertionError(ex, "It's ok if TC not running from `master`.")
926926

927927
self.failUnlessRaises(InvalidGitRepositoryError, Repo, worktree_path)
928+
929+
@with_rw_directory
930+
def test_git_work_tree_env(self, rw_dir):
931+
"""Check that we yield to GIT_WORK_TREE"""
932+
# clone a repo
933+
# move .git directory to a subdirectory
934+
# set GIT_DIR and GIT_WORK_TREE appropriately
935+
# check that repo.working_tree_dir == rw_dir
936+
git = Git(rw_dir)
937+
self.rorepo.clone(join_path_native(rw_dir, 'master_repo'))
938+
939+
repo_dir = join_path_native(rw_dir, 'master_repo')
940+
old_git_dir = join_path_native(repo_dir, '.git')
941+
new_subdir = join_path_native(repo_dir, 'gitdir')
942+
new_git_dir = join_path_native(new_subdir, 'git')
943+
os.mkdir(new_subdir)
944+
os.rename(old_git_dir, new_git_dir)
945+
946+
oldenv = os.environ.copy()
947+
os.environ['GIT_DIR'] = new_git_dir
948+
os.environ['GIT_WORK_TREE'] = repo_dir
949+
950+
try:
951+
r = Repo()
952+
self.assertEqual(r.working_tree_dir, repo_dir)
953+
self.assertEqual(r.working_dir, repo_dir)
954+
finally:
955+
os.environ = oldenv
956+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy