summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-23 12:51:09 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-23 12:51:09 +0000
commita56e35e9250b23c8949780fb2f5d8ed236c6d536 (patch)
treeece8bbc0477cbdfc110a85df6f0f7bffb36c6412
parent68942dbb3dcbb41f7d03137f94868d1b662dfd4b (diff)
parentd575ee3e90a7b13e4ed29fdea0b611ae8ef50496 (diff)
downloadgitlab-ce-a56e35e9250b23c8949780fb2f5d8ed236c6d536.tar.gz
Merge branch 'api-branch-deletion' into 'master'
Api branch deletion Fixes #1127
-rw-r--r--doc/api/branches.md14
-rw-r--r--lib/api/branches.rb8
-rw-r--r--spec/requests/api/branches_spec.rb23
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