Skip to content

Commit

Permalink
support gitconfig from env
Browse files Browse the repository at this point in the history
Add exceptions to the git env so externally configured gitconfig
values set via GIT_CONFIG_KEY_<n>, GIT_CONFIG_VALUE_<n> and
GIT_CONFIG_COUNT get passed through.
  • Loading branch information
emzeat authored and asottile committed Nov 23, 2021
1 parent b300116 commit 4eb91cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pre_commit/git.py
Expand Up @@ -41,9 +41,10 @@ def no_git_env(
return {
k: v for k, v in _env.items()
if not k.startswith('GIT_') or
k.startswith(('GIT_CONFIG_KEY_', 'GIT_CONFIG_VALUE_')) or
k in {
'GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND', 'GIT_SSL_CAINFO',
'GIT_SSL_NO_VERIFY',
'GIT_SSL_NO_VERIFY', 'GIT_CONFIG_COUNT',
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/git_test.py
Expand Up @@ -227,13 +227,23 @@ def test_no_git_env():
'GIT_SSH': '/usr/bin/ssh',
'GIT_SSH_COMMAND': 'ssh -o',
'GIT_DIR': '/none/shall/pass',
'GIT_CONFIG_KEY_0': 'user.name',
'GIT_CONFIG_VALUE_0': 'anthony',
'GIT_CONFIG_KEY_1': 'user.email',
'GIT_CONFIG_VALUE_1': 'asottile@example.com',
'GIT_CONFIG_COUNT': '2',
}
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',
'GIT_CONFIG_KEY_0': 'user.name',
'GIT_CONFIG_VALUE_0': 'anthony',
'GIT_CONFIG_KEY_1': 'user.email',
'GIT_CONFIG_VALUE_1': 'asottile@example.com',
'GIT_CONFIG_COUNT': '2',
}


Expand Down

0 comments on commit 4eb91cd

Please sign in to comment.