diff --git a/public/css/gogs.css b/public/css/gogs.css index bf39ea39ce..dcfb2758a0 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -309,6 +309,18 @@ html, body { height: 8em; } +#repo-import-auth{ + width: 100%; + margin-top: 48px; + box-sizing: border-box; +} + +#repo-import-auth .form-group{ + box-sizing: border-box; + margin-left: 0; + margin-right: 0; +} + /* gogits user setting */ #user-setting-nav > h4, #user-setting-container > h4, #user-setting-container > div > h4, diff --git a/routers/repo/repo.go b/routers/repo/repo.go index d223600c52..0ab1c9e420 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -55,6 +55,38 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Handle(200, "repo.Create", err) } +func Import(ctx *middleware.Context, form auth.CreateRepoForm) { + ctx.Data["Title"] = "Import repository" + ctx.Data["PageIsNewRepo"] = true // For navbar arrow. + ctx.Data["LanguageIgns"] = models.LanguageIgns + ctx.Data["Licenses"] = models.Licenses + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "repo/import") + return + } + + if ctx.HasError() { + ctx.HTML(200, "repo/import") + return + } + + _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, + form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") + if err == nil { + log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) + ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) + return + } else if err == models.ErrRepoAlreadyExist { + ctx.RenderWithErr("Repository name has already been used", "repo/import", &form) + return + } else if err == models.ErrRepoNameIllegal { + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/import", &form) + return + } + ctx.Handle(200, "repo.Import", err) +} + func Single(ctx *middleware.Context, params martini.Params) { branchName := ctx.Repo.BranchName commitId := ctx.Repo.CommitId diff --git a/templates/repo/import.tmpl b/templates/repo/import.tmpl new file mode 100644 index 0000000000..75d928d138 --- /dev/null +++ b/templates/repo/import.tmpl @@ -0,0 +1,112 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +