Skip to content

Commit 6d221ed

Browse files
committed
Handle edge case and CI feedback
1 parent b388d01 commit 6d221ed

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

routers/api/v1/repo/branch.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ func UpdateBranch(ctx *context.APIContext) {
410410
// in: path
411411
// description: name of the branch
412412
// type: string
413+
// required: true
413414
// - name: body
414415
// in: body
415416
// schema:
@@ -460,6 +461,12 @@ func UpdateBranch(ctx *context.APIContext) {
460461

461462
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
462463
if err != nil {
464+
if git.IsErrBranchNotExist(err) {
465+
// This could occur if the client passes a non-existent branch and we
466+
// skip executing the branch that contains the RenameBranch() call.
467+
ctx.NotFound(err)
468+
return
469+
}
463470
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
464471
return
465472
}

templates/swagger/v1_json.tmpl

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_branch_test.go

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

0 commit comments

Comments
 (0)