summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-22 14:39:09 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-22 14:39:09 +0300
commit0455391add2032dddc7353d1b0ae36d591818d3f (patch)
treefac9a9328a36b7f54ace89dd992e50a6f35470bc
parente089b11b7a4026acc7706e519682f4b7141b2bcd (diff)
downloadgitlab-ce-0455391add2032dddc7353d1b0ae36d591818d3f.tar.gz
Improve branch-removal logic
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/projects/branches_controller.rb9
-rw-r--r--app/services/delete_branch_service.rb4
-rw-r--r--app/views/projects/branches/_branch.html.haml4
3 files changed, 8 insertions, 9 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
index 6a6cbe48184..00811f17adb 100644
--- a/app/controllers/projects/branches_controller.rb
+++ b/app/controllers/projects/branches_controller.rb
@@ -4,8 +4,7 @@ class Projects::BranchesController < Projects::ApplicationController
before_filter :require_non_empty_project
before_filter :authorize_code_access!
- before_filter :authorize_push!, only: [:create]
- before_filter :authorize_admin_project!, only: [:destroy]
+ before_filter :authorize_push!, only: [:create, :destroy]
def index
@branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
@@ -22,11 +21,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
def destroy
- branch = @repository.find_branch(params[:id])
-
- if branch && @repository.rm_branch(branch.name)
- Event.create_ref_event(@project, current_user, branch, 'rm')
- end
+ DeleteBranchService.new.execute(project, params[:id], current_user)
respond_to do |format|
format.html { redirect_to project_branches_path(@project) }
diff --git a/app/services/delete_branch_service.rb b/app/services/delete_branch_service.rb
index 9f48ab4b60d..ce2d8093dff 100644
--- a/app/services/delete_branch_service.rb
+++ b/app/services/delete_branch_service.rb
@@ -8,6 +8,10 @@ class DeleteBranchService
return error('No such branch')
end
+ if branch_name == repository.root_ref
+ return error('Cannot remove HEAD branch')
+ end
+
# Dont allow remove of protected branch
if project.protected_branch?(branch_name)
return error('Protected branch cant be removed')
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index f0731977098..87f4dd88c27 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -16,8 +16,8 @@
%i.icon-copy
Compare
- - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref
- = link_to project_branch_path(@project, branch.name), class: 'btn btn-grouped btn-small remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do
+ - if can_remove_branch?(@project, branch.name)
+ = link_to project_branch_path(@project, branch.name), class: 'btn btn-grouped btn-small btn-remove remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do
%i.icon-trash
- if commit