diff options
-rw-r--r-- | doc/api/branches.md | 14 | ||||
-rw-r--r-- | lib/api/branches.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/branches_spec.rb | 23 |
3 files changed, 43 insertions, 2 deletions
diff --git a/doc/api/branches.md b/doc/api/branches.md index da9d4193f20..bb2d3fec09d 100644 --- a/doc/api/branches.md +++ b/doc/api/branches.md @@ -199,3 +199,17 @@ Parameters: "protected": false } ``` + +## Delete repository branch + + +``` +DELETE /projects/:id/repository/branches/:branch +``` + +Parameters: + ++ `id` (required) - The ID of a project ++ `branch` (required) - The name of the branch + +It return 200 if succeed or 405 if failed with error message explaining reason. diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 32597eb94c4..b32a4aa7bc2 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -94,7 +94,13 @@ module API # DELETE /projects/:id/repository/branches/:branch delete ":id/repository/branches/:branch" do authorize_push_project - DeleteBranchService.new.execute(user_project, params[:branch], current_user) + result = DeleteBranchService.new.execute(user_project, params[:branch], current_user) + + if result[:state] == :success + true + else + render_api_error!(result[:message], 405) + end end end end diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index abf6a8646ec..72589da5d40 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -91,7 +91,6 @@ describe API::API, api: true do end end - describe "POST /projects/:id/repository/branches" do it "should create a new branch" do post api("/projects/#{project.id}/repository/branches", user), @@ -112,4 +111,26 @@ describe API::API, api: true do response.status.should == 403 end end + + describe "DELETE /projects/:id/repository/branches/:branch" do + before { Repository.any_instance.stub(rm_branch: true) } + + it "should remove branch" do + delete api("/projects/#{project.id}/repository/branches/new_design", user) + response.status.should == 200 + end + + it "should remove protected branch" do + project.protected_branches.create(name: 'new_design') + delete api("/projects/#{project.id}/repository/branches/new_design", user) + response.status.should == 405 + json_response['message'].should == 'Protected branch cant be removed' + end + + it "should not remove HEAD branch" do + delete api("/projects/#{project.id}/repository/branches/master", user) + response.status.should == 405 + json_response['message'].should == 'Cannot remove HEAD branch' + end + end end |