diff options
author | Unknown <joe2010xtmf@163.com> | 2014-06-25 05:35:23 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-06-25 05:35:23 -0400 |
commit | 32b09681b2da96afe9a44790e7944c4ac51e696c (patch) | |
tree | 1b66f2a799ae2251b5e46637000422c2fd03d111 /routers | |
parent | 8644c571dbcb964a338565c8042ff71957030e52 (diff) | |
download | gitea-32b09681b2da96afe9a44790e7944c4ac51e696c.tar.gz gitea-32b09681b2da96afe9a44790e7944c4ac51e696c.zip |
Migrate repository by organization
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index d96456422b..6cb6c0660e 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -53,7 +53,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Data["Licenses"] = models.Licenses if err := ctx.User.GetOrganizations(); err != nil { - ctx.Handle(500, "home.Dashboard(GetOrganizations)", err) + ctx.Handle(500, "home.CreatePost(GetOrganizations)", err) return } ctx.Data["Orgs"] = ctx.User.Orgs @@ -70,9 +70,9 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { u, err = models.GetUserById(form.Uid) if err != nil { if err == models.ErrUserNotExist { - ctx.Handle(404, "home.Dashboard(GetUserById)", err) + ctx.Handle(404, "home.CreatePost(GetUserById)", err) } else { - ctx.Handle(500, "home.Dashboard(GetUserById)", err) + ctx.Handle(500, "home.CreatePost(GetUserById)", err) } return } @@ -97,12 +97,19 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { log.Error("repo.CreatePost(DeleteRepository): %v", errDelete) } } - ctx.Handle(500, "repo.CreatePost", err) + ctx.Handle(500, "repo.CreatePost(CreateRepository)", err) } func Migrate(ctx *middleware.Context) { ctx.Data["Title"] = "Migrate repository" ctx.Data["PageIsNewRepo"] = true + + if err := ctx.User.GetOrganizations(); err != nil { + ctx.Handle(500, "home.Migrate(GetOrganizations)", err) + return + } + ctx.Data["Orgs"] = ctx.User.Orgs + ctx.HTML(200, MIGRATE) } @@ -110,19 +117,40 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.Data["Title"] = "Migrate repository" ctx.Data["PageIsNewRepo"] = true + if err := ctx.User.GetOrganizations(); err != nil { + ctx.Handle(500, "home.MigratePost(GetOrganizations)", err) + return + } + ctx.Data["Orgs"] = ctx.User.Orgs + if ctx.HasError() { ctx.HTML(200, MIGRATE) return } + u := ctx.User + // Not equal means current user is an organization. + if u.Id != form.Uid { + var err error + u, err = models.GetUserById(form.Uid) + if err != nil { + if err == models.ErrUserNotExist { + ctx.Handle(404, "home.MigratePost(GetUserById)", err) + } else { + ctx.Handle(500, "home.MigratePost(GetUserById)", err) + } + return + } + } + authStr := strings.Replace(fmt.Sprintf("://%s:%s", form.AuthUserName, form.AuthPasswd), "@", "%40", -1) url := strings.Replace(form.Url, "://", authStr+"@", 1) - repo, err := models.MigrateRepository(ctx.User, form.RepoName, form.Description, form.Private, + repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private, form.Mirror, url) if err == nil { - log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) - ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) + log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName) + ctx.Redirect("/" + u.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form) @@ -133,7 +161,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { } if repo != nil { - if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil { + if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil { log.Error("repo.MigratePost(DeleteRepository): %v", errDelete) } } @@ -142,7 +170,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.RenderWithErr(err.Error(), MIGRATE, &form) return } - ctx.Handle(500, "repo.Migrate", err) + ctx.Handle(500, "repo.Migrate(MigrateRepository)", err) } func Single(ctx *middleware.Context, params martini.Params) { |