Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8dfa168

Browse files
committed
check for GIT_WORK_TREE
1 parentb197de0 commit8dfa168

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
@@ -133,7 +133,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
133133
# removed. It's just cleaner.
134134
ifis_git_dir(curpath):
135135
self.git_dir=curpath
136-
self._working_tree_dir=os.path.dirname(self.git_dir)
136+
self._working_tree_dir=os.getenv('GIT_WORK_TREE',os.path.dirname(self.git_dir))
137137
break
138138

139139
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
raiseAssertionError(ex,"It's ok if TC not running from `master`.")
926926

927927
self.failUnlessRaises(InvalidGitRepositoryError,Repo,worktree_path)
928+
929+
@with_rw_directory
930+
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp