Skip to content

Commit 3e279df

Browse files
authored
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
1 parent e9346fc commit 3e279df

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

routers/repo/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
185185

186186
address = u.String()
187187

188-
if err := mirror_service.SaveAddress(ctx.Repo.Mirror, address); err != nil {
189-
ctx.ServerError("SaveAddress", err)
188+
if err := mirror_service.UpdateAddress(ctx.Repo.Mirror, address); err != nil {
189+
ctx.ServerError("UpdateAddress", err)
190190
return
191191
}
192192

services/mirror/mirror.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,21 @@ func AddressNoCredentials(m *models.Mirror) string {
9090
return u.String()
9191
}
9292

93-
// SaveAddress writes new address to Git repository config.
94-
func SaveAddress(m *models.Mirror, addr string) error {
93+
// UpdateAddress writes new address to Git repository and database
94+
func UpdateAddress(m *models.Mirror, addr string) error {
9595
repoPath := m.Repo.RepoPath()
9696
// Remove old origin
9797
_, err := git.NewCommand("remote", "rm", "origin").RunInDir(repoPath)
9898
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
9999
return err
100100
}
101101

102-
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath)
103-
return err
102+
if _, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath); err != nil {
103+
return err
104+
}
105+
106+
m.Repo.OriginalURL = addr
107+
return models.UpdateRepositoryCols(m.Repo, "original_url")
104108
}
105109

106110
// gitShortEmptySha Git short empty SHA

0 commit comments

Comments
 (0)