Skip to content

Commit

Permalink
unset git global configs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
M0ses committed Aug 5, 2024
1 parent 0a2955f commit 32f8978
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion TarSCM/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import sys
import shutil
import tempfile

from TarSCM.scm.base import Scm
from TarSCM.exceptions import GitError
Expand All @@ -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"""
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 32f8978

Please sign in to comment.