Skip to content

Commit d07edc5

Browse files
Handle early git version's lack of get-url (#7065) (#7076)
1 parent 63cb160 commit d07edc5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

models/repo_mirror.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/Unknwon/com"
2222
"github.com/go-xorm/xorm"
23+
"github.com/mcuadros/go-version"
2324
)
2425

2526
// MirrorQueue holds an UniqueQueue object of the mirror
@@ -70,7 +71,17 @@ func (m *Mirror) ScheduleNextUpdate() {
7071
}
7172

7273
func remoteAddress(repoPath string) (string, error) {
73-
cmd := git.NewCommand("remote", "get-url", "origin")
74+
var cmd *git.Command
75+
binVersion, err := git.BinVersion()
76+
if err != nil {
77+
return "", err
78+
}
79+
if version.Compare(binVersion, "2.7", ">=") {
80+
cmd = git.NewCommand("remote", "get-url", "origin")
81+
} else {
82+
cmd = git.NewCommand("config", "--get", "remote.origin.url")
83+
}
84+
7485
result, err := cmd.RunInDir(repoPath)
7586
if err != nil {
7687
if strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {

0 commit comments

Comments
 (0)