Always set .gitconfig dir to user's home

This commit is contained in:
Daniel A. Wozniak 2018-11-15 00:58:44 -07:00
parent b0446f527e
commit d3620c3356
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

View file

@ -11,6 +11,7 @@ import glob
import hashlib
import logging
import os
import pwd
import re
import shlex
import shutil
@ -1424,6 +1425,10 @@ class Pygit2(GitProvider):
will let the calling function know whether or not a new repo was
initialized by this function.
'''
# https://github.com/libgit2/pygit2/issues/339
# https://github.com/libgit2/libgit2/issues/2122
home = pwd.getpwnam(salt.utils.get_user()).pw_dir
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = home
new = False
if not os.listdir(self.cachedir):
# Repo cachedir is empty, initialize a new repo there
@ -1432,17 +1437,7 @@ class Pygit2(GitProvider):
else:
# Repo cachedir exists, try to attach
try:
try:
self.repo = pygit2.Repository(self.cachedir)
except GitError as exc:
import pwd
# https://github.com/libgit2/pygit2/issues/339
# https://github.com/libgit2/libgit2/issues/2122
if "Error stat'ing config file" not in str(exc):
raise
home = pwd.getpwnam(salt.utils.get_user()).pw_dir
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = home
self.repo = pygit2.Repository(self.cachedir)
self.repo = pygit2.Repository(self.cachedir)
except KeyError:
log.error(_INVALID_REPO.format(self.cachedir, self.url, self.role))
return new