Skip to content

Commit a339f3b

Browse files
committed
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: #133 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 43aa314 commit a339f3b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/pkgdev/git.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import subprocess
23
import sys
34

@@ -12,6 +13,7 @@ def run(*args, **kwargs):
1213
"""Wrapper for running git via subprocess.run()."""
1314
kwargs.setdefault("check", True)
1415
kwargs.setdefault("text", True)
16+
kwargs.setdefault("env", os.environ.copy())["PKGDEV"] = "1"
1517
cmd = ["git"] + list(args)
1618

1719
# output git command that would be run to stderr
@@ -21,7 +23,7 @@ def run(*args, **kwargs):
2123

2224
try:
2325
return subprocess.run(cmd, **kwargs)
24-
except FileNotFoundError as e:
25-
raise UserException(str(e))
26-
except subprocess.CalledProcessError as e:
27-
raise GitError(e.returncode)
26+
except FileNotFoundError as exc:
27+
raise UserException(str(exc))
28+
except subprocess.CalledProcessError as exc:
29+
raise GitError(exc.returncode)

0 commit comments

Comments
 (0)