Files
Kamino/tests/scripts/git_env.py
T
Defame1297 6c80ab7772 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
2026-12-06 19:10:56 +00:00

13 lines
502 B
Python

# 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