summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-03 15:50:55 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-03 15:50:55 -0400
commit79a610592ea7c2e93ab2f91190af1782c4aa8f8d (patch)
tree94515ccd8e27fc7f01c08daea725bdd2f3dbee6a /models/repo.go
parentbbadbbdf685a7f6cb1924442a115aa88bb520e07 (diff)
downloadgitea-79a610592ea7c2e93ab2f91190af1782c4aa8f8d.tar.gz
gitea-79a610592ea7c2e93ab2f91190af1782c4aa8f8d.zip
Add: rename repository
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/models/repo.go b/models/repo.go
index e3270b1838..11e23ecd0f 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -369,14 +369,34 @@ func RepoPath(userName, repoName string) string {
return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
}
+// ChangeRepositoryName changes all corresponding setting from old repository name to new one.
+func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) {
+ // Update accesses.
+ accesses := make([]Access, 0, 5)
+ err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)})
+ if err != nil {
+ return err
+ }
+ for i := range accesses {
+ accesses[i].RepoName = userName + "/" + newRepoName
+ if err = UpdateAccess(&accesses[i]); err != nil {
+ return err
+ }
+ }
+
+ // Change repository directory name.
+ return os.Rename(RepoPath(userName, oldRepoName), RepoPath(userName, newRepoName))
+}
+
func UpdateRepository(repo *Repository) error {
+ repo.LowerName = strings.ToLower(repo.Name)
+
if len(repo.Description) > 255 {
repo.Description = repo.Description[:255]
}
if len(repo.Website) > 255 {
repo.Website = repo.Website[:255]
}
-
_, err := orm.Id(repo.Id).AllCols().Update(repo)
return err
}