summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/models/repo.go b/models/repo.go
index 5412ca8f82..91bb0d710b 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -283,9 +283,9 @@ type Mirror struct {
NextUpdate time.Time
}
-func GetMirror(repoId int64) (*Mirror, error) {
+func getMirror(e Engine, repoId int64) (*Mirror, error) {
m := &Mirror{RepoId: repoId}
- has, err := x.Get(m)
+ has, err := e.Get(m)
if err != nil {
return nil, err
} else if !has {
@@ -294,11 +294,20 @@ func GetMirror(repoId int64) (*Mirror, error) {
return m, nil
}
-func UpdateMirror(m *Mirror) error {
- _, err := x.Id(m.Id).Update(m)
+// GetMirror returns mirror object by given repository ID.
+func GetMirror(repoId int64) (*Mirror, error) {
+ return getMirror(x, repoId)
+}
+
+func updateMirror(e Engine, m *Mirror) error {
+ _, err := e.Id(m.Id).Update(m)
return err
}
+func UpdateMirror(m *Mirror) error {
+ return updateMirror(x, m)
+}
+
// MirrorRepository creates a mirror repository from source.
func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) error {
_, stderr, err := process.ExecTimeout(10*time.Minute,
@@ -697,6 +706,18 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
return fmt.Errorf("transferRepoAction: %v", err)
}
+ // Update mirror information.
+ if repo.IsMirror {
+ mirror, err := getMirror(sess, repo.Id)
+ if err != nil {
+ return fmt.Errorf("getMirror: %v", err)
+ }
+ mirror.RepoName = newOwner.LowerName + "/" + repo.LowerName
+ if err = updateMirror(sess, mirror); err != nil {
+ return fmt.Errorf("updateMirror: %v", err)
+ }
+ }
+
// Change repository directory name.
if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
return fmt.Errorf("rename directory: %v", err)