From 4a654a8d44bf4b0dc9ab1bf850be68f73b25e5cd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 28 Sep 2020 21:00:52 +0200 Subject: [PATCH] Mirror: Update DB on Address-Update too (#12964) * Mirror: Update DB on Address-Update too * new name for function to better describe --- routers/repo/setting.go | 4 ++-- services/mirror/mirror.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 865dea9bca..ca222375fb 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -202,8 +202,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 da794ea585..5eafdab38d 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -89,8 +89,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) @@ -117,7 +117,9 @@ func SaveAddress(m *models.Mirror, addr string) error { return err } } - return nil + + m.Repo.OriginalURL = addr + return models.UpdateRepositoryCols(m.Repo, "original_url") } // gitShortEmptySha Git short empty SHA