[Bug]: gitfs with pygit2 >= 1.20 keeps deleted branches as saltenvs (fetch prune no longer used)

未关闭
#70,767 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

已经有一个关联 PR 被合并了。

  • #70768 来自 @aliassar —— 已合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, devops

调研方向

Start in salt/utils/gitfs.py and inspect the three pygit2.GIT_FETCH_PRUNE references in Pygit2._fetch, Pygit2.clean_stale_refs, and verify_pygit2. Check how pygit2.enums.FetchPrune.PRUNE is used and compare anonymous with authenticated remotes when pruning. Done when pygit2 1.20 or newer prunes deleted refs on fetch for both remote types, without requiring the git binary for the pygit2 provider.

由索引模型根据 Issue 内容生成。

描述

What happened?

pygit2 1.20.0 removed the old GIT_* constants, including GIT_FETCH_PRUNE (it's pygit2.enums.FetchPrune.PRUNE now, available since 1.14.0). salt/utils/gitfs.py still reads pygit2.GIT_FETCH_PRUNE in three places and treats the AttributeError as "this pygit2 is too old to prune":

  • Pygit2._fetch stops passing prune= to Remote.fetch().
  • Pygit2.clean_stale_refs falls back to git remote prune for anonymous remotes, and for remotes with credentials it just logs "The installed version of pygit2 (...) does not support detecting stale refs for authenticated remotes" and returns [].
  • verify_pygit2 now requires the git binary to be on PATH, otherwise the pygit2 provider is rejected.

So with an authenticated gitfs/git_pillar remote (user/password or SSH key), a branch or tag deleted on the remote stays around as a saltenv forever.

Repro: I drove salt.utils.gitfs.Pygit2 directly against a local repo with master and feature branches, fetched, deleted feature in the remote, and fetched again. "Authenticated" means credentials/remotecallbacks are set the same way salt sets them for gitfs_user/gitfs_password.

pygit2 1.19.2                         pygit2 1.20.0
--- anonymous remote                  --- anonymous remote
after deleting feature: ['base']      after deleting feature: ['base']
prune kwarg: [PRUNE, PRUNE]           prune kwarg: [None, None]
--- authenticated remote              --- authenticated remote
after deleting feature: ['base']      after deleting feature: ['base', 'feature']
prune kwarg: [PRUNE, PRUNE]           prune kwarg: [None, None]

(The anonymous case still works on 1.20 only because it falls back to the git CLI.) Same result on pygit2 1.21.0 once the add_file problem from #70673 is out of the way.

The same debug message shows up in the log in #70298 (pygit2 1.20.0), and #70744 bumps pygit2 to >=1.21.0, so this will hit packaged installs soon.

Expected: pygit2 >= 1.20 prunes on fetch like older releases, and deleted branches stop being saltenvs.

Seen on 3008.x at 987eefd0f3. The code is the same on 3006.x, 3007.x and master, so any install that pulls in pygit2 >= 1.20 is affected.

Type of salt install

pip (git)

Major version

3008.x

What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)

Not OS specific (reproduced on macOS from a git checkout).

salt --versions-report output

Not from a packaged install. Relevant bits: salt 3008.x @ 987eefd0f3, Python 3.11, pygit2 1.20.0 (libgit2 1.9.6) and 1.21.0 (libgit2 1.9.7). pygit2 1.15.1 and 1.19.2 are fine.

主要语言
Python
星标
15.8k
派生
5.6k
平均合并
5 天 9 小时
30 天内合并 PR
99

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

saltstack/salt 的其他 Issue

查看 saltstack/salt 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。