Coverage for src/pullapprove/git.py: 0%
22 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-09 21:04 -0500
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-09 21:04 -0500
1import subprocess
2from pathlib import Path
5def git_root():
6 """Return the root directory of the git repository."""
7 output = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).strip()
8 return Path(output.decode("utf-8"))
11def git_ls_files(path):
12 """Yield files in the git repository one at a time."""
13 process = subprocess.Popen(
14 [
15 "git",
16 "ls-files",
17 "--cached",
18 "--deleted",
19 "--others",
20 "--exclude-standard",
21 ],
22 cwd=path,
23 stdout=subprocess.PIPE,
24 text=True,
25 )
27 for line in process.stdout:
28 yield line.strip()
30 process.stdout.close()
31 process.wait()
34def git_ls_changes(path):
35 process = subprocess.Popen(
36 [
37 "git",
38 "status",
39 "--porcelain=v1",
40 "--untracked-files=all",
41 ],
42 cwd=path,
43 stdout=subprocess.PIPE,
44 text=True,
45 )
47 for line in process.stdout:
48 yield line.strip().split(" ", 1)[1]
50 process.stdout.close()
51 process.wait()
54def git_diff_stream(path, *diff_args):
55 process = subprocess.Popen(
56 ["git", "diff", "--no-ext-diff"] + list(diff_args),
57 cwd=path,
58 stdout=subprocess.PIPE,
59 text=True,
60 )
62 yield from process.stdout
64 process.stdout.close()
65 process.wait()