enhance!: raise minimum git version to 2.34 (#39565)

Raise the minimum git version to 2.34, the version in Ubuntu 22.04,
Debian 12 and RHEL 8 ship newer, and remove the fallbacks it makes
obsolete.

- Always enable AGit
- Use `diff --skip-to` and `apply -3` unconditionally
- Set the default branch of new repos and wikis via `git init
--initial-branch`
- Detect rebase conflicts via `REBASE_HEAD`
This commit is contained in:
silverwind
2026-10-04 10:26:14 +02:00
committed by GitHub
parent 4bebd86285
commit eb4468ff4e
38 changed files with 177 additions and 404 deletions
+3 -9
View File
@@ -73,15 +73,9 @@ func syncGitConfig(ctx context.Context) (err error) {
return err
}
if DefaultFeatures().SupportProcReceive {
// set support for AGit flow
if err := configAddNonExist(ctx, "receive.procReceiveRefs", "refs/for"); err != nil {
return err
}
} else {
if err := configUnsetAll(ctx, "receive.procReceiveRefs", "refs/for"); err != nil {
return err
}
// set support for AGit flow
if err := configAddNonExist(ctx, "receive.procReceiveRefs", "refs/for"); err != nil {
return err
}
// Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user.
+1 -1
View File
@@ -40,7 +40,7 @@ func ForceFastImportWithInit(ctx context.Context, repoLocalPath string, commits
dirEntries, err := os.ReadDir(repoLocalPath)
if os.IsNotExist(err) || (err == nil && len(dirEntries) == 0) {
_ = os.MkdirAll(repoLocalPath, 0o755)
err := InitRepositoryLocal(ctx, repoLocalPath, initOpt.Bare, util.IfZero(initOpt.ObjectFormat, "sha1"))
err := InitRepositoryLocal(ctx, repoLocalPath, initOpt.Bare, util.IfZero(initOpt.ObjectFormat, "sha1"), "")
if err != nil {
return nil, err
}
+1 -3
View File
@@ -24,12 +24,11 @@ import (
"github.com/hashicorp/go-version"
)
const RequiredVersion = "2.25.0" // the minimum Git version required
const RequiredVersion = "2.34.0" // the minimum Git version required
type Features struct {
gitVersion *version.Version
SupportProcReceive bool // >= 2.29
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
SupportedObjectFormats []ObjectFormat // sha1, sha256
SupportCheckAttrOnBare bool // >= 2.40
@@ -79,7 +78,6 @@ func loadGitVersionFeatures() (*Features, error) {
}
features := &Features{gitVersion: ver}
features.SupportProcReceive = features.CheckVersionAtLeast("2.29")
features.SupportHashSha256 = features.CheckVersionAtLeast("2.42")
features.SupportedObjectFormats = []ObjectFormat{Sha1ObjectFormat}
if features.SupportHashSha256 {
+1 -2
View File
@@ -94,8 +94,7 @@ const (
StderrBadRevision StderrPrefix = "fatal: bad revision"
StderrNoSuchPath StderrPrefix = "fatal: no such path"
StderrNoSuchRemote1 StderrPrefix = "fatal: no such remote" // git < 2.30, exit status 128
StderrNoSuchRemote2 StderrPrefix = "error: no such remote" // git >= 2.30. exit status 2
StderrNoSuchRemote StderrPrefix = "error: no such remote"
StderrAuthenticationFailed StderrPrefix = "fatal: Authentication failed for"
StderrCouldNotReadUsername StderrPrefix = "fatal: could not read Username"
+2 -2
View File
@@ -38,8 +38,8 @@ func RenameRepository(ctx context.Context, repo, newRepo RepositoryFacade) error
return nil
}
func InitRepository(ctx context.Context, repo RepositoryFacade, objectFormatName string) error {
return InitRepositoryLocal(ctx, gitrepo.RepoLocalPath(repo), true, objectFormatName)
func InitRepository(ctx context.Context, repo RepositoryFacade, objectFormatName, initialBranch string) error {
return InitRepositoryLocal(ctx, gitrepo.RepoLocalPath(repo), true, objectFormatName, initialBranch)
}
func IsRepoFileExist(ctx context.Context, repo RepositoryFacade, relativeFilePath string) (bool, error) {
+1 -1
View File
@@ -66,7 +66,7 @@ func (err *ErrInvalidCloneAddr) Unwrap() error {
// IsRemoteNotExistError checks the prefix of the error message to see whether a remote does not exist.
func IsRemoteNotExistError(err error) bool {
return gitcmd.IsStderr(err, gitcmd.StderrNoSuchRemote1, gitcmd.StderrNoSuchRemote2)
return gitcmd.IsStderr(err, gitcmd.StderrNoSuchRemote)
}
// ParseRemoteAddr checks if given remote address is valid,
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsRemoteNotExistError(t *testing.T) {
_, err := GetRemoteAddress(t.Context(), mockRepository("repo1_bare"), "no-such-remote")
assert.True(t, IsRemoteNotExistError(err))
}
+4 -1
View File
@@ -118,7 +118,7 @@ func IsRepoURLAccessible(ctx context.Context, url string) bool {
}
// InitRepositoryLocal initializes a new Git repository.
func InitRepositoryLocal(ctx context.Context, localRepoPath string, bare bool, objectFormatName string) error {
func InitRepositoryLocal(ctx context.Context, localRepoPath string, bare bool, objectFormatName, initialBranch string) error {
err := os.MkdirAll(localRepoPath, os.ModePerm)
if err != nil {
return err
@@ -132,6 +132,9 @@ func InitRepositoryLocal(ctx context.Context, localRepoPath string, bare bool, o
if DefaultFeatures().SupportHashSha256 {
cmd.AddOptionValues("--object-format", objectFormatName)
}
if initialBranch != "" {
cmd.AddOptionValues("--initial-branch", initialBranch)
}
if bare {
cmd.AddArguments("--bare")