(c *context.Context, f form.CreateRepo)
| 94 | } |
| 95 | |
| 96 | func ForkPost(c *context.Context, f form.CreateRepo) { |
| 97 | c.Data["Title"] = c.Tr("new_fork") |
| 98 | |
| 99 | baseRepo := parseBaseRepository(c) |
| 100 | if c.Written() { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | ctxUser := checkContextUser(c, f.UserID) |
| 105 | if c.Written() { |
| 106 | return |
| 107 | } |
| 108 | c.Data["ContextUser"] = ctxUser |
| 109 | |
| 110 | if c.HasError() { |
| 111 | c.HTML(http.StatusBadRequest, tmplRepoPullsFork) |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | repo, has, err := database.HasForkedRepo(ctxUser.ID, baseRepo.ID) |
| 116 | if err != nil { |
| 117 | c.Error(err, "check forked repository") |
| 118 | return |
| 119 | } else if has { |
| 120 | c.Redirect(repo.Link()) |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | // Check ownership of organization. |
| 125 | if ctxUser.IsOrganization() && !ctxUser.IsOwnedBy(c.User.ID) { |
| 126 | c.Status(http.StatusForbidden) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | // Cannot fork to same owner |
| 131 | if ctxUser.ID == baseRepo.OwnerID { |
| 132 | c.RenderWithErr(c.Tr("repo.settings.cannot_fork_to_same_owner"), http.StatusUnprocessableEntity, tmplRepoPullsFork, &f) |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | repo, err = database.ForkRepository(c.User, ctxUser, baseRepo, f.RepoName, f.Description) |
| 137 | if err != nil { |
| 138 | c.Data["Err_RepoName"] = true |
| 139 | switch { |
| 140 | case database.IsErrReachLimitOfRepo(err): |
| 141 | c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", err.(database.ErrReachLimitOfRepo).Limit), http.StatusForbidden, tmplRepoPullsFork, &f) |
| 142 | case database.IsErrRepoAlreadyExist(err): |
| 143 | c.RenderWithErr(c.Tr("repo.settings.new_owner_has_same_repo"), http.StatusUnprocessableEntity, tmplRepoPullsFork, &f) |
| 144 | case database.IsErrNameNotAllowed(err): |
| 145 | c.RenderWithErr(c.Tr("repo.form.name_not_allowed", err.(database.ErrNameNotAllowed).Value()), http.StatusBadRequest, tmplRepoPullsFork, &f) |
| 146 | default: |
| 147 | c.Error(err, "fork repository") |
| 148 | } |
| 149 | return |
| 150 | } |
| 151 | |
| 152 | log.Trace("Repository forked from '%s' -> '%s'", baseRepo.FullName(), repo.FullName()) |
| 153 | c.Redirect(repo.Link()) |
nothing calls this directly
no test coverage detected