summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-07-02 15:09:09 +0100
committerGitHub <noreply@github.com>2020-07-02 15:09:09 +0100
commit482ba937ed118d68448c5fe347ee7e43f5621c0b (patch)
tree328ac6693790909f816faedea45520493ac1f478 /routers/repo
parenta87a64e6a1f2e3e673fc24818bd17f7225f921f6 (diff)
downloadgitea-482ba937ed118d68448c5fe347ee7e43f5621c0b.tar.gz
gitea-482ba937ed118d68448c5fe347ee7e43f5621c0b.zip
Provide option to unlink a fork (#11858)
* Provide option to unlink a fork Fix #4566 Signed-off-by: Andrew Thornton <art27@cantab.net> * Apply suggestions from code review Co-authored-by: techknowlogick <matti@mdranta.net> * Add check that user can create repo Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @cirnoT Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <matti@mdranta.net>
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/setting.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 635ec41334..02331c232b 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -356,9 +356,46 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
ctx.ServerError("DeleteMirrorByRepoID", err)
return
}
- log.Trace("Repository converted from mirror to regular: %s/%s", ctx.Repo.Owner.Name, repo.Name)
+ log.Trace("Repository converted from mirror to regular: %s", repo.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.convert_succeed"))
- ctx.Redirect(setting.AppSubURL + "/" + ctx.Repo.Owner.Name + "/" + repo.Name)
+ ctx.Redirect(repo.Link())
+
+ case "convert_fork":
+ if !ctx.Repo.IsOwner() {
+ ctx.Error(404)
+ return
+ }
+ if err := repo.GetOwner(); err != nil {
+ ctx.ServerError("Convert Fork", err)
+ return
+ }
+ if repo.Name != form.RepoName {
+ ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
+ return
+ }
+
+ if !repo.IsFork {
+ ctx.Error(404)
+ return
+ }
+
+ if !ctx.Repo.Owner.CanCreateRepo() {
+ ctx.Flash.Error(ctx.Tr("repo.form.reach_limit_of_creation", ctx.User.MaxCreationLimit()))
+ ctx.Redirect(repo.Link() + "/settings")
+ return
+ }
+
+ repo.IsFork = false
+ repo.ForkID = 0
+ if err := models.UpdateRepository(repo, false); err != nil {
+ log.Error("Unable to update repository %-v whilst converting from fork", repo)
+ ctx.ServerError("Convert Fork", err)
+ return
+ }
+
+ log.Trace("Repository converted from fork to regular: %s", repo.FullName())
+ ctx.Flash.Success(ctx.Tr("repo.settings.convert_fork_succeed"))
+ ctx.Redirect(repo.Link())
case "transfer":
if !ctx.Repo.IsOwner() {