From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BAB2115ACFB for ; Fri, 21 Apr 2023 08:03:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 02EE3E08DB; Fri, 21 Apr 2023 08:03:23 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E11C0E08DB for ; Fri, 21 Apr 2023 08:03:22 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A7A8934114C for ; Fri, 21 Apr 2023 08:03:21 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 63928141 for ; Fri, 21 Apr 2023 08:03:19 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1682064143.a339f3b4891e8e79b1c4b7145431de23b2b78d02.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/ X-VCS-Repository: proj/pkgcore/pkgdev X-VCS-Files: src/pkgdev/git.py X-VCS-Directories: src/pkgdev/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: a339f3b4891e8e79b1c4b7145431de23b2b78d02 X-VCS-Branch: main Date: Fri, 21 Apr 2023 08:03:19 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 3087e07d-a18a-4898-9449-cd4b6d37a5a0 X-Archives-Hash: f598464287991d26f84c27909a45a469 commit: a339f3b4891e8e79b1c4b7145431de23b2b78d02 Author: Arthur Zamarin gentoo org> AuthorDate: Fri Apr 21 08:02:23 2023 +0000 Commit: Arthur Zamarin gentoo 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 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)