diff options
author | 6543 | 2020-09-28 21:52:13 +0200 |
---|---|---|
committer | GitHub | 2020-09-28 21:52:13 +0200 |
commit | 3e279dfb0bc08fe74ed394d0ea26b7c6a8b23b86 (patch) | |
tree | 10773d64228e3ff6f4d63fab595cce8d782edd08 | |
parent | e9346fc4a9cebddbe277e0c2447e18c18c3f947a (diff) |
Mirror: Update DB on Address-Update too (#12964) (#12967)
* Mirror: Update DB on Address-Update too (#12964)
* Mirror: Update DB on Address-Update too
* new name for function to better describe
* fix lint
-rw-r--r-- | routers/repo/setting.go | 4 | ||||
-rw-r--r-- | services/mirror/mirror.go | 12 |
2 files changed, 10 insertions, 6 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 02a565286..b1af3076f 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -185,8 +185,8 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { address = u.String() - if err := mirror_service.SaveAddress(ctx.Repo.Mirror, address); err != nil { - ctx.ServerError("SaveAddress", err) + if err := mirror_service.UpdateAddress(ctx.Repo.Mirror, address); err != nil { + ctx.ServerError("UpdateAddress", err) return } diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go index 165e7cd35..1d60e9758 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -90,8 +90,8 @@ func AddressNoCredentials(m *models.Mirror) string { return u.String() } -// SaveAddress writes new address to Git repository config. -func SaveAddress(m *models.Mirror, addr string) error { +// UpdateAddress writes new address to Git repository and database +func UpdateAddress(m *models.Mirror, addr string) error { repoPath := m.Repo.RepoPath() // Remove old origin _, err := git.NewCommand("remote", "rm", "origin").RunInDir(repoPath) @@ -99,8 +99,12 @@ func SaveAddress(m *models.Mirror, addr string) error { return err } - _, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath) - return err + if _, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath); err != nil { + return err + } + + m.Repo.OriginalURL = addr + return models.UpdateRepositoryCols(m.Repo, "original_url") } // gitShortEmptySha Git short empty SHA |