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:
Defame1297 committed 2026-12-06 19:10:56 +00:00
1 parent d6037df6e4
commit 6c80ab7772
5 files changed
+29 -17

No files matched your search

@@ -14,6 +14,7 @@ import sys
import tempfile
import unittest
import git_env
import yaml
REPO = pathlib.Path(__file__).resolve().parents[2]
@@ -44,7 +45,11 @@ class CheckScenariosLoadCheckoutTest(unittest.TestCase):
self.checkout = collection(self.ac_root)
(self.checkout / "scripts").mkdir()
# molecule's CLI finds the base config from the repository root, as in the real checkout
subprocess.run(["git", "init", "-q", str(self.checkout)], check=True)
subprocess.run(
["git", "init", "-q", str(self.checkout)],
check=True,
env=git_env.isolated(),
)
self.base_config = self.checkout / ".config" / "molecule" / "config.yml"
self.base_config.parent.mkdir(parents=True)
self.base_config.write_text("prerun: false\n")