test(scripts): keep git fixtures off the caller's GIT_* variables
A git hook exports GIT_DIR (and often GIT_INDEX_FILE). A fixture that passes the caller's environment to git would run its init, add and commit against this repository instead of its temporary one once the suite runs as a hook. tests/scripts/git_env.py gives each fixture a copy of the environment without any GIT_* key and with no user or system config. The bot pull request gate's repository tests also isolate os.environ, because the gate runs git in-process. Refs: #187 Assisted-by: Claude Code
This commit is contained in:
1 parent
d6037df6e4
commit
6c80ab7772
5 files changed
+29
-17
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""The environment for a test's git fixture: no caller GIT_* and no user or system config."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def isolated(**extra):
|
||||
"""A copy of os.environ for git: a hook exports GIT_DIR, which would point it at the real repo."""
|
||||
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")}
|
||||
env.update(GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1", **extra)
|
||||
return env
|
||||
Reference in new issue
Block a user