Skip to content

Commit

Permalink
Mirror: Update DB on Address-Update too (go-gitea#12964)
Browse files Browse the repository at this point in the history
* Mirror: Update DB on Address-Update too

* new name for function to better describe
  • Loading branch information
6543 committed Sep 28, 2020
1 parent e9346fc commit 0b85b7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions services/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 0b85b7f

Please sign in to comment.