aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--models/repo.go12
-rw-r--r--options/locale/locale_en-US.ini5
-rw-r--r--routers/repo/setting.go41
-rw-r--r--templates/repo/settings/options.tmpl109
-rw-r--r--web_src/less/_repository.less5
5 files changed, 124 insertions, 48 deletions
diff --git a/models/repo.go b/models/repo.go
index 3b874f3359..c7d2ef467c 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -209,19 +209,9 @@ func (repo *Repository) SanitizedOriginalURL() string {
// ColorFormat returns a colored string to represent this repo
func (repo *Repository) ColorFormat(s fmt.State) {
- var ownerName interface{}
-
- if repo.OwnerName != "" {
- ownerName = repo.OwnerName
- } else if repo.Owner != nil {
- ownerName = repo.Owner.Name
- } else {
- ownerName = log.NewColoredIDValue(strconv.FormatInt(repo.OwnerID, 10))
- }
-
log.ColorFprintf(s, "%d:%s/%s",
log.NewColoredIDValue(repo.ID),
- ownerName,
+ repo.OwnerName,
repo.Name)
}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 7bde0d2af3..036665256d 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1382,6 +1382,11 @@ settings.convert_desc = You can convert this mirror into a regular repository. T
settings.convert_notices_1 = This operation will convert the mirror into a regular repository and cannot be undone.
settings.convert_confirm = Convert Repository
settings.convert_succeed = The mirror has been converted into a regular repository.
+settings.convert_fork = Convert to Regular Repository
+settings.convert_fork_desc = You can convert this fork into a regular repository. This cannot be undone.
+settings.convert_fork_notices_1 = This operation will convert the fork into a regular repository and cannot be undone.
+settings.convert_fork_confirm = Convert Repository
+settings.convert_fork_succeed = The fork has been converted into a regular repository.
settings.transfer = Transfer Ownership
settings.transfer_desc = Transfer this repository to a user or to an organization for which you have administrator rights.
settings.transfer_notices_1 = - You will lose access to the repository if you transfer it to an individual user.
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() {
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl
index c674fcf7f9..5666b8f956 100644
--- a/templates/repo/settings/options.tmpl
+++ b/templates/repo/settings/options.tmpl
@@ -358,17 +358,28 @@
</h4>
<div class="ui attached warning table danger segment">
{{if .Repository.IsMirror}}
- <div class="item">
- <div class="ui right">
- <button class="ui basic red show-modal button" data-modal="#convert-repo-modal">{{.i18n.Tr "repo.settings.convert"}}</button>
+ <div class="item">
+ <div class="ui right">
+ <button class="ui basic red show-modal button" data-modal="#convert-mirror-repo-modal">{{.i18n.Tr "repo.settings.convert"}}</button>
+ </div>
+ <div>
+ <h5>{{.i18n.Tr "repo.settings.convert"}}</h5>
+ <p>{{.i18n.Tr "repo.settings.convert_desc"}}</p>
+ </div>
</div>
- <div>
- <h5>{{.i18n.Tr "repo.settings.convert"}}</h5>
- <p>{{.i18n.Tr "repo.settings.convert_desc"}}</p>
+ <div class="ui divider"></div>
+ {{end}}
+ {{if and .Repository.IsFork .Repository.Owner.CanCreateRepo}}
+ <div class="item">
+ <div class="ui right">
+ <button class="ui basic red show-modal button" data-modal="#convert-fork-repo-modal">{{.i18n.Tr "repo.settings.convert_fork"}}</button>
+ </div>
+ <div>
+ <h5>{{.i18n.Tr "repo.settings.convert_fork"}}</h5>
+ <p>{{.i18n.Tr "repo.settings.convert_fork_desc"}}</p>
+ </div>
</div>
- </div>
-
- <div class="ui divider"></div>
+ <div class="ui divider"></div>
{{end}}
<div class="item">
<div class="ui right">
@@ -437,37 +448,67 @@
{{if .Permission.IsOwner}}
{{if .Repository.IsMirror}}
- <div class="ui small modal" id="convert-repo-modal">
- <div class="header">
- {{.i18n.Tr "repo.settings.convert"}}
- </div>
- <div class="content">
- <div class="ui warning message text left">
- {{.i18n.Tr "repo.settings.convert_notices_1"}}
+ <div class="ui small modal" id="convert-mirror-repo-modal">
+ <div class="header">
+ {{.i18n.Tr "repo.settings.convert"}}
</div>
- <form class="ui form" action="{{.Link}}" method="post">
- {{.CsrfTokenHtml}}
- <input type="hidden" name="action" value="convert">
- <div class="field">
- <label>
- {{.i18n.Tr "repo.settings.transfer_form_title"}}
- <span class="text red">{{.Repository.Name}}</span>
- </label>
- </div>
- <div class="required field">
- <label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
- <input id="repo_name" name="repo_name" required>
+ <div class="content">
+ <div class="ui warning message text left">
+ {{.i18n.Tr "repo.settings.convert_notices_1"}}
</div>
+ <form class="ui form" action="{{.Link}}" method="post">
+ {{.CsrfTokenHtml}}
+ <input type="hidden" name="action" value="convert">
+ <div class="field">
+ <label>
+ {{.i18n.Tr "repo.settings.transfer_form_title"}}
+ <span class="text red">{{.Repository.Name}}</span>
+ </label>
+ </div>
+ <div class="required field">
+ <label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
+ <input id="repo_name" name="repo_name" required>
+ </div>
- <div class="text right actions">
- <div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
- <button class="ui red button">{{.i18n.Tr "repo.settings.convert_confirm"}}</button>
- </div>
- </form>
+ <div class="text right actions">
+ <div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
+ <button class="ui red button">{{.i18n.Tr "repo.settings.convert_confirm"}}</button>
+ </div>
+ </form>
+ </div>
</div>
- </div>
{{end}}
+ {{if and .Repository.IsFork .Repository.Owner.CanCreateRepo}}
+ <div class="ui small modal" id="convert-fork-repo-modal">
+ <div class="header">
+ {{.i18n.Tr "repo.settings.convert_fork"}}
+ </div>
+ <div class="content">
+ <div class="ui warning message text left">
+ {{.i18n.Tr "repo.settings.convert_fork_notices_1"}}
+ </div>
+ <form class="ui form" action="{{.Link}}" method="post">
+ {{.CsrfTokenHtml}}
+ <input type="hidden" name="action" value="convert_fork">
+ <div class="field">
+ <label>
+ {{.i18n.Tr "repo.settings.transfer_form_title"}}
+ <span class="text red">{{.Repository.Name}}</span>
+ </label>
+ </div>
+ <div class="required field">
+ <label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
+ <input id="repo_name" name="repo_name" required>
+ </div>
+ <div class="text right actions">
+ <div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
+ <button class="ui red button">{{.i18n.Tr "repo.settings.convert_fork_confirm"}}</button>
+ </div>
+ </form>
+ </div>
+ </div>
+ {{end}}
<div class="ui small modal" id="transfer-repo-modal">
<div class="header">
{{.i18n.Tr "repo.settings.transfer"}}
diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less
index e986c41bf0..c10e8e59df 100644
--- a/web_src/less/_repository.less
+++ b/web_src/less/_repository.less
@@ -2796,7 +2796,10 @@
}
#transfer-repo-modal,
-#delete-repo-modal {
+#delete-repo-modal,
+#delete-wiki-modal,
+#convert-fork-repo-modal,
+#convert-mirror-repo-modal {
.ui.message {
width: 100% !important;
}