aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2023-04-21 11:02:23 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2023-04-21 11:02:23 +0300
commita339f3b4891e8e79b1c4b7145431de23b2b78d02 (patch)
treee6736df2a401069e1c87b8af5e68760c9f8292de /src
parentpkgdev bugs: Fix spelling of agent noun for 'file' (diff)
downloadpkgdev-a339f3b4891e8e79b1c4b7145431de23b2b78d02.tar.gz
pkgdev-a339f3b4891e8e79b1c4b7145431de23b2b78d02.tar.bz2
pkgdev-a339f3b4891e8e79b1c4b7145431de23b2b78d02.zip
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@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/pkgdev/git.py10
1 files 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)