From cfed11f092580ecf47cff43274c7cdd10d07bffd Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 12 Sep 2014 18:29:58 -0400 Subject: [PATCH] Bug: Transfer repository doesn't update the count --- conf/locale/locale_en-US.ini | 1 + conf/locale/locale_zh-CN.ini | 1 + gogs.go | 2 +- models/repo.go | 20 +++++++++++--------- routers/repo/setting.go | 6 +++++- templates/.VERSION | 2 +- templates/repo/view_file.tmpl | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index ba9bef6d52..2d69b48df5 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -257,6 +257,7 @@ settings.site = Official Site settings.update_settings = Update Settings settings.transfer = Transfer Ownership settings.transfer_desc = Transfer this repo to another user or to an organization where you have admin rights. +settings.new_owner_has_same_repo = New owner already has a repository with same name. settings.delete = Delete This Repository settings.delete_desc = Once you delete a repository, there is no going back. Please be certain. settings.update_settings_success = Repository options has been successfully updated. diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index 7d10142e62..2022361f82 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -257,6 +257,7 @@ settings.site = 官方网站 settings.update_settings = 更新仓库设置 settings.transfer = 转移仓库所有权 settings.transfer_desc = 您可以将仓库转移至您拥有管理员权限的帐户或组织。 +settings.new_owner_has_same_repo = 新的仓库拥有者已经存在同名仓库! settings.delete = 删除本仓库 settings.delete_desc = 删除仓库操作不可逆转,请三思而后行。 settings.update_settings_success = 仓库设置更新成功! diff --git a/gogs.go b/gogs.go index d3aa43778a..6f32b747a2 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.0.0910 Beta" +const APP_VER = "0.5.0.0912 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 341e7e47a1..25876872eb 100644 --- a/models/repo.go +++ b/models/repo.go @@ -644,12 +644,20 @@ func RepoPath(userName, repoName string) string { } // TransferOwnership transfers all corresponding setting from old user to new one. -func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) { +func TransferOwnership(u *User, newOwner string, repo *Repository) error { newUser, err := GetUserByName(newOwner) if err != nil { return err } + // Check if new owner has repository with same name. + has, err := IsRepositoryExist(u, repo.Name) + if err != nil { + return err + } else if has { + return ErrRepoAlreadyExist + } + sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { @@ -717,12 +725,6 @@ func TransferOwnership(u *User, newOwner string, repo *Repository) (err error) { } } - if _, err = sess.Exec( - "UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil { - sess.Rollback() - return err - } - // Update owner team info and count. t.RepoIds += "$" + com.ToStr(repo.Id) + "|" t.NumRepos++ @@ -933,9 +935,9 @@ func GetRepositoryByRef(ref string) (*Repository, error) { } // GetRepositoryByName returns the repository by given name under user if exists. -func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { +func GetRepositoryByName(uid int64, repoName string) (*Repository, error) { repo := &Repository{ - OwnerId: userId, + OwnerId: uid, LowerName: strings.ToLower(repoName), } has, err := x.Get(repo) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 80a064492e..2354fbc13f 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -113,7 +113,11 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil) return } else if err = models.TransferOwnership(ctx.Repo.Owner, newOwner, ctx.Repo.Repository); err != nil { - ctx.Handle(500, "TransferOwnership", err) + if err == models.ErrRepoAlreadyExist { + ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), SETTINGS_OPTIONS, nil) + } else { + ctx.Handle(500, "TransferOwnership", err) + } return } log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) diff --git a/templates/.VERSION b/templates/.VERSION index 18a13b3a73..e53dedcbf4 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.0.0910 Beta \ No newline at end of file +0.5.0.0912 Beta \ No newline at end of file diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index fb05945b9f..96efcdac54 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -14,7 +14,7 @@

{{if .ReadmeExist}} - {{.FileContent | Str2html}} + {{if .FileContent}}{{.FileContent | Str2html}}{{end}} {{else if not .IsFileText}}
{{if .IsImageFile}}