@@ -118,6 +118,21 @@ func DeleteBranch(ctx *context.APIContext) {
118
118
// "404":
119
119
// "$ref": "#/responses/notFound"
120
120
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
+
121
136
branchName := ctx .Params ("*" )
122
137
123
138
if ctx .Repo .Repository .IsEmpty {
@@ -195,17 +210,30 @@ func CreateBranch(ctx *context.APIContext) {
195
210
// responses:
196
211
// "201":
197
212
// "$ref": "#/responses/Branch"
213
+ // "403":
214
+ // description: The branch is archived or a mirror.
198
215
// "404":
199
216
// description: The old branch does not exist.
200
217
// "409":
201
218
// description: The branch with the same name already exists.
202
219
203
- opt := web .GetForm (ctx ).(* api.CreateBranchRepoOption )
204
220
if ctx .Repo .Repository .IsEmpty {
205
221
ctx .Error (http .StatusNotFound , "" , "Git Repository is empty." )
206
222
return
207
223
}
208
224
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
+
209
237
var oldCommit * git.Commit
210
238
var err error
211
239
@@ -313,7 +341,12 @@ func ListBranches(ctx *context.APIContext) {
313
341
314
342
listOptions := utils .GetListOptions (ctx )
315
343
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
+
317
350
branchOpts := git_model.FindBranchOptions {
318
351
ListOptions : listOptions ,
319
352
RepoID : ctx .Repo .Repository .ID ,
0 commit comments