Peter Pentchev | b91fc93 | 2023-01-19 15:27:13 +0200 | [diff] [blame^] | 1 | # SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net> |
| 2 | # SPDX-License-Identifier: BSD-2-Clause |
| 3 | """Run git-if-needed.""" |
| 4 | |
| 5 | from __future__ import annotations |
| 6 | |
| 7 | import shlex |
| 8 | import subprocess |
| 9 | |
| 10 | from typing import TYPE_CHECKING |
| 11 | |
| 12 | from . import defs |
| 13 | |
| 14 | if TYPE_CHECKING: |
| 15 | import pathlib |
| 16 | |
| 17 | |
| 18 | def apply_series(cfg: defs.Config, tempd: pathlib.Path) -> None: |
| 19 | """Run git-if-needed to apply all the patches in a series file.""" |
| 20 | cmd: list[str | pathlib.Path] = [cfg.program, "-s", cfg.series, "--", "am"] |
| 21 | cmdstr = shlex.join(str(arg) for arg in cmd) |
| 22 | cfg.log.debug("Running `%(cmdstr)s`", {"cmdstr": cmdstr}) |
| 23 | try: |
| 24 | subprocess.run(cmd, check=True, cwd=tempd, shell=False) |
| 25 | except (OSError, subprocess.CalledProcessError) as err: |
| 26 | raise defs.GApplyError(f"Could not run `{cmdstr}` in {tempd}: {err}") from err |