Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failed to stat '/root/.gitconfig' issue on gitfs (bsc#1230944) (bsc#1234881) #699

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/64121.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure the right HOME environment value is set during Pygit2 remote initialization.
9 changes: 5 additions & 4 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,12 @@ def init_remote(self):
"""
# https://github.com/libgit2/pygit2/issues/339
# https://github.com/libgit2/libgit2/issues/2122
# https://github.com/saltstack/salt/issues/64121
home = os.path.expanduser("~")
if "HOME" not in os.environ:
# Make sure $HOME env variable is set to prevent
# _pygit2.GitError: error loading known_hosts in some libgit2 versions.
os.environ["HOME"] = home
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = home
new = False
if not os.listdir(self._cachedir):
Expand Down Expand Up @@ -1990,10 +1995,6 @@ def _fetch(self):
# pruning only available in pygit2 >= 0.26.2
pass
try:
# Make sure $HOME env variable is set to prevent
# _pygit2.GitError: error loading known_hosts in some libgit2 versions.
if "HOME" not in os.environ:
os.environ["HOME"] = salt.syspaths.HOME_DIR
fetch_results = origin.fetch(**fetch_kwargs)
except GitError as exc: # pylint: disable=broad-except
exc_str = get_error_message(exc).lower()
Expand Down
1 change: 0 additions & 1 deletion tests/pytests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def test_checkout_pygit2_with_home_env_unset(_prepare_provider):
with patched_environ(__cleanup__=["HOME"]):
assert "HOME" not in os.environ
provider.init_remote()
provider.fetch()
assert "HOME" in os.environ


Expand Down
Loading