@@ -177,23 +177,18 @@ func CreateBranch(ctx *context.APIContext) {
177
177
}
178
178
179
179
err := repo_service .CreateNewBranch (ctx .User , ctx .Repo .Repository , opt .OldBranchName , opt .BranchName )
180
-
181
180
if err != nil {
182
181
if models .IsErrBranchDoesNotExist (err ) {
183
182
ctx .Error (http .StatusNotFound , "" , "The old branch does not exist" )
184
183
}
185
184
if models .IsErrTagAlreadyExists (err ) {
186
185
ctx .Error (http .StatusConflict , "" , "The branch with the same tag already exists." )
187
-
188
186
} else if models .IsErrBranchAlreadyExists (err ) || git .IsErrPushOutOfDate (err ) {
189
187
ctx .Error (http .StatusConflict , "" , "The branch already exists." )
190
-
191
188
} else if models .IsErrBranchNameConflict (err ) {
192
189
ctx .Error (http .StatusConflict , "" , "The branch with the same name already exists." )
193
-
194
190
} else {
195
191
ctx .Error (http .StatusInternalServerError , "CreateRepoBranch" , err )
196
-
197
192
}
198
193
return
199
194
}
@@ -263,10 +258,15 @@ func ListBranches(ctx *context.APIContext) {
263
258
return
264
259
}
265
260
266
- apiBranches := make ([]* api.Branch , len (branches ))
261
+ apiBranches := make ([]* api.Branch , 0 , len (branches ))
267
262
for i := range branches {
268
263
c , err := branches [i ].GetCommit ()
269
264
if err != nil {
265
+ // Skip if this branch doesn't exist anymore.
266
+ if git .IsErrNotExist (err ) {
267
+ totalNumOfBranches --
268
+ continue
269
+ }
270
270
ctx .Error (http .StatusInternalServerError , "GetCommit" , err )
271
271
return
272
272
}
@@ -275,11 +275,12 @@ func ListBranches(ctx *context.APIContext) {
275
275
ctx .Error (http .StatusInternalServerError , "GetBranchProtection" , err )
276
276
return
277
277
}
278
- apiBranches [ i ] , err = convert .ToBranch (ctx .Repo .Repository , branches [i ], c , branchProtection , ctx .User , ctx .Repo .IsAdmin ())
278
+ apiBranch , err : = convert .ToBranch (ctx .Repo .Repository , branches [i ], c , branchProtection , ctx .User , ctx .Repo .IsAdmin ())
279
279
if err != nil {
280
280
ctx .Error (http .StatusInternalServerError , "convert.ToBranch" , err )
281
281
return
282
282
}
283
+ apiBranches = append (apiBranches , apiBranch )
283
284
}
284
285
285
286
ctx .SetLinkHeader (totalNumOfBranches , listOptions .PageSize )
@@ -532,7 +533,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
532
533
}
533
534
534
535
ctx .JSON (http .StatusCreated , convert .ToBranchProtection (bp ))
535
-
536
536
}
537
537
538
538
// EditBranchProtection edits a branch protection for a repo
0 commit comments