Skip to content

Fix pygit2 gitfs remotes failing to initialize with pygit2 1.21 - #70684

Open
aliassar wants to merge 1 commit into
saltstack:3006.xfrom
aliassar:fix-70673-pygit2-1.21
Open

aliassar wants to merge 1 commit into
saltstack:3006.xfrom
aliassar:fix-70673-pygit2-1.21

Conversation

@aliassar

@aliassar aliassar commented Nov 5, 2026

Copy link
Copy Markdown

What does this PR do?

Removes the self.repo.config.add_file(<gitdir>/config) call from Pygit2.init_remote. pygit2 1.21.0 returns a RepositoryConfig from Repository.config whose add_file() always raises TypeError, so every pygit2 gitfs/git_pillar/winrepo remote failed to initialize.

The call was redundant: the repo config already loads .git/config at the local level and libgit2 re-reads it when it changes, so what enforce_git_config() writes is still picked up. On older pygit2 it just loaded the file a second time, so fetch_refspecs listed every refspec twice. I checked this on pygit2 1.8.0 through 1.21.0, so I dropped the call instead of gating it on the version.

What issues does this PR fix or reference?

Fixes #70673

Previous Behavior

With pygit2 1.21.0, fileserver.update (and git_pillar/winrepo) fails with TypeError: The local repository configuration does not support adding files. from Pygit2.init_remote. With older pygit2, the in-memory repo config has .git/config loaded twice, so the fetch refspecs are duplicated.

New Behavior

pygit2 remotes initialize with 1.21.0, and the repo config has each refspec once on all versions.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Added test_init_remote_pygit2_git_config in tests/pytests/unit/utils/test_gitfs.py. It fails before the change on 1.21.0 (the TypeError) and on 1.15.1/1.19.2 (duplicated refspecs), and passes after. tests/pytests/unit/utils/test_gitfs.py and tests/pytests/functional/utils/gitfs/ -k pygit2 --run-slow pass with pygit2 1.15.1, 1.19.2 and 1.21.0. Without the change, the functional pygit2 tests all fail on 1.21.0 (16 failed).

Commits signed with GPG?

No

pygit2 1.21.0 returns a RepositoryConfig from Repository.config, and its
add_file() always raises TypeError, so Pygit2.init_remote failed for
every gitfs, git_pillar and winrepo remote.

The add_file() call was redundant anyway: the repository config already
reads .git/config at the local level and libgit2 re-reads it when it
changes on disk. On older pygit2 versions the extra call only loaded the
same file a second time, so every multivar (such as the fetch refspecs)
showed up twice. Drop the call.

Fixes saltstack#70673
@aliassar
aliassar requested a review from a team as a code owner November 5, 2026 00:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant