MCPcopy Create free account
hub / github.com/gogs/gogs / ForkPost

Function ForkPost

internal/route/repo/pull.go:96–154  ·  view source on GitHub ↗
(c *context.Context, f form.CreateRepo)

Source from the content-addressed store, hash-verified

94}
95
96func 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())

Callers

nothing calls this directly

Calls 15

HasForkedRepoFunction · 0.92
ForkRepositoryFunction · 0.92
IsErrReachLimitOfRepoFunction · 0.92
IsErrRepoAlreadyExistFunction · 0.92
IsErrNameNotAllowedFunction · 0.92
parseBaseRepositoryFunction · 0.85
checkContextUserFunction · 0.85
TrMethod · 0.80
HasErrorMethod · 0.80
HTMLMethod · 0.80
RedirectMethod · 0.80
IsOrganizationMethod · 0.80

Tested by

no test coverage detected