@@ -118,6 +118,21 @@ func DeleteBranch(ctx *context.APIContext) {
118118 // "404":
119119 // "$ref": "#/responses/notFound"
120120
121+ if ctx .Repo .Repository .IsEmpty {
122+ ctx .Error (http .StatusNotFound , "" , "Git Repository is empty." )
123+ return
124+ }
125+
126+ if ctx .Repo .Repository .IsArchived {
127+ ctx .Error (http .StatusForbidden , "" , "Git Repository is archived." )
128+ return
129+ }
130+
131+ if ctx .Repo .Repository .IsMirror {
132+ ctx .Error (http .StatusForbidden , "" , "Git Repository is a mirror." )
133+ return
134+ }
135+
121136 branchName := ctx .Params ("*" )
122137
123138 if ctx .Repo .Repository .IsEmpty {
@@ -195,17 +210,30 @@ func CreateBranch(ctx *context.APIContext) {
195210 // responses:
196211 // "201":
197212 // "$ref": "#/responses/Branch"
213+ // "403":
214+ // description: The branch is archived or a mirror.
198215 // "404":
199216 // description: The old branch does not exist.
200217 // "409":
201218 // description: The branch with the same name already exists.
202219
203- opt := web .GetForm (ctx ).(* api.CreateBranchRepoOption )
204220 if ctx .Repo .Repository .IsEmpty {
205221 ctx .Error (http .StatusNotFound , "" , "Git Repository is empty." )
206222 return
207223 }
208224
225+ if ctx .Repo .Repository .IsArchived {
226+ ctx .Error (http .StatusForbidden , "" , "Git Repository is archived." )
227+ return
228+ }
229+
230+ if ctx .Repo .Repository .IsMirror {
231+ ctx .Error (http .StatusForbidden , "" , "Git Repository is a mirror." )
232+ return
233+ }
234+
235+ opt := web .GetForm (ctx ).(* api.CreateBranchRepoOption )
236+
209237 var oldCommit * git.Commit
210238 var err error
211239
@@ -313,7 +341,12 @@ func ListBranches(ctx *context.APIContext) {
313341
314342 listOptions := utils .GetListOptions (ctx )
315343
316- if ! ctx .Repo .Repository .IsEmpty && ctx .Repo .GitRepo != nil {
344+ if ! ctx .Repo .Repository .IsEmpty {
345+ if ctx .Repo .GitRepo == nil {
346+ ctx .Error (http .StatusInternalServerError , "Load git repository failed" , nil )
347+ return
348+ }
349+
317350 branchOpts := git_model.FindBranchOptions {
318351 ListOptions : listOptions ,
319352 RepoID : ctx .Repo .Repository .ID ,
0 commit comments