mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-23 02:29:43 +08:00
fix lfs version check warning log when using ssh protocol (#5501)
This commit is contained in:
parent
2a660a1de1
commit
7fd34c0517
12
cmd/hook.go
12
cmd/hook.go
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -63,11 +62,6 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func hookSetup(logPath string) {
|
|
||||||
setting.NewContext()
|
|
||||||
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath))
|
|
||||||
}
|
|
||||||
|
|
||||||
func runHookPreReceive(c *cli.Context) error {
|
func runHookPreReceive(c *cli.Context) error {
|
||||||
if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
|
if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -79,7 +73,7 @@ func runHookPreReceive(c *cli.Context) error {
|
||||||
setting.CustomConf = c.GlobalString("config")
|
setting.CustomConf = c.GlobalString("config")
|
||||||
}
|
}
|
||||||
|
|
||||||
hookSetup("hooks/pre-receive.log")
|
setup("hooks/pre-receive.log")
|
||||||
|
|
||||||
// the environment setted on serv command
|
// the environment setted on serv command
|
||||||
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
|
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
|
||||||
|
@ -155,7 +149,7 @@ func runHookUpdate(c *cli.Context) error {
|
||||||
setting.CustomConf = c.GlobalString("config")
|
setting.CustomConf = c.GlobalString("config")
|
||||||
}
|
}
|
||||||
|
|
||||||
hookSetup("hooks/update.log")
|
setup("hooks/update.log")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -171,7 +165,7 @@ func runHookPostReceive(c *cli.Context) error {
|
||||||
setting.CustomConf = c.GlobalString("config")
|
setting.CustomConf = c.GlobalString("config")
|
||||||
}
|
}
|
||||||
|
|
||||||
hookSetup("hooks/post-receive.log")
|
setup("hooks/post-receive.log")
|
||||||
|
|
||||||
// the environment setted on serv command
|
// the environment setted on serv command
|
||||||
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
|
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
|
||||||
|
|
22
cmd/serv.go
22
cmd/serv.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/pprof"
|
"code.gitea.io/gitea/modules/pprof"
|
||||||
|
@ -22,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
|
version "github.com/mcuadros/go-version"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,8 +50,28 @@ var CmdServ = cli.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkLFSVersion() {
|
||||||
|
if setting.LFS.StartServer {
|
||||||
|
//Disable LFS client hooks if installed for the current OS user
|
||||||
|
//Needs at least git v2.1.2
|
||||||
|
binVersion, err := git.BinVersion()
|
||||||
|
if err != nil {
|
||||||
|
fail(fmt.Sprintf("Error retrieving git version: %v", err), fmt.Sprintf("Error retrieving git version: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !version.Compare(binVersion, "2.1.2", ">=") {
|
||||||
|
setting.LFS.StartServer = false
|
||||||
|
println("LFS server support needs at least Git v2.1.2, disabled")
|
||||||
|
} else {
|
||||||
|
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
|
||||||
|
"-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setup(logPath string) {
|
func setup(logPath string) {
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
|
checkLFSVersion()
|
||||||
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath))
|
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ func initIntegrationTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
|
setting.CheckLFSVersion()
|
||||||
models.LoadConfigs()
|
models.LoadConfigs()
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
|
@ -693,6 +693,27 @@ func createPIDFile(pidPath string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckLFSVersion will check lfs version, if not satisfied, then disable it.
|
||||||
|
func CheckLFSVersion() {
|
||||||
|
if LFS.StartServer {
|
||||||
|
//Disable LFS client hooks if installed for the current OS user
|
||||||
|
//Needs at least git v2.1.2
|
||||||
|
|
||||||
|
binVersion, err := git.BinVersion()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(4, "Error retrieving git version: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !version.Compare(binVersion, "2.1.2", ">=") {
|
||||||
|
LFS.StartServer = false
|
||||||
|
log.Error(4, "LFS server support needs at least Git v2.1.2")
|
||||||
|
} else {
|
||||||
|
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
|
||||||
|
"-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewContext initializes configuration context.
|
// NewContext initializes configuration context.
|
||||||
// NOTE: do not print any log except error.
|
// NOTE: do not print any log except error.
|
||||||
func NewContext() {
|
func NewContext() {
|
||||||
|
@ -888,7 +909,6 @@ func NewContext() {
|
||||||
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(20 * time.Minute)
|
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(20 * time.Minute)
|
||||||
|
|
||||||
if LFS.StartServer {
|
if LFS.StartServer {
|
||||||
|
|
||||||
if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
|
if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
|
||||||
log.Fatal(4, "Failed to create '%s': %v", LFS.ContentPath, err)
|
log.Fatal(4, "Failed to create '%s': %v", LFS.ContentPath, err)
|
||||||
}
|
}
|
||||||
|
@ -922,26 +942,6 @@ func NewContext() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Disable LFS client hooks if installed for the current OS user
|
|
||||||
//Needs at least git v2.1.2
|
|
||||||
|
|
||||||
binVersion, err := git.BinVersion()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(4, "Error retrieving git version: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !version.Compare(binVersion, "2.1.2", ">=") {
|
|
||||||
|
|
||||||
LFS.StartServer = false
|
|
||||||
log.Error(4, "LFS server support needs at least Git v2.1.2")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "filter.lfs.required=",
|
|
||||||
"-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sec = Cfg.Section("security")
|
sec = Cfg.Section("security")
|
||||||
|
|
|
@ -45,6 +45,7 @@ func NewServices() {
|
||||||
// GlobalInit is for global configuration reload-able.
|
// GlobalInit is for global configuration reload-able.
|
||||||
func GlobalInit() {
|
func GlobalInit() {
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
|
setting.CheckLFSVersion()
|
||||||
log.Trace("AppPath: %s", setting.AppPath)
|
log.Trace("AppPath: %s", setting.AppPath)
|
||||||
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
|
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
|
||||||
log.Trace("Custom path: %s", setting.CustomPath)
|
log.Trace("Custom path: %s", setting.CustomPath)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user