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

Ensure the right HOME environment value is set during Pygit2 remote initialization #67186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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.
5 changes: 5 additions & 0 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,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
15 changes: 15 additions & 0 deletions tests/pytests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import salt.fileserver.gitfs
import salt.utils.gitfs
from salt.exceptions import FileserverConfigError
from tests.support.helpers import patched_environ
from tests.support.mock import MagicMock, patch

try:
Expand Down Expand Up @@ -239,6 +240,20 @@ def test_checkout_pygit2(_prepare_provider):
assert provider.checkout() is None


@pytest.mark.skipif(not HAS_PYGIT2, reason="This host lacks proper pygit2 support")
@pytest.mark.skip_on_windows(
reason="Skip Pygit2 on windows, due to pygit2 access error on windows"
)
def test_checkout_pygit2_with_home_env_unset(_prepare_provider):
provider = _prepare_provider
provider.remotecallbacks = None
provider.credentials = None
with patched_environ(__cleanup__=["HOME"]):
assert "HOME" not in os.environ
provider.init_remote()
assert "HOME" in os.environ


@pytest.mark.skipif(not HAS_PYGIT2, reason="This host lacks proper pygit2 support")
@pytest.mark.skip_on_windows(
reason="Skip Pygit2 on windows, due to pygit2 access error on windows"
Expand Down
Loading