blob: 3dbee5e9df8f53d071b235d09066e547e416a2d1 [file] [log] [blame]
Peter Pentchevb91fc932023-01-19 15:27:13 +02001# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
2# SPDX-License-Identifier: BSD-2-Clause
3"""Run git-if-needed."""
4
5from __future__ import annotations
6
7import shlex
Peter Pentchev81fa7662024-01-18 13:19:34 +02008import subprocess # noqa: S404
Peter Pentchevb91fc932023-01-19 15:27:13 +02009
10from typing import TYPE_CHECKING
11
12from . import defs
13
14if TYPE_CHECKING:
15 import pathlib
16
17
18def 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:
Peter Pentchev78ab37b2024-01-18 13:07:33 +020024 subprocess.run(cmd, check=True, cwd=tempd, shell=False) # noqa: S603
Peter Pentchevb91fc932023-01-19 15:27:13 +020025 except (OSError, subprocess.CalledProcessError) as err:
26 raise defs.GApplyError(f"Could not run `{cmdstr}` in {tempd}: {err}") from err