mirror of
https://github.com/go-gitea/gitea
synced 2024-11-21 23:03:39 +01:00
Handle edge case and CI feedback
This commit is contained in:
parent
a82d2feac9
commit
1ad8de7ac7
3 changed files with 12 additions and 1 deletions
|
@ -420,6 +420,7 @@ func UpdateBranch(ctx *context.APIContext) {
|
|||
// in: path
|
||||
// description: name of the branch
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: body
|
||||
// in: body
|
||||
// schema:
|
||||
|
@ -470,6 +471,12 @@ func UpdateBranch(ctx *context.APIContext) {
|
|||
|
||||
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
|
||||
if err != nil {
|
||||
if git.IsErrBranchNotExist(err) {
|
||||
// This could occur if the client passes a non-existent branch and we
|
||||
// skip executing the branch that contains the RenameBranch() call.
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
|
||||
return
|
||||
}
|
||||
|
|
3
templates/swagger/v1_json.tmpl
generated
3
templates/swagger/v1_json.tmpl
generated
|
@ -5025,7 +5025,8 @@
|
|||
"type": "string",
|
||||
"description": "name of the branch",
|
||||
"name": "branch",
|
||||
"in": "path"
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
|
|
|
@ -218,6 +218,9 @@ func TestAPIUpdateBranch(t *testing.T) {
|
|||
branchWasUnchanged := slices.ContainsFunc(branches, func(b *git_model.Branch) bool { return b.Name == "master" })
|
||||
assert.True(t, branchWasUnchanged, "master branch shouldn't have been renamed")
|
||||
})
|
||||
t.Run("UpdateBranchWithNonExistentBranchAndNewNameIsTheEmptyString", func(t *testing.T) {
|
||||
testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "", http.StatusNotFound)
|
||||
})
|
||||
t.Run("RenameBranchNormalScenario", func(t *testing.T) {
|
||||
resp := testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusOK)
|
||||
var branch api.Branch
|
||||
|
|
Loading…
Reference in a new issue