feat: vendor gitea 1.16.2
This commit is contained in:
@@ -12,25 +12,28 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/tempdir"
|
||||
"code.gitea.io/gitea/modules/testlogger"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
const RequiredVersion = "2.0.0" // the minimum Git version required
|
||||
const RequiredVersion = "2.6.0" // the minimum Git version required
|
||||
|
||||
type Features 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
|
||||
SupportCheckAttrOnBare bool // >= 2.40
|
||||
UsingGogit bool
|
||||
SupportProcReceive bool // >= 2.29
|
||||
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
|
||||
SupportedObjectFormats []ObjectFormat // sha1, sha256
|
||||
SupportCheckAttrOnBare bool // >= 2.40
|
||||
SupportCatFileBatchCommand bool // >= 2.36, support `git cat-file --batch-command`
|
||||
SupportGitMergeTree bool // >= 2.40 // we also need "--merge-base"
|
||||
}
|
||||
|
||||
var defaultFeatures *Features
|
||||
@@ -57,7 +60,7 @@ func DefaultFeatures() *Features {
|
||||
}
|
||||
|
||||
func loadGitVersionFeatures() (*Features, error) {
|
||||
stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background(), nil)
|
||||
stdout, _, runErr := gitcmd.NewCommand("version").RunStdString(context.Background())
|
||||
if runErr != nil {
|
||||
return nil, runErr
|
||||
}
|
||||
@@ -75,6 +78,8 @@ func loadGitVersionFeatures() (*Features, error) {
|
||||
features.SupportedObjectFormats = append(features.SupportedObjectFormats, Sha256ObjectFormat)
|
||||
}
|
||||
features.SupportCheckAttrOnBare = features.CheckVersionAtLeast("2.40")
|
||||
features.SupportCatFileBatchCommand = features.CheckVersionAtLeast("2.36")
|
||||
features.SupportGitMergeTree = features.CheckVersionAtLeast("2.40") // we also need "--merge-base"
|
||||
return features, nil
|
||||
}
|
||||
|
||||
@@ -84,12 +89,17 @@ func parseGitVersionLine(s string) (*version.Version, error) {
|
||||
return nil, fmt.Errorf("invalid git version: %q", s)
|
||||
}
|
||||
|
||||
// version string is like: "git version 2.29.3" or "git version 2.29.3.windows.1"
|
||||
// version output is like: "git version {versionString}"
|
||||
// versionString can be:
|
||||
// * "2.5.3"
|
||||
// * "2.29.3.windows.1"
|
||||
// * "2.28.0.618.gf4bc123cb7": https://github.com/go-gitea/gitea/issues/12731
|
||||
versionString := fields[2]
|
||||
if pos := strings.Index(versionString, "windows"); pos >= 1 {
|
||||
versionString = versionString[:pos-1]
|
||||
versionFields := strings.Split(versionString, ".")
|
||||
if len(versionFields) > 3 {
|
||||
versionFields = versionFields[:3]
|
||||
}
|
||||
return version.NewVersion(versionString)
|
||||
return version.NewVersion(strings.Join(versionFields, "."))
|
||||
}
|
||||
|
||||
func checkGitVersionCompatibility(gitVer *version.Version) error {
|
||||
@@ -137,10 +147,6 @@ func InitSimple() error {
|
||||
log.Warn("git module has been initialized already, duplicate init may work but it's better to fix it")
|
||||
}
|
||||
|
||||
if setting.Git.Timeout.Default > 0 {
|
||||
gitcmd.SetDefaultCommandExecutionTimeout(time.Duration(setting.Git.Timeout.Default) * time.Second)
|
||||
}
|
||||
|
||||
if err := gitcmd.SetExecutablePath(setting.Git.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -176,3 +182,23 @@ func InitFull() (err error) {
|
||||
|
||||
return syncGitConfig(context.Background())
|
||||
}
|
||||
|
||||
// RunGitTests helps to init the git module and run tests.
|
||||
// FIXME: GIT-PACKAGE-DEPENDENCY: the dependency is not right, setting.Git.HomePath is initialized in this package but used in gitcmd package
|
||||
func RunGitTests(m interface{ Run() int }) {
|
||||
os.Exit(runGitTests(m))
|
||||
}
|
||||
|
||||
func runGitTests(m interface{ Run() int }) int {
|
||||
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
|
||||
if err != nil {
|
||||
testlogger.Panicf("unable to create temp dir: %s", err.Error())
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
setting.Git.HomePath = gitHomePath
|
||||
if err = InitFull(); err != nil {
|
||||
testlogger.Panicf("failed to call Init: %s", err.Error())
|
||||
}
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user