From 32f89780f94cd35835cf41f63ee6b5db7d488c84 Mon Sep 17 00:00:00 2001 From: Frank Schreiner Date: Mon, 5 Aug 2024 14:53:08 +0200 Subject: [PATCH] unset git global configs git is highly configurable and esp. for the `log` command its very popular to modify the config to the users needs/preferences. Unfortunatly these settings are also active in scripted environments like tar_scm/obs_scm and can cause various errors. This patch sets the ENV VAR GIT_CONFIG_GLOBAL to /dev/null so configs in ~/.gitconfig and $XDG_CONFIG_HOME/git/config should be ignored. --- TarSCM/scm/git.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/TarSCM/scm/git.py b/TarSCM/scm/git.py index 8625f89d..b804fb54 100644 --- a/TarSCM/scm/git.py +++ b/TarSCM/scm/git.py @@ -3,6 +3,7 @@ import re import sys import shutil +import tempfile from TarSCM.scm.base import Scm from TarSCM.exceptions import GitError @@ -24,6 +25,15 @@ class Git(Scm): scm = 'git' _stash_pop_required = False partial_clone = False + temp_git_config_global = tempfile.NamedTemporaryFile(delete=False) + + def __init__(self, args, task): + super().__init__(args, task) + os.putenv('GIT_CONFIG_GLOBAL', self.temp_git_config_global.name) + + def __del__(self): + super().__del__() + os.unlink(self.temp_git_config_global.name) def _get_scm_cmd(self): """Compose a GIT-specific command line using http proxies""" @@ -228,7 +238,9 @@ def update_cache(self): self.auth_url() try: self.helpers.safe_run( - self._get_scm_cmd() + ['config', 'remote.origin.url', + self._get_scm_cmd() + ['config', + '--local', + 'remote.origin.url', self.url], cwd=self.clone_dir, interactive=sys.stdout.isatty()