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

Đang mở
#70,767 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Một pull request liên quan đã được merge.

  • #70768 của @aliassar — đã merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, devops

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
15.8k
Fork
5.6k
Merge trung bình
5 ngày 9 giờ
Pull request đã merge (30 ngày)
99

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của saltstack/salt

Tất cả issue của saltstack/salt

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.