limiting-factor
d92409ab11
chore: remove dead code from DELETE /repos/{owner}/{repo}/branches/{branch} ( #14163 )
...
The verification is duplicated from a few lines above.
The test coverage before the deletion as of e80687c98a is:
<pre>
<span>file: forgejo.org/routers/api/v1/repo/branch.go
</span><span style="color: rgb(125, 125, 125)"> 92: </span><span>func DeleteBranch(ctx *context.APIContext) </span><span style="color: rgb(25, 200, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 93: </span><span style="color: rgb(25, 200, 25)"> // swagger:operation DELETE /repos/{owner}/{repo}/branches/{branch} repository repoDeleteBranch</span>
<span style="color: rgb(125, 125, 125)"> 94: </span><span style="color: rgb(25, 200, 25)"> // ---</span>
<span style="color: rgb(125, 125, 125)"> 95: </span><span style="color: rgb(25, 200, 25)"> // summary: Delete a specific branch from a repository</span>
<span style="color: rgb(125, 125, 125)"> 96: </span><span style="color: rgb(25, 200, 25)"> // produces:</span>
<span style="color: rgb(125, 125, 125)"> 97: </span><span style="color: rgb(25, 200, 25)"> // - application/json</span>
<span style="color: rgb(125, 125, 125)"> 98: </span><span style="color: rgb(25, 200, 25)"> // parameters:</span>
<span style="color: rgb(125, 125, 125)"> 99: </span><span style="color: rgb(25, 200, 25)"> // - name: owner</span>
<span style="color: rgb(125, 125, 125)"> 100: </span><span style="color: rgb(25, 200, 25)"> // in: path</span>
<span style="color: rgb(125, 125, 125)"> 101: </span><span style="color: rgb(25, 200, 25)"> // description: owner of the repo</span>
<span style="color: rgb(125, 125, 125)"> 102: </span><span style="color: rgb(25, 200, 25)"> // type: string</span>
<span style="color: rgb(125, 125, 125)"> 103: </span><span style="color: rgb(25, 200, 25)"> // required: true</span>
<span style="color: rgb(125, 125, 125)"> 104: </span><span style="color: rgb(25, 200, 25)"> // - name: repo</span>
<span style="color: rgb(125, 125, 125)"> 105: </span><span style="color: rgb(25, 200, 25)"> // in: path</span>
<span style="color: rgb(125, 125, 125)"> 106: </span><span style="color: rgb(25, 200, 25)"> // description: name of the repo</span>
<span style="color: rgb(125, 125, 125)"> 107: </span><span style="color: rgb(25, 200, 25)"> // type: string</span>
<span style="color: rgb(125, 125, 125)"> 108: </span><span style="color: rgb(25, 200, 25)"> // required: true</span>
<span style="color: rgb(125, 125, 125)"> 109: </span><span style="color: rgb(25, 200, 25)"> // - name: branch</span>
<span style="color: rgb(125, 125, 125)"> 110: </span><span style="color: rgb(25, 200, 25)"> // in: path</span>
<span style="color: rgb(125, 125, 125)"> 111: </span><span style="color: rgb(25, 200, 25)"> // description: branch to delete</span>
<span style="color: rgb(125, 125, 125)"> 112: </span><span style="color: rgb(25, 200, 25)"> // type: string</span>
<span style="color: rgb(125, 125, 125)"> 113: </span><span style="color: rgb(25, 200, 25)"> // required: true</span>
<span style="color: rgb(125, 125, 125)"> 114: </span><span style="color: rgb(25, 200, 25)"> // responses:</span>
<span style="color: rgb(125, 125, 125)"> 115: </span><span style="color: rgb(25, 200, 25)"> // "204":</span>
<span style="color: rgb(125, 125, 125)"> 116: </span><span style="color: rgb(25, 200, 25)"> // "$ref": "#/responses/empty"</span>
<span style="color: rgb(125, 125, 125)"> 117: </span><span style="color: rgb(25, 200, 25)"> // "403":</span>
<span style="color: rgb(125, 125, 125)"> 118: </span><span style="color: rgb(25, 200, 25)"> // "$ref": "#/responses/error"</span>
<span style="color: rgb(125, 125, 125)"> 119: </span><span style="color: rgb(25, 200, 25)"> // "404":</span>
<span style="color: rgb(125, 125, 125)"> 120: </span><span style="color: rgb(25, 200, 25)"> // "$ref": "#/responses/notFound"</span>
<span style="color: rgb(125, 125, 125)"> 121: </span><span style="color: rgb(25, 200, 25)"> // "423":</span>
<span style="color: rgb(125, 125, 125)"> 122: </span><span style="color: rgb(25, 200, 25)"> // "$ref": "#/responses/repoArchivedError"</span>
<span style="color: rgb(125, 125, 125)"> 123: </span><span style="color: rgb(25, 200, 25)"> if ctx.Repo().Repository.IsEmpty </span><span style="color: rgb(255, 25, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 124: </span><span style="color: rgb(255, 25, 25)"> ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")</span>
<span style="color: rgb(125, 125, 125)"> 125: </span><span style="color: rgb(255, 25, 25)"> return</span>
<span style="color: rgb(125, 125, 125)"> 126: </span><span style="color: rgb(255, 25, 25)"> }</span><span></span>
<span style="color: rgb(125, 125, 125)"> 127: </span><span></span>
<span style="color: rgb(125, 125, 125)"> 128: </span><span> </span><span style="color: rgb(25, 200, 25)">if ctx.Repo().Repository.IsMirror </span><span style="color: rgb(25, 200, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 129: </span><span style="color: rgb(25, 200, 25)"> ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")</span>
<span style="color: rgb(125, 125, 125)"> 130: </span><span style="color: rgb(25, 200, 25)"> return</span>
<span style="color: rgb(125, 125, 125)"> 131: </span><span style="color: rgb(25, 200, 25)"> }</span><span></span>
<span style="color: rgb(125, 125, 125)"> 132: </span><span></span>
<span style="color: rgb(125, 125, 125)"> 133: </span><span> </span><span style="color: rgb(25, 200, 25)">branchName := ctx.Params("*")</span>
<span style="color: rgb(125, 125, 125)"> 134: </span><span style="color: rgb(25, 200, 25)"></span>
<span style="color: rgb(125, 125, 125)"> 135: </span><span style="color: rgb(25, 200, 25)"> // check whether branches of this repository has been synced</span>
<span style="color: rgb(125, 125, 125)"> 136: </span><span style="color: rgb(25, 200, 25)"> totalNumOfBranches, err := db.Count[git_model.Branch](ctx, git_model.FindBranchOptions{</span>
<span style="color: rgb(125, 125, 125)"> 137: </span><span style="color: rgb(25, 200, 25)"> RepoID: ctx.Repo().Repository.ID,</span>
<span style="color: rgb(125, 125, 125)"> 138: </span><span style="color: rgb(25, 200, 25)"> IsDeletedBranch: optional.Some(false),</span>
<span style="color: rgb(125, 125, 125)"> 139: </span><span style="color: rgb(25, 200, 25)"> })</span>
<span style="color: rgb(125, 125, 125)"> 140: </span><span style="color: rgb(25, 200, 25)"> if err != nil </span><span style="color: rgb(255, 25, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 141: </span><span style="color: rgb(255, 25, 25)"> ctx.Error(http.StatusInternalServerError, "CountBranches", err)</span>
<span style="color: rgb(125, 125, 125)"> 142: </span><span style="color: rgb(255, 25, 25)"> return</span>
<span style="color: rgb(125, 125, 125)"> 143: </span><span style="color: rgb(255, 25, 25)"> }</span><span></span>
<span style="color: rgb(125, 125, 125)"> 144: </span><span> </span><span style="color: rgb(25, 200, 25)">if totalNumOfBranches == 0 </span><span style="color: rgb(255, 25, 25)">{ // sync branches immediately because non-empty repository should have at least 1 branch</span>
<span style="color: rgb(125, 125, 125)"> 145: </span><span style="color: rgb(255, 25, 25)"> _, err = repo_module.SyncRepoBranches(ctx, ctx.Repo().Repository.ID, 0)</span>
<span style="color: rgb(125, 125, 125)"> 146: </span><span style="color: rgb(255, 25, 25)"> if err != nil </span><span style="color: rgb(255, 25, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 147: </span><span style="color: rgb(255, 25, 25)"> ctx.ServerError("SyncRepoBranches", err)</span>
<span style="color: rgb(125, 125, 125)"> 148: </span><span style="color: rgb(255, 25, 25)"> return</span>
<span style="color: rgb(125, 125, 125)"> 149: </span><span style="color: rgb(255, 25, 25)"> }</span><span></span>
<span style="color: rgb(125, 125, 125)"> 150: </span><span> }</span>
<span style="color: rgb(125, 125, 125)"> 151: </span><span></span>
<span style="color: rgb(125, 125, 125)"> 152: </span><span> </span><span style="color: rgb(25, 200, 25)">if ctx.Repo().Repository.IsMirror </span><span style="color: rgb(255, 25, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 153: </span><span style="color: rgb(255, 25, 25)"> ctx.Error(http.StatusForbidden, "IsMirrored", errors.New("can not delete branch of an mirror repository"))</span>
<span style="color: rgb(125, 125, 125)"> 154: </span><span style="color: rgb(255, 25, 25)"> return</span>
<span style="color: rgb(125, 125, 125)"> 155: </span><span style="color: rgb(255, 25, 25)"> }</span><span></span>
<span style="color: rgb(125, 125, 125)"> 156: </span><span></span>
<span style="color: rgb(125, 125, 125)"> 157: </span><span> </span><span style="color: rgb(25, 200, 25)">if err := repo_service.DeleteBranch(ctx, ctx.Doer(), ctx.Repo().Repository, ctx.Repo().GitRepo, branchName); err != nil </span><span style="color: rgb(25, 200, 25)">{</span>
<span style="color: rgb(125, 125, 125)"> 158: </span><span style="color: rgb(25, 200, 25)"> switch </span><span>{</span>
<span style="color: rgb(125, 125, 125)"> 159: </span><span> case git.IsErrBranchNotExist(err):</span><span style="color: rgb(255, 25, 25)"></span>
<span style="color: rgb(125, 125, 125)"> 160: </span><span style="color: rgb(255, 25, 25)"> ctx.NotFound(err)</span><span></span>
<span style="color: rgb(125, 125, 125)"> 161: </span><span> case errors.Is(err, repo_service.ErrBranchIsDefault):</span><span style="color: rgb(25, 200, 25)"></span>
<span style="color: rgb(125, 125, 125)"> 162: </span><span style="color: rgb(25, 200, 25)"> ctx.Error(http.StatusForbidden, "DefaultBranch", errors.New("can not delete default branch"))</span><span></span>
<span style="color: rgb(125, 125, 125)"> 163: </span><span> case errors.Is(err, git_model.ErrBranchIsProtected):</span><span style="color: rgb(255, 25, 25)"></span>
<span style="color: rgb(125, 125, 125)"> 164: </span><span style="color: rgb(255, 25, 25)"> ctx.Error(http.StatusForbidden, "IsProtectedBranch", errors.New("branch protected"))</span><span></span>
<span style="color: rgb(125, 125, 125)"> 165: </span><span> default:</span><span style="color: rgb(255, 25, 25)"></span>
<span style="color: rgb(125, 125, 125)"> 166: </span><span style="color: rgb(255, 25, 25)"> ctx.Error(http.StatusInternalServerError, "DeleteBranch", err)</span><span></span>
<span style="color: rgb(125, 125, 125)"> 167: </span><span> }</span>
<span style="color: rgb(125, 125, 125)"> 168: </span><span> </span><span style="color: rgb(25, 200, 25)">return</span><span></span>
<span style="color: rgb(125, 125, 125)"> 169: </span><span> }</span>
<span style="color: rgb(125, 125, 125)"> 170: </span><span></span>
<span style="color: rgb(125, 125, 125)"> 171: </span><span> </span><span style="color: rgb(25, 200, 25)">ctx.Status(http.StatusNoContent)</span><span></span>
<span style="color: rgb(125, 125, 125)"> 172: </span><span>}</span>
</pre>
### Compliance
- [x] I confirm that I make this contribution in accordance with [Forgejo's AI Agreement](9084720dc6/AIAgreement.md ).
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/14163
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
2026-08-29 23:18:24 +02:00