Skip to content

Commit c9781ea

Browse files
Make git commands more robust
1 parent 0a201c0 commit c9781ea

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tests/integration/conftest.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import pathlib
5+
import shutil
56
import subprocess
67
import uuid
78

@@ -50,16 +51,22 @@ def _(*variables):
5051

5152

5253
@pytest.fixture
53-
def commit(integration_dir):
54+
def git():
55+
return shutil.which("git")
56+
57+
58+
@pytest.fixture
59+
def commit(integration_dir, git):
5460
def _():
5561
subprocess.check_call(
56-
["git", "add", "."],
62+
[git, "add", "."],
5763
cwd=integration_dir,
5864
)
5965
subprocess.check_call(
60-
["git", "commit", "-m", str(uuid.uuid4())],
66+
[git, "commit", "-m", str(uuid.uuid4())],
6167
cwd=integration_dir,
62-
env={
68+
env=os.environ
69+
| {
6370
"GIT_AUTHOR_NAME": "foo",
6471
"GIT_AUTHOR_EMAIL": "foo",
6572
"GIT_COMMITTER_NAME": "foo",
@@ -73,27 +80,27 @@ def _():
7380

7481

7582
@pytest.fixture
76-
def integration_env(integration_dir, write_file, run_coverage, commit, request):
77-
subprocess.check_call(["git", "init", "-b", "main"], cwd=integration_dir)
83+
def integration_env(integration_dir, write_file, run_coverage, commit, request, git):
84+
subprocess.check_call([git, "init", "-b", "main"], cwd=integration_dir)
7885
# diff coverage reads the "origin/{...}" branch so we simulate an origin remote
79-
subprocess.check_call(["git", "remote", "add", "origin", "."], cwd=integration_dir)
86+
subprocess.check_call([git, "remote", "add", "origin", "."], cwd=integration_dir)
8087
write_file("A", "B")
8188
commit()
8289

8390
add_branch_mark = request.node.get_closest_marker("add_branches")
8491
for additional_branch in add_branch_mark.args if add_branch_mark else []:
8592
subprocess.check_call(
86-
["git", "switch", "-c", additional_branch],
93+
[git, "switch", "-c", additional_branch],
8794
cwd=integration_dir,
8895
)
8996

9097
subprocess.check_call(
91-
["git", "switch", "-c", "branch"],
98+
[git, "switch", "-c", "branch"],
9299
cwd=integration_dir,
93100
)
94101

95102
write_file("A", "B", "C", "D")
96103
commit()
97104

98105
run_coverage("A", "C")
99-
subprocess.check_call(["git", "fetch", "origin"], cwd=integration_dir)
106+
subprocess.check_call([git, "fetch", "origin"], cwd=integration_dir)

0 commit comments

Comments
 (0)