From 89978e1f308c66ae5975542c34248b5a145064d1 Mon Sep 17 00:00:00 2001 From: apkawa Date: Wed, 19 Apr 2023 12:14:56 +0300 Subject: [PATCH] test: fix git_sandbox for git<2.33 for old git like git-2.30 the tests broke my ~/.gitconfig file and created thousands of `name=GitHub` lines Signed-off-by: apkawa --- tests/conftest.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 25cbcbf27c..c79358209b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,9 +23,14 @@ def git_sandbox(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): monkeypatch.delenv(var) # Define a dedicated temporary git config - monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(tmp_path / "gitconfig")) - cmd.run(f"git config --global user.name {SIGNER}") - cmd.run(f"git config --global user.email {SIGNER_MAIL}") + gitconfig = tmp_path / ".git" / "config" + if not gitconfig.parent.exists(): + gitconfig.parent.mkdir() + monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(gitconfig)) + r = cmd.run(f"git config --file {gitconfig} user.name {SIGNER}") + assert r.return_code == 0, r.err + r = cmd.run(f"git config --file {gitconfig} user.email {SIGNER_MAIL}") + assert r.return_code == 0, r.err @pytest.fixture(scope="function")