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
@@ -17,6 +17,7 @@ import yaml
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(REPO / "scripts"))
|
||||
import git_env
|
||||
import select_molecule_scenarios as sel
|
||||
|
||||
ROLE_KEYS = {
|
||||
@@ -409,9 +410,6 @@ class MainTest(unittest.TestCase):
|
||||
(d / "molecule.yml").write_text("---\n")
|
||||
|
||||
def git(self, root, *args):
|
||||
# No GIT_* from the caller (a hook exports GIT_DIR), no user or system config.
|
||||
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")
|
||||
subprocess.run(
|
||||
[
|
||||
"git",
|
||||
@@ -427,7 +425,7 @@ class MainTest(unittest.TestCase):
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
env=env,
|
||||
env=git_env.isolated(),
|
||||
)
|
||||
|
||||
def topic_repo(self, root, files):
|
||||
|
||||
Reference in new issue
Block a user