Skip to content

Commit cc3ca2e

Browse files
committed
refactor: Explicit checks for subprocess runs
1 parent c7bd4ce commit cc3ca2e

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/griffe/git.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def _get_latest_tag(path: str | Path) -> str:
5757
text=True,
5858
stdout=subprocess.PIPE,
5959
stderr=subprocess.STDOUT,
60+
check=False,
6061
)
6162
output = process.stdout.strip()
6263
if process.returncode != 0 or not output:
@@ -99,16 +100,17 @@ def _tmp_worktree(repo: str | Path = ".", ref: str = "HEAD") -> Iterator[Path]:
99100
process = subprocess.run(
100101
["git", "-C", repo, "worktree", "add", "-b", branch, location, ref],
101102
capture_output=True,
103+
check=False,
102104
)
103105
if process.returncode:
104106
raise RuntimeError(f"Could not create git worktree: {process.stderr.decode()}")
105107

106108
try:
107109
yield Path(location)
108110
finally:
109-
subprocess.run(["git", "-C", repo, "worktree", "remove", branch], stdout=subprocess.DEVNULL)
110-
subprocess.run(["git", "-C", repo, "worktree", "prune"], stdout=subprocess.DEVNULL)
111-
subprocess.run(["git", "-C", repo, "branch", "-D", branch], stdout=subprocess.DEVNULL)
111+
subprocess.run(["git", "-C", repo, "worktree", "remove", branch], stdout=subprocess.DEVNULL, check=False)
112+
subprocess.run(["git", "-C", repo, "worktree", "prune"], stdout=subprocess.DEVNULL, check=False)
113+
subprocess.run(["git", "-C", repo, "branch", "-D", branch], stdout=subprocess.DEVNULL, check=False)
112114

113115

114116
def load_git(

tests/test_git.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def git_repo(tmp_path: Path) -> Path:
5959
"""
6060
repo_path = tmp_path / REPO_NAME
6161
repo_path.mkdir()
62-
run(["git", "-C", str(repo_path), "init"])
63-
run(["git", "-C", str(repo_path), "config", "user.name", "Name"])
64-
run(["git", "-C", str(repo_path), "config", "user.email", "my@email.com"])
62+
run(["git", "-C", str(repo_path), "init"], check=True)
63+
run(["git", "-C", str(repo_path), "config", "user.name", "Name"], check=True)
64+
run(["git", "-C", str(repo_path), "config", "user.email", "my@email.com"], check=True)
6565
for tagdir in REPO_SOURCE.iterdir():
6666
ver = tagdir.name
6767
_copy_contents(tagdir, repo_path)
68-
run(["git", "-C", str(repo_path), "add", "."])
69-
run(["git", "-C", str(repo_path), "commit", "-m", f"feat: {ver} stuff"])
70-
run(["git", "-C", str(repo_path), "tag", ver])
68+
run(["git", "-C", str(repo_path), "add", "."], check=True)
69+
run(["git", "-C", str(repo_path), "commit", "-m", f"feat: {ver} stuff"], check=True)
70+
run(["git", "-C", str(repo_path), "tag", ver], check=True)
7171
return repo_path
7272

7373

0 commit comments

Comments
 (0)