File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def zsplit(s):
1818 return []
1919
2020
21- def no_git_env ():
21+ def no_git_env (_env = None ):
2222 # Too many bugs dealing with environment variables and GIT:
2323 # https://github.com/pre-commit/pre-commit/issues/300
2424 # In git 2.6.3 (maybe others), git exports GIT_WORK_TREE while running
@@ -27,8 +27,9 @@ def no_git_env():
2727 # while running pre-commit hooks in submodules.
2828 # GIT_DIR: Causes git clone to clone wrong thing
2929 # GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
30+ _env = _env if _env is not None else os .environ
3031 return {
31- k : v for k , v in os . environ .items ()
32+ k : v for k , v in _env .items ()
3233 if not k .startswith ('GIT_' ) or
3334 k in {'GIT_EXEC_PATH' , 'GIT_SSH' , 'GIT_SSH_COMMAND' }
3435 }
Original file line number Diff line number Diff line change @@ -173,3 +173,20 @@ def test_status_output_with_rename(in_git_dir):
173173 cmd_output ('git' , 'add' , '--intent-to-add' , 'c' )
174174
175175 assert git .intent_to_add_files () == ['c' ]
176+
177+
178+ def test_no_git_env ():
179+ env = {
180+ 'http_proxy' : 'http://myproxy:80' ,
181+ 'GIT_EXEC_PATH' : '/some/git/exec/path' ,
182+ 'GIT_SSH' : '/usr/bin/ssh' ,
183+ 'GIT_SSH_COMMAND' : 'ssh -o' ,
184+ 'GIT_DIR' : '/none/shall/pass' ,
185+ }
186+ no_git_env = git .no_git_env (env )
187+ assert no_git_env == {
188+ 'http_proxy' : 'http://myproxy:80' ,
189+ 'GIT_EXEC_PATH' : '/some/git/exec/path' ,
190+ 'GIT_SSH' : '/usr/bin/ssh' ,
191+ 'GIT_SSH_COMMAND' : 'ssh -o' ,
192+ }
You can’t perform that action at this time.
0 commit comments