Coverage for src/pullapprove/git.py: 0%
26 statements
« prev ^ index » next coverage.py v7.8.2, created at 2026-03-11 17:04 -0500
« prev ^ index » next coverage.py v7.8.2, created at 2026-03-11 17:04 -0500
1import subprocess
2from collections.abc import Generator
3from pathlib import Path
6def git_root() -> Path:
7 """Return the root directory of the git repository."""
8 output = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).strip()
9 return Path(output.decode("utf-8"))
12def git_ls_files(path: Path) -> Generator[str]:
13 """Yield files in the git repository one at a time."""
14 process = subprocess.Popen(
15 [
16 "git",
17 "ls-files",
18 "--cached",
19 "--deleted",
20 "--others",
21 "--exclude-standard",
22 ],
23 cwd=path,
24 stdout=subprocess.PIPE,
25 text=True,
26 )
28 assert process.stdout is not None
29 for line in process.stdout:
30 yield line.strip()
32 process.stdout.close()
33 process.wait()
36def git_ls_changes(path: Path) -> Generator[str]:
37 process = subprocess.Popen(
38 [
39 "git",
40 "status",
41 "--porcelain=v1",
42 "--untracked-files=all",
43 ],
44 cwd=path,
45 stdout=subprocess.PIPE,
46 text=True,
47 )
49 assert process.stdout is not None
50 for line in process.stdout:
51 yield line.strip().split(" ", 1)[1]
53 process.stdout.close()
54 process.wait()
57def git_diff_stream(path: Path, *diff_args: str) -> Generator[str]:
58 process = subprocess.Popen(
59 ["git", "diff", "--no-ext-diff"] + list(diff_args),
60 cwd=path,
61 stdout=subprocess.PIPE,
62 text=True,
63 )
65 assert process.stdout is not None
66 yield from process.stdout
68 process.stdout.close()
69 process.wait()