Skip to content

Commit 4eb91cd

Browse files
emzeatasottile
authored andcommitted
support gitconfig from env
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.
1 parent b300116 commit 4eb91cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pre_commit/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ def no_git_env(
4141
return {
4242
k: v for k, v in _env.items()
4343
if not k.startswith('GIT_') or
44+
k.startswith(('GIT_CONFIG_KEY_', 'GIT_CONFIG_VALUE_')) or
4445
k in {
4546
'GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND', 'GIT_SSL_CAINFO',
46-
'GIT_SSL_NO_VERIFY',
47+
'GIT_SSL_NO_VERIFY', 'GIT_CONFIG_COUNT',
4748
}
4849
}
4950

tests/git_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,23 @@ def test_no_git_env():
227227
'GIT_SSH': '/usr/bin/ssh',
228228
'GIT_SSH_COMMAND': 'ssh -o',
229229
'GIT_DIR': '/none/shall/pass',
230+
'GIT_CONFIG_KEY_0': 'user.name',
231+
'GIT_CONFIG_VALUE_0': 'anthony',
232+
'GIT_CONFIG_KEY_1': 'user.email',
233+
'GIT_CONFIG_VALUE_1': 'asottile@example.com',
234+
'GIT_CONFIG_COUNT': '2',
230235
}
231236
no_git_env = git.no_git_env(env)
232237
assert no_git_env == {
233238
'http_proxy': 'http://myproxy:80',
234239
'GIT_EXEC_PATH': '/some/git/exec/path',
235240
'GIT_SSH': '/usr/bin/ssh',
236241
'GIT_SSH_COMMAND': 'ssh -o',
242+
'GIT_CONFIG_KEY_0': 'user.name',
243+
'GIT_CONFIG_VALUE_0': 'anthony',
244+
'GIT_CONFIG_KEY_1': 'user.email',
245+
'GIT_CONFIG_VALUE_1': 'asottile@example.com',
246+
'GIT_CONFIG_COUNT': '2',
237247
}
238248

239249

0 commit comments

Comments
 (0)