|
18 | 18 | from typing import IO |
19 | 19 | from xml.etree import ElementTree as ET |
20 | 20 |
|
| 21 | +from . import git |
21 | 22 | from .allow import AllowedFeatures |
22 | 23 | from .builddir import Builddir |
23 | 24 | from .errors import NixpkgsReviewError |
@@ -276,41 +277,36 @@ def _display_pr_info(self, pr: dict, pr_number: int) -> None: |
276 | 277 | print(f"{'=' * 80}\n") |
277 | 278 |
|
278 | 279 | def git_merge(self, commit: str) -> None: |
279 | | - res = sh( |
280 | | - ["git", "merge", "--no-commit", "--no-ff", commit], cwd=self.worktree_dir() |
| 280 | + res = git.run( |
| 281 | + ["merge", "--no-commit", "--no-ff", commit], cwd=self.worktree_dir() |
281 | 282 | ) |
282 | 283 | if res.returncode != 0: |
283 | 284 | msg = f"Failed to merge {commit} into {self.worktree_dir()}. git merge failed with exit code {res.returncode}" |
284 | 285 | raise NixpkgsReviewError(msg) |
285 | 286 |
|
286 | 287 | def git_checkout(self, commit: str) -> None: |
287 | | - res = sh(["git", "checkout", commit], cwd=self.worktree_dir()) |
| 288 | + res = git.run(["checkout", commit], cwd=self.worktree_dir()) |
288 | 289 | if res.returncode != 0: |
289 | 290 | msg = f"Failed to checkout {commit} in {self.worktree_dir()}. git checkout failed with exit code {res.returncode}" |
290 | 291 | raise NixpkgsReviewError(msg) |
291 | 292 |
|
292 | 293 | def apply_unstaged(self, staged: bool = False) -> None: |
293 | 294 | args = [ |
294 | | - "git", |
295 | 295 | "--no-pager", |
296 | 296 | "diff", |
297 | 297 | "--no-ext-diff", |
298 | 298 | "--src-prefix=a/", |
299 | 299 | "--dst-prefix=b/", |
300 | 300 | ] |
301 | 301 | args.extend(["--staged"] if staged else []) |
302 | | - with subprocess.Popen(args, stdout=subprocess.PIPE) as diff_proc: |
303 | | - assert diff_proc.stdout |
304 | | - diff = diff_proc.stdout.read() |
| 302 | + diff = git.run(args, stdout=subprocess.PIPE).stdout |
305 | 303 |
|
306 | 304 | if not diff: |
307 | 305 | info("No diff detected, stopping review...") |
308 | 306 | sys.exit(0) |
309 | 307 |
|
310 | 308 | info("Applying `nixpkgs` diff...") |
311 | | - result = subprocess.run( |
312 | | - ["git", "apply"], cwd=self.worktree_dir(), input=diff, check=False |
313 | | - ) |
| 309 | + result = git.run(["apply"], cwd=self.worktree_dir(), stdin=diff) |
314 | 310 |
|
315 | 311 | if result.returncode != 0: |
316 | 312 | warn(f"Failed to apply diff in {self.worktree_dir()}") |
@@ -386,7 +382,7 @@ def build_commit( |
386 | 382 | return self.build(changed_attrs, self.build_args) |
387 | 383 |
|
388 | 384 | def git_worktree(self, commit: str) -> None: |
389 | | - res = sh(["git", "worktree", "add", self.worktree_dir(), commit]) |
| 385 | + res = git.run(["worktree", "add", self.worktree_dir(), commit]) |
390 | 386 | if res.returncode != 0: |
391 | 387 | msg = f"Failed to add worktree for {commit} in {self.worktree_dir()}. git worktree failed with exit code {res.returncode}" |
392 | 388 | raise NixpkgsReviewError(msg) |
|
0 commit comments