diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 42ba3f478d..631376bdb4 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -584,14 +584,19 @@ settings.tracker_url_format = External Issue Tracker URL Format settings.tracker_url_format_desc = You can use placeholder {user} {repo} {index} for user name, repository name and issue index. settings.pulls_desc = Enable pull requests to accept public contributions settings.danger_zone = Danger Zone +settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name. +settings.convert = Convert To Regular Repository +settings.convert_desc = You can convert this mirror to a regular repository. This cannot be reversed. +settings.convert_notices_1 = - This operation will convert this repository mirror into a regular repository and cannot be undone. +settings.convert_succeed = Repository successfully converted. +settings.convert_failed = Unable to convert repository. settings.transfer = Transfer Ownership settings.transfer_desc = Transfer this repository to another user or to an organization in which you have admin rights. -settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name. -settings.delete = Delete This Repository -settings.delete_desc = Once you delete a repository, there is no going back. Please be certain. settings.transfer_notices_1 = - You will lose access if new owner is a individual user. settings.transfer_notices_2 = - You will conserve access if new owner is an organization and if you're one of the owners. settings.transfer_form_title = Please enter following information to confirm your operation: +settings.delete = Delete This Repository +settings.delete_desc = Once you delete a repository, there is no going back. Please be certain. settings.delete_notices_1 = - This operation CANNOT be undone. settings.delete_notices_2 = - This operation will permanently delete the everything of this repository, including Git data, issues, comments and accesses of collaborators. settings.delete_notices_fork_1 = - If this repository is public, all forks will become independent after deletion. diff --git a/models/repo.go b/models/repo.go index 4a8c8f0546..a08d3a4df1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -655,7 +655,12 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { return repo, UpdateRepository(repo, false) } - if err = createUpdateHook(repoPath); err != nil { + return CleanUpMigrateInfo(repo, repoPath) +} + +// Finish migrating repository with things that don't need to be done for mirrors. +func CleanUpMigrateInfo(repo *Repository, repoPath string) (*Repository, error) { + if err := createUpdateHook(repoPath); err != nil { return repo, fmt.Errorf("createUpdateHook: %v", err) } @@ -1615,6 +1620,11 @@ func MirrorUpdate() { } } +func DeleteMirrorByRepoID(repoId int64) error { + _, err := x.Delete(&Mirror{RepoID: repoId}) + return err +} + // GitFsck calls 'git fsck' to check repository health. func GitFsck() { if taskStatusPool.IsRunning(_GIT_FSCK) { diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 507984e56d..3712a088b0 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -141,6 +141,38 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") + case "convert": + if repo.Name != form.RepoName { + ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) + return + } + + if ctx.Repo.Owner.IsOrganization() { + if !ctx.Repo.Owner.IsOwnedBy(ctx.User.Id) { + ctx.Error(404) + return + } + } + + if !repo.IsMirror { + ctx.Error(404) + return + } + repo.IsMirror = false + + if _, err := models.CleanUpMigrateInfo(repo, models.RepoPath(ctx.Repo.Owner.Name, repo.Name)); err != nil { + ctx.RenderWithErr(ctx.Tr("settings.convert.failed"), SETTINGS_OPTIONS, &form) + return + } + + if err := models.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil { + ctx.RenderWithErr(ctx.Tr("settings.convert.failed"), SETTINGS_OPTIONS, &form) + return + } + log.Trace("Repository converted from mirror to regular: %s/%s", ctx.Repo.Owner.Name, repo.Name) + ctx.Flash.Success(ctx.Tr("repo.settings.convert_succeed")) + ctx.Redirect(setting.AppSubUrl + "/" + ctx.Repo.Owner.Name + "/" + repo.Name) + case "transfer": if repo.Name != form.RepoName { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), SETTINGS_OPTIONS, nil) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 4bb39bb07a..4bc422c340 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -138,6 +138,19 @@ {{.i18n.Tr "repo.settings.danger_zone"}}
+ {{if .Repository.IsMirror}} +
+
+ +
+
+
{{.i18n.Tr "repo.settings.convert"}}
+

{{.i18n.Tr "repo.settings.convert_desc"}}

+
+
+ +
+ {{end}}
@@ -165,6 +178,38 @@
+{{if .Repository.IsMirror}} + +{{end}} + +
+
{{.i18n.Tr "settings.cancel"}}
+ +
+ +
{{template "base/footer" .}}