From 6f3c6b1ea4c0ac147b3a08e2adb81ba56816fdcd Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:59:28 +0200 Subject: [PATCH] Do not override externally set GIT_CONFIG_COUNT --- alibuild_helpers/git.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/alibuild_helpers/git.py b/alibuild_helpers/git.py index 6ed86db9..a2ce6fb5 100644 --- a/alibuild_helpers/git.py +++ b/alibuild_helpers/git.py @@ -2,6 +2,7 @@ from alibuild_helpers.cmd import getstatusoutput from alibuild_helpers.log import debug from alibuild_helpers.scm import SCM, SCMError +import os GIT_COMMAND_TIMEOUT_SEC = 120 """How many seconds to let any git command execute before being terminated.""" @@ -75,6 +76,7 @@ def checkUntracked(self, line): def git(args, directory=".", check=True, prompt=True): + lastGitOverride = int(os.environ.get("GIT_CONFIG_COUNT", "0")) debug("Executing git %s (in directory %s)", " ".join(args), directory) # We can't use git --git-dir=%s/.git or git -C %s here as the former requires # that the directory we're inspecting to be the root of a git directory, not @@ -89,8 +91,8 @@ def git(args, directory=".", check=True, prompt=True): directory=quote(directory), args=" ".join(map(quote, args)), # GIT_TERMINAL_PROMPT is only supported in git 2.3+. - prompt_var="GIT_TERMINAL_PROMPT=0" if not prompt else "", - directory_safe_var="GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0=$PWD" if directory else "", + prompt_var=f"GIT_TERMINAL_PROMPT=0" if not prompt else "", + directory_safe_var=f"GIT_CONFIG_COUNT={lastGitOverride+1} GIT_CONFIG_KEY_{lastGitOverride}=safe.directory GIT_CONFIG_VALUE_{lastGitOverride}=$PWD" if directory else "", ), timeout=GIT_COMMAND_TIMEOUT_SEC) if check and err != 0: raise SCMError("Error {} from git {}: {}".format(err, " ".join(args), output))