Skip to content

Commit 1ad8de7

Browse files
committed
Handle edge case and CI feedback
1 parent a82d2fe commit 1ad8de7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

routers/api/v1/repo/branch.go

+7
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ func UpdateBranch(ctx *context.APIContext) {
420420
// in: path
421421
// description: name of the branch
422422
// type: string
423+
// required: true
423424
// - name: body
424425
// in: body
425426
// schema:
@@ -470,6 +471,12 @@ func UpdateBranch(ctx *context.APIContext) {
470471

471472
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
472473
if err != nil {
474+
if git.IsErrBranchNotExist(err) {
475+
// This could occur if the client passes a non-existent branch and we
476+
// skip executing the branch that contains the RenameBranch() call.
477+
ctx.NotFound(err)
478+
return
479+
}
473480
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
474481
return
475482
}

templates/swagger/v1_json.tmpl

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_branch_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ func TestAPIUpdateBranch(t *testing.T) {
218218
branchWasUnchanged := slices.ContainsFunc(branches, func(b *git_model.Branch) bool { return b.Name == "master" })
219219
assert.True(t, branchWasUnchanged, "master branch shouldn't have been renamed")
220220
})
221+
t.Run("UpdateBranchWithNonExistentBranchAndNewNameIsTheEmptyString", func(t *testing.T) {
222+
testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "", http.StatusNotFound)
223+
})
221224
t.Run("RenameBranchNormalScenario", func(t *testing.T) {
222225
resp := testAPIUpdateBranch(t, "user2", "repo1", "branch2", "new-branch-name", http.StatusOK)
223226
var branch api.Branch

0 commit comments

Comments
 (0)