mirror of
https://github.com/go-gitea/gitea
synced 2025-02-16 16:51:50 +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
|
// in: path
|
||||||
// description: name of the branch
|
// description: name of the branch
|
||||||
// type: string
|
// type: string
|
||||||
|
// required: true
|
||||||
// - name: body
|
// - name: body
|
||||||
// in: body
|
// in: body
|
||||||
// schema:
|
// schema:
|
||||||
|
@ -470,6 +471,12 @@ func UpdateBranch(ctx *context.APIContext) {
|
||||||
|
|
||||||
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
|
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
|
||||||
if err != nil {
|
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)
|
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
3
templates/swagger/v1_json.tmpl
generated
3
templates/swagger/v1_json.tmpl
generated
|
@ -5025,7 +5025,8 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the branch",
|
"description": "name of the branch",
|
||||||
"name": "branch",
|
"name": "branch",
|
||||||
"in": "path"
|
"in": "path",
|
||||||
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "body",
|
"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" })
|
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")
|
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) {
|
t.Run("RenameBranchNormalScenario", func(t *testing.T) {
|
||||||
resp := testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusOK)
|
resp := testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusOK)
|
||||||
var branch api.Branch
|
var branch api.Branch
|
||||||
|
|
Loading…
Add table
Reference in a new issue