mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Added test for git.no_git_env().
Signed-off-by: Brett Randall <javabrett@gmail.com>
This commit is contained in:
parent
f673f8bb55
commit
f5af95cc9d
2 changed files with 20 additions and 2 deletions
|
|
@ -18,7 +18,7 @@ def zsplit(s):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def no_git_env():
|
def no_git_env(_env=None):
|
||||||
# Too many bugs dealing with environment variables and GIT:
|
# Too many bugs dealing with environment variables and GIT:
|
||||||
# https://github.com/pre-commit/pre-commit/issues/300
|
# https://github.com/pre-commit/pre-commit/issues/300
|
||||||
# In git 2.6.3 (maybe others), git exports GIT_WORK_TREE while running
|
# In git 2.6.3 (maybe others), git exports GIT_WORK_TREE while running
|
||||||
|
|
@ -27,8 +27,9 @@ def no_git_env():
|
||||||
# while running pre-commit hooks in submodules.
|
# while running pre-commit hooks in submodules.
|
||||||
# GIT_DIR: Causes git clone to clone wrong thing
|
# GIT_DIR: Causes git clone to clone wrong thing
|
||||||
# GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
|
# GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
|
||||||
|
_env = _env if _env is not None else os.environ
|
||||||
return {
|
return {
|
||||||
k: v for k, v in os.environ.items()
|
k: v for k, v in _env.items()
|
||||||
if not k.startswith('GIT_') or
|
if not k.startswith('GIT_') or
|
||||||
k in {'GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND'}
|
k in {'GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND'}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,3 +173,20 @@ def test_status_output_with_rename(in_git_dir):
|
||||||
cmd_output('git', 'add', '--intent-to-add', 'c')
|
cmd_output('git', 'add', '--intent-to-add', 'c')
|
||||||
|
|
||||||
assert git.intent_to_add_files() == ['c']
|
assert git.intent_to_add_files() == ['c']
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_git_env():
|
||||||
|
env = {
|
||||||
|
'http_proxy': 'http://myproxy:80',
|
||||||
|
'GIT_EXEC_PATH': '/some/git/exec/path',
|
||||||
|
'GIT_SSH': '/usr/bin/ssh',
|
||||||
|
'GIT_SSH_COMMAND': 'ssh -o',
|
||||||
|
'GIT_DIR': '/none/shall/pass',
|
||||||
|
}
|
||||||
|
no_git_env = git.no_git_env(env)
|
||||||
|
assert no_git_env == {
|
||||||
|
'http_proxy': 'http://myproxy:80',
|
||||||
|
'GIT_EXEC_PATH': '/some/git/exec/path',
|
||||||
|
'GIT_SSH': '/usr/bin/ssh',
|
||||||
|
'GIT_SSH_COMMAND': 'ssh -o',
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue