Browse Source

Make sure git version&feature are always prepared (#30877) (#30879)

Backport #30877
tags/v1.22.0
wxiaoguang 1 month ago
parent
commit
d5563be0ee
No account linked to committer's email address

+ 2
- 5
cmd/hook.go View File

} }
} }


supportProcReceive := false
if git.CheckGitVersionAtLeast("2.29") == nil {
supportProcReceive = true
}
supportProcReceive := git.DefaultFeatures().SupportProcReceive


for scanner.Scan() { for scanner.Scan() {
// TODO: support news feeds for wiki // TODO: support news feeds for wiki
return nil return nil
} }


if git.CheckGitVersionAtLeast("2.29") != nil {
if !git.DefaultFeatures().SupportProcReceive {
return fail(ctx, "No proc-receive support", "current git version doesn't support proc-receive.") return fail(ctx, "No proc-receive support", "current git version doesn't support proc-receive.")
} }



+ 1
- 1
cmd/serv.go View File

} }


if len(words) < 2 { if len(words) < 2 {
if git.CheckGitVersionAtLeast("2.29") == nil {
if git.DefaultFeatures().SupportProcReceive {
// for AGit Flow // for AGit Flow
if cmd == "ssh_info" { if cmd == "ssh_info" {
fmt.Print(`{"type":"gitea","version":1}`) fmt.Print(`{"type":"gitea","version":1}`)

+ 1
- 1
modules/git/blame.go View File

// CreateBlameReader creates reader for given repository, commit and file // CreateBlameReader creates reader for given repository, commit and file
func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error) { func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error) {
var ignoreRevsFile *string var ignoreRevsFile *string
if CheckGitVersionAtLeast("2.23") == nil && !bypassBlameIgnore {
if DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore {
ignoreRevsFile = tryCreateBlameIgnoreRevsFile(commit) ignoreRevsFile = tryCreateBlameIgnoreRevsFile(commit)
} }



+ 1
- 1
modules/git/commit.go View File

// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only') // GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
func (c *Commit) GetBranchName() (string, error) { func (c *Commit) GetBranchName() (string, error) {
cmd := NewCommand(c.repo.Ctx, "name-rev") cmd := NewCommand(c.repo.Ctx, "name-rev")
if CheckGitVersionAtLeast("2.13.0") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.13.0") {
cmd.AddArguments("--exclude", "refs/tags/*") cmd.AddArguments("--exclude", "refs/tags/*")
} }
cmd.AddArguments("--name-only", "--no-undefined").AddDynamicArguments(c.ID.String()) cmd.AddArguments("--name-only", "--no-undefined").AddDynamicArguments(c.ID.String())

+ 83
- 100
modules/git/git.go View File

"github.com/hashicorp/go-version" "github.com/hashicorp/go-version"
) )


// RequiredVersion is the minimum Git version required
const RequiredVersion = "2.0.0"
const RequiredVersion = "2.0.0" // the minimum Git version required


var (
// GitExecutable is the command name of git
// Could be updated to an absolute path while initialization
GitExecutable = "git"

// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx
DefaultContext context.Context
type Features struct {
gitVersion *version.Version


DefaultFeatures struct {
GitVersion *version.Version
UsingGogit bool
SupportProcReceive bool // >= 2.29
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
SupportedObjectFormats []ObjectFormat // sha1, sha256
}


SupportProcReceive bool // >= 2.29
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
}
var (
GitExecutable = "git" // the command name of git, will be updated to an absolute path during initialization
DefaultContext context.Context // the default context to run git commands in, must be initialized by git.InitXxx
defaultFeatures *Features
) )


// loadGitVersion tries to get the current git version and stores it into a global variable
func loadGitVersion() error {
// doesn't need RWMutex because it's executed by Init()
if DefaultFeatures.GitVersion != nil {
return nil
func (f *Features) CheckVersionAtLeast(atLeast string) bool {
return f.gitVersion.Compare(version.Must(version.NewVersion(atLeast))) >= 0
}

// VersionInfo returns git version information
func (f *Features) VersionInfo() string {
return f.gitVersion.Original()
}

func DefaultFeatures() *Features {
if defaultFeatures == nil {
if !setting.IsProd || setting.IsInTesting {
log.Warn("git.DefaultFeatures is called before git.InitXxx, initializing with default values")
}
if err := InitSimple(context.Background()); err != nil {
log.Fatal("git.InitSimple failed: %v", err)
}
} }
return defaultFeatures
}


func loadGitVersionFeatures() (*Features, error) {
stdout, _, runErr := NewCommand(DefaultContext, "version").RunStdString(nil) stdout, _, runErr := NewCommand(DefaultContext, "version").RunStdString(nil)
if runErr != nil { if runErr != nil {
return runErr
return nil, runErr
} }


ver, err := parseGitVersionLine(strings.TrimSpace(stdout)) ver, err := parseGitVersionLine(strings.TrimSpace(stdout))
if err == nil {
DefaultFeatures.GitVersion = ver
if err != nil {
return nil, err
} }
return err

features := &Features{gitVersion: ver, UsingGogit: isGogit}
features.SupportProcReceive = features.CheckVersionAtLeast("2.29")
features.SupportHashSha256 = features.CheckVersionAtLeast("2.42") && !isGogit
features.SupportedObjectFormats = []ObjectFormat{Sha1ObjectFormat}
if features.SupportHashSha256 {
features.SupportedObjectFormats = append(features.SupportedObjectFormats, Sha256ObjectFormat)
}
return features, nil
} }


func parseGitVersionLine(s string) (*version.Version, error) { func parseGitVersionLine(s string) (*version.Version, error) {
return fmt.Errorf("git not found: %w", err) return fmt.Errorf("git not found: %w", err)
} }
GitExecutable = absPath GitExecutable = absPath
return nil
}


if err = loadGitVersion(); err != nil {
return fmt.Errorf("unable to load git version: %w", err)
}

versionRequired, err := version.NewVersion(RequiredVersion)
if err != nil {
return err
}

if DefaultFeatures.GitVersion.LessThan(versionRequired) {
func ensureGitVersion() error {
if !DefaultFeatures().CheckVersionAtLeast(RequiredVersion) {
moreHint := "get git: https://git-scm.com/download/" moreHint := "get git: https://git-scm.com/download/"
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
// there are a lot of CentOS/RHEL users using old git, so we add a special hint for them // there are a lot of CentOS/RHEL users using old git, so we add a special hint for them
if _, err = os.Stat("/etc/redhat-release"); err == nil {
if _, err := os.Stat("/etc/redhat-release"); err == nil {
// ius.io is the recommended official(git-scm.com) method to install git // ius.io is the recommended official(git-scm.com) method to install git
moreHint = "get git: https://git-scm.com/download/linux and https://ius.io" moreHint = "get git: https://git-scm.com/download/linux and https://ius.io"
} }
} }
return fmt.Errorf("installed git version %q is not supported, Gitea requires git version >= %q, %s", DefaultFeatures.GitVersion.Original(), RequiredVersion, moreHint)
return fmt.Errorf("installed git version %q is not supported, Gitea requires git version >= %q, %s", DefaultFeatures().gitVersion.Original(), RequiredVersion, moreHint)
} }


if err = checkGitVersionCompatibility(DefaultFeatures.GitVersion); err != nil {
return fmt.Errorf("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git", DefaultFeatures.GitVersion.String(), err)
}
return nil
}

// VersionInfo returns git version information
func VersionInfo() string {
if DefaultFeatures.GitVersion == nil {
return "(git not found)"
}
format := "%s"
args := []any{DefaultFeatures.GitVersion.Original()}
// Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
format += ", Wire Protocol %s Enabled"
args = append(args, "Version 2") // for focus color
}

return fmt.Sprintf(format, args...)
}

func checkInit() error {
if setting.Git.HomePath == "" {
return errors.New("unable to init Git's HomeDir, incorrect initialization of the setting and git modules")
}
if DefaultContext != nil {
log.Warn("git module has been initialized already, duplicate init may work but it's better to fix it")
if err := checkGitVersionCompatibility(DefaultFeatures().gitVersion); err != nil {
return fmt.Errorf("installed git version %s has a known compatibility issue with Gitea: %w, please upgrade (or downgrade) git", DefaultFeatures().gitVersion.String(), err)
} }
return nil return nil
} }
// InitSimple initializes git module with a very simple step, no config changes, no global command arguments. // InitSimple initializes git module with a very simple step, no config changes, no global command arguments.
// This method doesn't change anything to filesystem. At the moment, it is only used by some Gitea sub-commands. // This method doesn't change anything to filesystem. At the moment, it is only used by some Gitea sub-commands.
func InitSimple(ctx context.Context) error { func InitSimple(ctx context.Context) error {
if err := checkInit(); err != nil {
return err
if setting.Git.HomePath == "" {
return errors.New("unable to init Git's HomeDir, incorrect initialization of the setting and git modules")
}

if DefaultContext != nil && (!setting.IsProd || setting.IsInTesting) {
log.Warn("git module has been initialized already, duplicate init may work but it's better to fix it")
} }


DefaultContext = ctx DefaultContext = ctx
defaultCommandExecutionTimeout = time.Duration(setting.Git.Timeout.Default) * time.Second defaultCommandExecutionTimeout = time.Duration(setting.Git.Timeout.Default) * time.Second
} }


return SetExecutablePath(setting.Git.Path)
}
if err := SetExecutablePath(setting.Git.Path); err != nil {
return err
}


// InitFull initializes git module with version check and change global variables, sync gitconfig.
// It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables.
func InitFull(ctx context.Context) (err error) {
if err = InitSimple(ctx); err != nil {
var err error
defaultFeatures, err = loadGitVersionFeatures()
if err != nil {
return err
}
if err = ensureGitVersion(); err != nil {
return err return err
} }


if _, ok := os.LookupEnv("GNUPGHOME"); !ok { if _, ok := os.LookupEnv("GNUPGHOME"); !ok {
_ = os.Setenv("GNUPGHOME", filepath.Join(HomeDir(), ".gnupg")) _ = os.Setenv("GNUPGHOME", filepath.Join(HomeDir(), ".gnupg"))
} }
return nil
}

// InitFull initializes git module with version check and change global variables, sync gitconfig.
// It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables.
func InitFull(ctx context.Context) (err error) {
if err = InitSimple(ctx); err != nil {
return err
}


// Since git wire protocol has been released from git v2.18 // Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
if setting.Git.EnableAutoGitWireProtocol && DefaultFeatures().CheckVersionAtLeast("2.18") {
globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2") globalCommandArgs = append(globalCommandArgs, "-c", "protocol.version=2")
} }


// Explicitly disable credential helper, otherwise Git credentials might leak // Explicitly disable credential helper, otherwise Git credentials might leak
if CheckGitVersionAtLeast("2.9") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.9") {
globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=") globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=")
} }
DefaultFeatures.SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil
DefaultFeatures.SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil && !isGogit
if DefaultFeatures.SupportHashSha256 {
SupportedObjectFormats = append(SupportedObjectFormats, Sha256ObjectFormat)
} else {
log.Warn("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported")
}


if setting.LFS.StartServer { if setting.LFS.StartServer {
if CheckGitVersionAtLeast("2.1.2") != nil {
if !DefaultFeatures().CheckVersionAtLeast("2.1.2") {
return errors.New("LFS server support requires Git >= 2.1.2") return errors.New("LFS server support requires Git >= 2.1.2")
} }
globalCommandArgs = append(globalCommandArgs, "-c", "filter.lfs.required=", "-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=") globalCommandArgs = append(globalCommandArgs, "-c", "filter.lfs.required=", "-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
return err return err
} }


if CheckGitVersionAtLeast("2.10") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.10") {
if err := configSet("receive.advertisePushOptions", "true"); err != nil { if err := configSet("receive.advertisePushOptions", "true"); err != nil {
return err return err
} }
} }


if CheckGitVersionAtLeast("2.18") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.18") {
if err := configSet("core.commitGraph", "true"); err != nil { if err := configSet("core.commitGraph", "true"); err != nil {
return err return err
} }
} }
} }


if DefaultFeatures.SupportProcReceive {
if DefaultFeatures().SupportProcReceive {
// set support for AGit flow // set support for AGit flow
if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil { if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil {
return err return err
} }


// By default partial clones are disabled, enable them from git v2.22 // By default partial clones are disabled, enable them from git v2.22
if !setting.Git.DisablePartialClone && CheckGitVersionAtLeast("2.22") == nil {
if !setting.Git.DisablePartialClone && DefaultFeatures().CheckVersionAtLeast("2.22") {
if err = configSet("uploadpack.allowfilter", "true"); err != nil { if err = configSet("uploadpack.allowfilter", "true"); err != nil {
return err return err
} }
return err return err
} }


// CheckGitVersionAtLeast check git version is at least the constraint version
func CheckGitVersionAtLeast(atLeast string) error {
if DefaultFeatures.GitVersion == nil {
panic("git module is not initialized") // it shouldn't happen
}
atLeastVersion, err := version.NewVersion(atLeast)
if err != nil {
return err
}
if DefaultFeatures.GitVersion.Compare(atLeastVersion) < 0 {
return fmt.Errorf("installed git binary version %s is not at least %s", DefaultFeatures.GitVersion.Original(), atLeast)
}
return nil
}

func checkGitVersionCompatibility(gitVer *version.Version) error { func checkGitVersionCompatibility(gitVer *version.Version) error {
badVersions := []struct { badVersions := []struct {
Version *version.Version Version *version.Version

+ 1
- 5
modules/git/object_format.go View File

Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{} Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{}
) )


var SupportedObjectFormats = []ObjectFormat{
Sha1ObjectFormat,
}

func ObjectFormatFromName(name string) ObjectFormat { func ObjectFormatFromName(name string) ObjectFormat {
for _, objectFormat := range SupportedObjectFormats {
for _, objectFormat := range DefaultFeatures().SupportedObjectFormats {
if name == objectFormat.Name() { if name == objectFormat.Name() {
return objectFormat return objectFormat
} }

+ 1
- 1
modules/git/object_id.go View File



func NewIDFromString(hexHash string) (ObjectID, error) { func NewIDFromString(hexHash string) (ObjectID, error) {
var theObjectFormat ObjectFormat var theObjectFormat ObjectFormat
for _, objectFormat := range SupportedObjectFormats {
for _, objectFormat := range DefaultFeatures().SupportedObjectFormats {
if len(hexHash) == objectFormat.FullLength() { if len(hexHash) == objectFormat.FullLength() {
theObjectFormat = objectFormat theObjectFormat = objectFormat
break break

+ 1
- 1
modules/git/remote.go View File

// GetRemoteAddress returns remote url of git repository in the repoPath with special remote name // GetRemoteAddress returns remote url of git repository in the repoPath with special remote name
func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string, error) { func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string, error) {
var cmd *Command var cmd *Command
if CheckGitVersionAtLeast("2.7") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.7") {
cmd = NewCommand(ctx, "remote", "get-url").AddDynamicArguments(remoteName) cmd = NewCommand(ctx, "remote", "get-url").AddDynamicArguments(remoteName)
} else { } else {
cmd = NewCommand(ctx, "config", "--get").AddDynamicArguments("remote." + remoteName + ".url") cmd = NewCommand(ctx, "config", "--get").AddDynamicArguments("remote." + remoteName + ".url")

+ 1
- 1
modules/git/repo.go View File

if !IsValidObjectFormat(objectFormatName) { if !IsValidObjectFormat(objectFormatName) {
return fmt.Errorf("invalid object format: %s", objectFormatName) return fmt.Errorf("invalid object format: %s", objectFormatName)
} }
if DefaultFeatures.SupportHashSha256 {
if DefaultFeatures().SupportHashSha256 {
cmd.AddOptionValues("--object-format", objectFormatName) cmd.AddOptionValues("--object-format", objectFormatName)
} }



+ 0
- 6
modules/git/repo_base.go View File

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package git

var isGogit bool

+ 1
- 3
modules/git/repo_base_gogit.go View File

"github.com/go-git/go-git/v5/storage/filesystem" "github.com/go-git/go-git/v5/storage/filesystem"
) )


func init() {
isGogit = true
}
const isGogit = true


// Repository represents a Git repository. // Repository represents a Git repository.
type Repository struct { type Repository struct {

+ 1
- 3
modules/git/repo_base_nogogit.go View File

"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
) )


func init() {
isGogit = false
}
const isGogit = false


// Repository represents a Git repository. // Repository represents a Git repository.
type Repository struct { type Repository struct {

+ 1
- 1
modules/git/repo_commit.go View File

} }


func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) { func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) {
if CheckGitVersionAtLeast("2.7.0") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.7.0") {
stdout, _, err := NewCommand(repo.Ctx, "for-each-ref", "--format=%(refname:strip=2)"). stdout, _, err := NewCommand(repo.Ctx, "for-each-ref", "--format=%(refname:strip=2)").
AddOptionFormat("--count=%d", limit). AddOptionFormat("--count=%d", limit).
AddOptionValues("--contains", commit.ID.String(), BranchPrefix). AddOptionValues("--contains", commit.ID.String(), BranchPrefix).

+ 1
- 1
modules/git/repo_commitgraph.go View File

// WriteCommitGraph write commit graph to speed up repo access // WriteCommitGraph write commit graph to speed up repo access
// this requires git v2.18 to be installed // this requires git v2.18 to be installed
func WriteCommitGraph(ctx context.Context, repoPath string) error { func WriteCommitGraph(ctx context.Context, repoPath string) error {
if CheckGitVersionAtLeast("2.18") == nil {
if DefaultFeatures().CheckVersionAtLeast("2.18") {
if _, _, err := NewCommand(ctx, "commit-graph", "write").RunStdString(&RunOpts{Dir: repoPath}); err != nil { if _, _, err := NewCommand(ctx, "commit-graph", "write").RunStdString(&RunOpts{Dir: repoPath}); err != nil {
return fmt.Errorf("unable to write commit-graph for '%s' : %w", repoPath, err) return fmt.Errorf("unable to write commit-graph for '%s' : %w", repoPath, err)
} }

+ 1
- 1
modules/lfs/pointer_scanner_nogogit.go View File

go pipeline.BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader, shasToBatchWriter, &wg) go pipeline.BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader, shasToBatchWriter, &wg)


// 1. Run batch-check on all objects in the repository // 1. Run batch-check on all objects in the repository
if git.CheckGitVersionAtLeast("2.6.0") != nil {
if !git.DefaultFeatures().CheckVersionAtLeast("2.6.0") {
revListReader, revListWriter := io.Pipe() revListReader, revListWriter := io.Pipe()
shasToCheckReader, shasToCheckWriter := io.Pipe() shasToCheckReader, shasToCheckWriter := io.Pipe()
wg.Add(2) wg.Add(2)

+ 5
- 1
routers/init.go View File

"code.gitea.io/gitea/modules/system" "code.gitea.io/gitea/modules/system"
"code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/routing" "code.gitea.io/gitea/modules/web/routing"
actions_router "code.gitea.io/gitea/routers/api/actions" actions_router "code.gitea.io/gitea/routers/api/actions"
// InitWebInstalled is for global installed configuration. // InitWebInstalled is for global installed configuration.
func InitWebInstalled(ctx context.Context) { func InitWebInstalled(ctx context.Context) {
mustInitCtx(ctx, git.InitFull) mustInitCtx(ctx, git.InitFull)
log.Info("Git version: %s (home: %s)", git.VersionInfo(), git.HomeDir())
log.Info("Git version: %s (home: %s)", git.DefaultFeatures().VersionInfo(), git.HomeDir())
if !git.DefaultFeatures().SupportHashSha256 {
log.Warn("sha256 hash support is disabled - requires Git >= 2.42." + util.Iif(git.DefaultFeatures().UsingGogit, " Gogit is currently unsupported.", ""))
}


// Setup i18n // Setup i18n
translation.InitLocales(ctx) translation.InitLocales(ctx)

+ 1
- 1
routers/private/hook_pre_receive.go View File

preReceiveBranch(ourCtx, oldCommitID, newCommitID, refFullName) preReceiveBranch(ourCtx, oldCommitID, newCommitID, refFullName)
case refFullName.IsTag(): case refFullName.IsTag():
preReceiveTag(ourCtx, oldCommitID, newCommitID, refFullName) preReceiveTag(ourCtx, oldCommitID, newCommitID, refFullName)
case git.DefaultFeatures.SupportProcReceive && refFullName.IsFor():
case git.DefaultFeatures().SupportProcReceive && refFullName.IsFor():
preReceiveFor(ourCtx, oldCommitID, newCommitID, refFullName) preReceiveFor(ourCtx, oldCommitID, newCommitID, refFullName)
default: default:
ourCtx.AssertCanWriteCode() ourCtx.AssertCanWriteCode()

+ 1
- 1
routers/private/hook_proc_receive.go View File

// HookProcReceive proc-receive hook - only handles agit Proc-Receive requests at present // HookProcReceive proc-receive hook - only handles agit Proc-Receive requests at present
func HookProcReceive(ctx *gitea_context.PrivateContext) { func HookProcReceive(ctx *gitea_context.PrivateContext) {
opts := web.GetForm(ctx).(*private.HookOptions) opts := web.GetForm(ctx).(*private.HookOptions)
if !git.DefaultFeatures.SupportProcReceive {
if !git.DefaultFeatures().SupportProcReceive {
ctx.Status(http.StatusNotFound) ctx.Status(http.StatusNotFound)
return return
} }

+ 1
- 1
routers/private/serv.go View File

} }
} else { } else {
// Because of the special ref "refs/for" we will need to delay write permission check // Because of the special ref "refs/for" we will need to delay write permission check
if git.DefaultFeatures.SupportProcReceive && unitType == unit.TypeCode {
if git.DefaultFeatures().SupportProcReceive && unitType == unit.TypeCode {
mode = perm.AccessModeRead mode = perm.AccessModeRead
} }



+ 1
- 1
routers/web/admin/config.go View File

ctx.Data["OfflineMode"] = setting.OfflineMode ctx.Data["OfflineMode"] = setting.OfflineMode
ctx.Data["RunUser"] = setting.RunUser ctx.Data["RunUser"] = setting.RunUser
ctx.Data["RunMode"] = util.ToTitleCase(setting.RunMode) ctx.Data["RunMode"] = util.ToTitleCase(setting.RunMode)
ctx.Data["GitVersion"] = git.VersionInfo()
ctx.Data["GitVersion"] = git.DefaultFeatures().VersionInfo()


ctx.Data["AppDataPath"] = setting.AppDataPath ctx.Data["AppDataPath"] = setting.AppDataPath
ctx.Data["RepoRootPath"] = setting.RepoRootPath ctx.Data["RepoRootPath"] = setting.RepoRootPath

+ 1
- 1
routers/web/misc/misc.go View File

) )


func SSHInfo(rw http.ResponseWriter, req *http.Request) { func SSHInfo(rw http.ResponseWriter, req *http.Request) {
if !git.DefaultFeatures.SupportProcReceive {
if !git.DefaultFeatures().SupportProcReceive {
rw.WriteHeader(http.StatusNotFound) rw.WriteHeader(http.StatusNotFound)
return return
} }

+ 1
- 1
routers/web/repo/githttp.go View File



if repoExist { if repoExist {
// Because of special ref "refs/for" .. , need delay write permission check // Because of special ref "refs/for" .. , need delay write permission check
if git.DefaultFeatures.SupportProcReceive {
if git.DefaultFeatures().SupportProcReceive {
accessMode = perm.AccessModeRead accessMode = perm.AccessModeRead
} }



+ 1
- 1
routers/web/repo/repo.go View File



ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo() ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit() ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()
ctx.Data["SupportedObjectFormats"] = git.SupportedObjectFormats
ctx.Data["SupportedObjectFormats"] = git.DefaultFeatures().SupportedObjectFormats
ctx.Data["DefaultObjectFormat"] = git.Sha1ObjectFormat ctx.Data["DefaultObjectFormat"] = git.Sha1ObjectFormat


ctx.HTML(http.StatusOK, tplCreate) ctx.HTML(http.StatusOK, tplCreate)

+ 1
- 1
services/gitdiff/gitdiff.go View File

// so if we are using at least this version of git we don't have to tell ParsePatch to do // so if we are using at least this version of git we don't have to tell ParsePatch to do
// the skipping for us // the skipping for us
parsePatchSkipToFile := opts.SkipTo parsePatchSkipToFile := opts.SkipTo
if opts.SkipTo != "" && git.CheckGitVersionAtLeast("2.31") == nil {
if opts.SkipTo != "" && git.DefaultFeatures().CheckVersionAtLeast("2.31") {
cmdDiff.AddOptionFormat("--skip-to=%s", opts.SkipTo) cmdDiff.AddOptionFormat("--skip-to=%s", opts.SkipTo)
parsePatchSkipToFile = "" parsePatchSkipToFile = ""
} }

+ 1
- 1
services/pull/patch.go View File

cmdApply.AddArguments("--ignore-whitespace") cmdApply.AddArguments("--ignore-whitespace")
} }
is3way := false is3way := false
if git.CheckGitVersionAtLeast("2.32.0") == nil {
if git.DefaultFeatures().CheckVersionAtLeast("2.32.0") {
cmdApply.AddArguments("--3way") cmdApply.AddArguments("--3way")
is3way = true is3way = true
} }

+ 1
- 1
services/pull/temp_repo.go View File

baseBranch := "base" baseBranch := "base"


fetchArgs := git.TrustedCmdArgs{"--no-tags"} fetchArgs := git.TrustedCmdArgs{"--no-tags"}
if git.CheckGitVersionAtLeast("2.25.0") == nil {
if git.DefaultFeatures().CheckVersionAtLeast("2.25.0") {
// Writing the commit graph can be slow and is not needed here // Writing the commit graph can be slow and is not needed here
fetchArgs = append(fetchArgs, "--no-write-commit-graph") fetchArgs = append(fetchArgs, "--no-write-commit-graph")
} }

+ 1
- 1
services/repository/files/patch.go View File

stderr := &strings.Builder{} stderr := &strings.Builder{}


cmdApply := git.NewCommand(ctx, "apply", "--index", "--recount", "--cached", "--ignore-whitespace", "--whitespace=fix", "--binary") cmdApply := git.NewCommand(ctx, "apply", "--index", "--recount", "--cached", "--ignore-whitespace", "--whitespace=fix", "--binary")
if git.CheckGitVersionAtLeast("2.32") == nil {
if git.DefaultFeatures().CheckVersionAtLeast("2.32") {
cmdApply.AddArguments("-3") cmdApply.AddArguments("-3")
} }



+ 1
- 1
tests/integration/git_test.go View File

defer tests.PrintCurrentTest(t)() defer tests.PrintCurrentTest(t)()


// skip this test if git version is low // skip this test if git version is low
if git.CheckGitVersionAtLeast("2.29") != nil {
if !git.DefaultFeatures().SupportProcReceive {
return return
} }



Loading…
Cancel
Save