Skip to content

Commit

Permalink
Do not override externally set GIT_CONFIG_COUNT
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Jun 13, 2024
1 parent 0cedaf1 commit 6f3c6b1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions alibuild_helpers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 6f3c6b1

Please sign in to comment.