Handle early git version's lack of get-url (#7065) (#7076)

This commit is contained in:
techknowlogick 2019-05-29 12:04:55 -04:00 committed by GitHub
parent 63cb160cb1
commit d07edc5336
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,7 @@ import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
"github.com/mcuadros/go-version"
) )
// MirrorQueue holds an UniqueQueue object of the mirror // MirrorQueue holds an UniqueQueue object of the mirror
@ -70,7 +71,17 @@ func (m *Mirror) ScheduleNextUpdate() {
} }
func remoteAddress(repoPath string) (string, error) { 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) result, err := cmd.RunInDir(repoPath)
if err != nil { if err != nil {
if strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") { if strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {