summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-29 10:44:40 +0200
committerGitHub <noreply@github.com>2022-04-29 10:44:40 +0200
commit334707fee90922e514485718088e3f0d55671c72 (patch)
tree02d753ee3d249f2ab03bd7489248915fa4f67381 /routers
parent[skip ci] Updated translations via Crowdin (diff)
downloadforgejo-334707fee90922e514485718088e3f0d55671c72.tar.xz
forgejo-334707fee90922e514485718088e3f0d55671c72.zip
Don't error when branch's commit doesn't exist (#19547)
* Don't error when branch's commit doesn't exist - If one of the branches no longer exists, don't throw an error, it's possible that the branch was destroyed during the process. Simply skip it and disregard it. - Resolves #19541 * Don't send empty objects * Use more minimal approach
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/branch.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 794d367b53..c030a896a7 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -259,10 +259,15 @@ func ListBranches(ctx *context.APIContext) {
return
}
- apiBranches := make([]*api.Branch, len(branches))
+ apiBranches := make([]*api.Branch, 0, len(branches))
for i := range branches {
c, err := branches[i].GetCommit()
if err != nil {
+ // Skip if this branch doesn't exist anymore.
+ if git.IsErrNotExist(err) {
+ totalNumOfBranches--
+ continue
+ }
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
@@ -271,11 +276,12 @@ func ListBranches(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
return
}
- apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
+ apiBranch, err := convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
if err != nil {
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
return
}
+ apiBranches = append(apiBranches, apiBranch)
}
ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize)