Repository: go-gitea/gitea
File: routers/web/repo/setting/setting.go (Go)

Code before:
		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() {
			ctx.HTTPError(http.StatusNotFound)
			return
		}
		if repo.Name != form.RepoName {
			ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
			return
		}

		newOwner, err := user_model.GetUserByName(ctx, ctx.FormString("new_owner_name"))
		if err != nil {
			if user_model.IsErrUserNotExist(err) {
				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
				return
			}
			ctx.ServerError("IsUserExist", err)
			return
		}

		if !newOwner.CanCreateRepo() {
			limit := util.Iif(newOwner.MaxRepoCreation != -1, newOwner.MaxRepoCreation, setting.Repository.MaxCreationLimit)
			ctx.RenderWithErr(ctx.TrN(limit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", limit), tplSettingsOptions, nil)
			return
		}

		if newOwner.Type == user_model.UserTypeOrganization {
			if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
				// The user shouldn't know about this organization
				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
				return
			}
		}

		// Close the GitRepo if open
		if ctx.Repo.GitRepo != nil {
			ctx.Repo.GitRepo.Close()
			ctx.Repo.GitRepo = nil
		}

		oldFullname := repo.FullName()
		if err := repo_service.StartRepositoryTransfer(ctx, ctx.Doer, newOwner, repo, nil); err != nil {
			if repo_model.IsErrRepoAlreadyExist(err) {
				ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil)
			} else if repo_model.IsErrRepoTransferInProgress(err) {
				ctx.RenderWithErr(ctx.Tr("repo.settings.transfer_in_progress"), tplSettingsOptions, nil)
			} else if errors.Is(err, user_model.ErrBlockedUser) {

Review comment (suggestion):
```suggestion
			limit := util.Iif(newOwner.MaxRepoCreation >= 0, newOwner.MaxRepoCreation, setting.Repository.MaxCreationLimit)
```

Code after:
		ctx.ServerError("CleanUpMigrateInfo", err)
		return
	} else if err = repo_model.DeleteMirrorByRepoID(ctx, ctx.Repo.Repository.ID); err != nil {
		ctx.ServerError("DeleteMirrorByRepoID", err)
		return
	}
	log.Trace("Repository converted from mirror to regular: %s", repo.FullName())
	ctx.Flash.Success(ctx.Tr("repo.settings.convert_succeed"))
	ctx.Redirect(repo.Link())
}

func handleSettingsPostConvertFork(ctx *context.Context) {
	form := web.GetForm(ctx).(*forms.RepoSettingForm)
	repo := ctx.Repo.Repository
	if !ctx.Repo.IsOwner() {
		ctx.HTTPError(http.StatusNotFound)
		return
	}
	if err := repo.LoadOwner(ctx); 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.HTTPError(http.StatusNotFound)
		return
	}

	if !ctx.Repo.Owner.CanCreateRepo() {
		maxCreationLimit := ctx.Repo.Owner.MaxCreationLimit()
		msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
		ctx.Flash.Error(msg)
		ctx.Redirect(repo.Link() + "/settings")
		return
	}

	if err := repo_service.ConvertForkToNormalRepository(ctx, repo); err != nil {
		log.Error("Unable to convert repository %-v from fork. Error: %v", repo, err)
		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())
}