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
This commit is contained in:
6543 2020-09-28 21:52:13 +02:00 committed by GitHub
parent e9346fc4a9
commit 3e279dfb0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -185,8 +185,8 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
address = u.String() address = u.String()
if err := mirror_service.SaveAddress(ctx.Repo.Mirror, address); err != nil { if err := mirror_service.UpdateAddress(ctx.Repo.Mirror, address); err != nil {
ctx.ServerError("SaveAddress", err) ctx.ServerError("UpdateAddress", err)
return return
} }

View file

@ -90,8 +90,8 @@ func AddressNoCredentials(m *models.Mirror) string {
return u.String() return u.String()
} }
// SaveAddress writes new address to Git repository config. // UpdateAddress writes new address to Git repository and database
func SaveAddress(m *models.Mirror, addr string) error { func UpdateAddress(m *models.Mirror, addr string) error {
repoPath := m.Repo.RepoPath() repoPath := m.Repo.RepoPath()
// Remove old origin // Remove old origin
_, err := git.NewCommand("remote", "rm", "origin").RunInDir(repoPath) _, err := git.NewCommand("remote", "rm", "origin").RunInDir(repoPath)
@ -99,10 +99,14 @@ func SaveAddress(m *models.Mirror, addr string) error {
return err return err
} }
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath) if _, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath); err != nil {
return err return err
} }
m.Repo.OriginalURL = addr
return models.UpdateRepositoryCols(m.Repo, "original_url")
}
// gitShortEmptySha Git short empty SHA // gitShortEmptySha Git short empty SHA
const gitShortEmptySha = "0000000" const gitShortEmptySha = "0000000"