Skip to content

Commit 0f7e617

Browse files
committed
Return 404 when deleting non-existent branch through api
1 parent 08254cf commit 0f7e617

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

services/repository/branch.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
609609
return fmt.Errorf("DeleteBranch: %v", err)
610610
}
611611
}
612+
if notExist {
613+
return git.ErrBranchNotExist{
614+
Name: branchName,
615+
}
616+
}
612617
if branchCommit == nil {
613618
return nil
614619
}
@@ -618,6 +623,11 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
618623
return err
619624
}
620625

626+
if notExist {
627+
return git.ErrBranchNotExist{
628+
Name: branchName,
629+
}
630+
}
621631
if branchCommit == nil {
622632
return nil
623633
}

tests/integration/api_branch_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ func TestAPIBranchProtection(t *testing.T) {
402402
// Test branch deletion
403403
testAPIDeleteBranch(t, "master", http.StatusForbidden)
404404
testAPIDeleteBranch(t, "branch2", http.StatusNoContent)
405+
testAPIDeleteBranch(t, "branch2", http.StatusNotFound)
405406
}
406407

407408
func TestAPICreateBranchWithSyncBranches(t *testing.T) {

0 commit comments

Comments
 (0)