Skip to content

Fix lfs version check warning log when using ssh protocol #5501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -63,11 +62,6 @@ var (
}
)

func hookSetup(logPath string) {
setting.NewContext()
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath))
}

func runHookPreReceive(c *cli.Context) error {
if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {
return nil
Expand All @@ -79,7 +73,7 @@ func runHookPreReceive(c *cli.Context) error {
setting.CustomConf = c.GlobalString("config")
}

hookSetup("hooks/pre-receive.log")
setup("hooks/pre-receive.log")

// the environment setted on serv command
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
Expand Down Expand Up @@ -155,7 +149,7 @@ func runHookUpdate(c *cli.Context) error {
setting.CustomConf = c.GlobalString("config")
}

hookSetup("hooks/update.log")
setup("hooks/update.log")

return nil
}
Expand All @@ -171,7 +165,7 @@ func runHookPostReceive(c *cli.Context) error {
setting.CustomConf = c.GlobalString("config")
}

hookSetup("hooks/post-receive.log")
setup("hooks/post-receive.log")

// the environment setted on serv command
repoID, _ := strconv.ParseInt(os.Getenv(models.ProtectedBranchRepoID), 10, 64)
Expand Down
22 changes: 22 additions & 0 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

"code.gitea.io/git"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
Expand All @@ -22,6 +23,7 @@ import (

"github.com/Unknwon/com"
"github.com/dgrijalva/jwt-go"
version "github.com/mcuadros/go-version"
"github.com/urfave/cli"
)

Expand All @@ -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=",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this require git-lfs on server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary.

"-c", "filter.lfs.smudge=", "-c", "filter.lfs.clean=")
}
}
}

func setup(logPath string) {
setting.NewContext()
checkLFSVersion()
log.NewGitLogger(filepath.Join(setting.LogRootPath, logPath))
}

Expand Down
1 change: 1 addition & 0 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func initIntegrationTest() {
}

setting.NewContext()
setting.CheckLFSVersion()
models.LoadConfigs()

switch {
Expand Down
42 changes: 21 additions & 21 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// NOTE: do not print any log except error.
func NewContext() {
Expand Down Expand Up @@ -888,7 +909,6 @@ func NewContext() {
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(20 * time.Minute)

if LFS.StartServer {

if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
log.Fatal(4, "Failed to create '%s': %v", LFS.ContentPath, err)
}
Expand Down Expand Up @@ -922,26 +942,6 @@ func NewContext() {
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")
Expand Down
1 change: 1 addition & 0 deletions routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewServices() {
// GlobalInit is for global configuration reload-able.
func GlobalInit() {
setting.NewContext()
setting.CheckLFSVersion()
log.Trace("AppPath: %s", setting.AppPath)
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
log.Trace("Custom path: %s", setting.CustomPath)
Expand Down