Bug: Transfer repository doesn't update the count

This commit is contained in:
Unknwon 2014-09-12 18:29:58 -04:00
parent f67c59135f
commit cfed11f092
7 changed files with 21 additions and 13 deletions

View file

@ -257,6 +257,7 @@ settings.site = Official Site
settings.update_settings = Update Settings settings.update_settings = Update Settings
settings.transfer = Transfer Ownership settings.transfer = Transfer Ownership
settings.transfer_desc = Transfer this repo to another user or to an organization where you have admin rights. 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 = Delete This Repository
settings.delete_desc = Once you delete a repository, there is no going back. Please be certain. 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. settings.update_settings_success = Repository options has been successfully updated.

View file

@ -257,6 +257,7 @@ settings.site = 官方网站
settings.update_settings = 更新仓库设置 settings.update_settings = 更新仓库设置
settings.transfer = 转移仓库所有权 settings.transfer = 转移仓库所有权
settings.transfer_desc = 您可以将仓库转移至您拥有管理员权限的帐户或组织。 settings.transfer_desc = 您可以将仓库转移至您拥有管理员权限的帐户或组织。
settings.new_owner_has_same_repo = 新的仓库拥有者已经存在同名仓库!
settings.delete = 删除本仓库 settings.delete = 删除本仓库
settings.delete_desc = 删除仓库操作不可逆转,请三思而后行。 settings.delete_desc = 删除仓库操作不可逆转,请三思而后行。
settings.update_settings_success = 仓库设置更新成功! settings.update_settings_success = 仓库设置更新成功!

View file

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.5.0.0910 Beta" const APP_VER = "0.5.0.0912 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View file

@ -644,12 +644,20 @@ func RepoPath(userName, repoName string) string {
} }
// TransferOwnership transfers all corresponding setting from old user to new one. // 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) newUser, err := GetUserByName(newOwner)
if err != nil { if err != nil {
return err 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() sess := x.NewSession()
defer sess.Close() defer sess.Close()
if err = sess.Begin(); err != nil { 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. // Update owner team info and count.
t.RepoIds += "$" + com.ToStr(repo.Id) + "|" t.RepoIds += "$" + com.ToStr(repo.Id) + "|"
t.NumRepos++ t.NumRepos++
@ -933,9 +935,9 @@ func GetRepositoryByRef(ref string) (*Repository, error) {
} }
// GetRepositoryByName returns the repository by given name under user if exists. // 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{ repo := &Repository{
OwnerId: userId, OwnerId: uid,
LowerName: strings.ToLower(repoName), LowerName: strings.ToLower(repoName),
} }
has, err := x.Get(repo) has, err := x.Get(repo)

View file

@ -113,7 +113,11 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), SETTINGS_OPTIONS, nil)
return return
} else if err = models.TransferOwnership(ctx.Repo.Owner, newOwner, ctx.Repo.Repository); err != nil { } 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 return
} }
log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner) log.Trace("Repository transfered: %s/%s -> %s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newOwner)

View file

@ -1 +1 @@
0.5.0.0910 Beta 0.5.0.0912 Beta

View file

@ -14,7 +14,7 @@
</p> </p>
<div class="{{if .ReadmeExist}}panel-content markdown{{end}} code-view"> <div class="{{if .ReadmeExist}}panel-content markdown{{end}} code-view">
{{if .ReadmeExist}} {{if .ReadmeExist}}
{{.FileContent | Str2html}} {{if .FileContent}}{{.FileContent | Str2html}}{{end}}
{{else if not .IsFileText}} {{else if not .IsFileText}}
<div class="view-raw"> <div class="view-raw">
{{if .IsImageFile}} {{if .IsImageFile}}