diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 02a565286738..b1af3076f141 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 165e7cd35b2a..93e58f2cd4b9 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) @@ -100,7 +100,9 @@ func SaveAddress(m *models.Mirror, addr string) error { } _, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath) - return err + + m.Repo.OriginalURL = addr + return models.UpdateRepositoryCols(m.Repo, "original_url") } // gitShortEmptySha Git short empty SHA