From d07edc5336342b8cce2eb44a61806f15782d5728 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 29 May 2019 12:04:55 -0400 Subject: [PATCH] Handle early git version's lack of get-url (#7065) (#7076) --- models/repo_mirror.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/models/repo_mirror.go b/models/repo_mirror.go index cdc1f4d95b..a582b4529c 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -20,6 +20,7 @@ import ( "github.com/Unknwon/com" "github.com/go-xorm/xorm" + "github.com/mcuadros/go-version" ) // MirrorQueue holds an UniqueQueue object of the mirror @@ -70,7 +71,17 @@ func (m *Mirror) ScheduleNextUpdate() { } func remoteAddress(repoPath string) (string, error) { - cmd := git.NewCommand("remote", "get-url", "origin") + var cmd *git.Command + binVersion, err := git.BinVersion() + if err != nil { + return "", err + } + if version.Compare(binVersion, "2.7", ">=") { + cmd = git.NewCommand("remote", "get-url", "origin") + } else { + cmd = git.NewCommand("config", "--get", "remote.origin.url") + } + result, err := cmd.RunInDir(repoPath) if err != nil { if strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {