fix: allow git clone of private repos with anonymous code access (#38074) (#38146)

Backport #38074

## Summary

Fixes #38062.

Private repositories with a code unit configured for **anonymous read
access** (Settings → Public Access → Code: anonymous view) could not be
cloned without credentials. The git HTTP auth gate (`httpBase`) only
bypassed authentication for non-private repos, ignoring the per-unit
anonymous access setting entirely.

- Check anonymous permissions via
`access_model.GetDoerRepoPermission(ctx, repo, nil)` + `CanAccess`
before requiring auth on pull operations, so the per-unit
`AnonymousAccessMode` is respected through the existing permission model
- This also correctly handles `setting.Repository.ForcePrivate` (which
the naive direct-field check would have missed)
- Push (receive-pack) and `RequireSignInViewStrict` continue to require
credentials as before

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
bircni
2026-06-17 21:21:05 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 99f8b3d9a1
commit 6fb96fcfdf
3 changed files with 57 additions and 22 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ RUN_MODE = prod
[database]
DB_TYPE = sqlite3
PATH = gitea.db
PATH = gitea-test.db
[indexer]
REPO_INDEXER_ENABLED = true