summaryrefslogtreecommitdiffstats
path: root/models/repo_mirror.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-04-12 21:52:57 +0100
committerGitHub <noreply@github.com>2019-04-12 21:52:57 +0100
commitb3e757a06c2cfc554c7db0e2da170b123404f058 (patch)
treeb5ff24cc87a1a51308132a11b192d459d1c6f957 /models/repo_mirror.go
parent01e0408fa1bf01094c40887ed8d58992459e3ba4 (diff)
downloadgitea-b3e757a06c2cfc554c7db0e2da170b123404f058.tar.gz
gitea-b3e757a06c2cfc554c7db0e2da170b123404f058.zip
Correctly adjust mirror url (#6593)
Diffstat (limited to 'models/repo_mirror.go')
-rw-r--r--models/repo_mirror.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/models/repo_mirror.go b/models/repo_mirror.go
index 759241e461..b63fba5741 100644
--- a/models/repo_mirror.go
+++ b/models/repo_mirror.go
@@ -20,7 +20,6 @@ import (
"github.com/Unknwon/com"
"github.com/go-xorm/xorm"
- "gopkg.in/ini.v1"
)
// MirrorQueue holds an UniqueQueue object of the mirror
@@ -71,11 +70,18 @@ func (m *Mirror) ScheduleNextUpdate() {
}
func remoteAddress(repoPath string) (string, error) {
- cfg, err := ini.Load(GitConfigPath(repoPath))
+ cmd := git.NewCommand("remote", "get-url", "origin")
+ result, err := cmd.RunInDir(repoPath)
if err != nil {
+ if strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
+ return "", nil
+ }
return "", err
}
- return cfg.Section("remote \"origin\"").Key("url").Value(), nil
+ if len(result) > 0 {
+ return result[:len(result)-1], nil
+ }
+ return "", nil
}
func (m *Mirror) readAddress() {
@@ -115,14 +121,15 @@ func (m *Mirror) FullAddress() string {
// SaveAddress writes new address to Git repository config.
func (m *Mirror) SaveAddress(addr string) error {
- configPath := m.Repo.GitConfigPath()
- cfg, err := ini.Load(configPath)
- if err != nil {
- return fmt.Errorf("Load: %v", err)
+ repoPath := m.Repo.RepoPath()
+ // Remove old origin
+ _, err := git.NewCommand("remote", "remove", "origin").RunInDir(repoPath)
+ if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
+ return err
}
- cfg.Section("remote \"origin\"").Key("url").SetValue(addr)
- return cfg.SaveToIndent(configPath, "\t")
+ _, err = git.NewCommand("remote", "add", "origin", addr).RunInDir(repoPath)
+ return err
}
// gitShortEmptySha Git short empty SHA