commit: a339f3b4891e8e79b1c4b7145431de23b2b78d02 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Fri Apr 21 08:02:23 2023 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Fri Apr 21 08:02:23 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=a339f3b4
git: declare PKGDEV=1 env for git commands Can be used in git hooks to verify if we are running inside a pkgdev call. Resolves: https://github.com/pkgcore/pkgdev/issues/133 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgdev/git.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pkgdev/git.py b/src/pkgdev/git.py index cc96716..55e1fae 100644 --- a/src/pkgdev/git.py +++ b/src/pkgdev/git.py @@ -1,3 +1,4 @@ +import os import subprocess import sys @@ -12,6 +13,7 @@ def run(*args, **kwargs): """Wrapper for running git via subprocess.run().""" kwargs.setdefault("check", True) kwargs.setdefault("text", True) + kwargs.setdefault("env", os.environ.copy())["PKGDEV"] = "1" cmd = ["git"] + list(args) # output git command that would be run to stderr @@ -21,7 +23,7 @@ def run(*args, **kwargs): try: return subprocess.run(cmd, **kwargs) - except FileNotFoundError as e: - raise UserException(str(e)) - except subprocess.CalledProcessError as e: - raise GitError(e.returncode) + except FileNotFoundError as exc: + raise UserException(str(exc)) + except subprocess.CalledProcessError as exc: + raise GitError(exc.returncode)
