Skip to content
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/70673.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed gitfs, git_pillar and winrepo failing to initialize pygit2 remotes with pygit2 1.21.0, which raises ``TypeError`` when adding a file to the repository config.
3 changes: 0 additions & 3 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,9 +2110,6 @@ def init_remote(self):

self.gitdir = salt.utils.path.join(self.repo.workdir, ".git")
self.enforce_git_config()
git_config = os.path.join(self.gitdir, "config")
if os.path.exists(git_config) and PYGIT2_VERSION >= Version("0.28.0"):
self.repo.config.add_file(git_config)

return new

Expand Down
20 changes: 20 additions & 0 deletions tests/pytests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,26 @@ 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_init_remote_pygit2_git_config(_prepare_provider):
"""
The repo config already includes .git/config, so init_remote must not add
it again (pygit2 >= 1.21 raises TypeError, older versions load it twice and
list every fetch refspec twice).
"""
provider = _prepare_provider
assert provider.init_remote() is False
origin = provider.repo.remotes["origin"]
assert origin.url == provider.url
assert origin.fetch_refspecs == [
"+refs/heads/*:refs/remotes/origin/*",
"+refs/tags/*:refs/tags/*",
]


@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