Commit e4f5b6df authored by Marin Jankovski's avatar Marin Jankovski

Do a simpler rebase, show rebase check box only for users how can push code.

parent 267896c3
......@@ -19,4 +19,14 @@ module BranchesHelper
current_user.can?(action, project)
end
def can_rebase?(project, branch_name)
if project.protected_branch? branch_name
can?(current_user, :push_code_to_protected_branches, project)
elsif can?(current_user, :push_code, project)
true
else
false
end
end
end
......@@ -24,7 +24,7 @@
= label_tag :should_remove_source_branch, class: "checkbox" do
= check_box_tag :should_remove_source_branch
Remove source-branch
- if @merge_request.source_project.merge_requests_rebase_enabled && !@merge_request.for_fork?
- if @merge_request.target_project.merge_requests_rebase_enabled && can_rebase?(@merge_request.target_project, @merge_request.target_branch)
.remove_branch_holder.pull-left
= label_tag :should_rebase, class: "checkbox" do
= check_box_tag :should_rebase
......
......@@ -35,7 +35,6 @@ module Gitlab
# If unsuccesful, continue with regular merge.
if merge_request.should_rebase
if rebase_in_satellite!(merge_repo)
merge_repo.git.push(default_options, :origin, merge_request.target_branch)
remove_source_branch(merge_repo)
return true
end
......@@ -154,21 +153,20 @@ module Gitlab
# target_branch: master
#
# git checkout feature
# git merge master
# git rebase master
# git checkout master
# git pull --rebase origin master
# git push origin feature:master
# git merge feature
# git push remote master
def rebase_in_satellite!(repo)
update_satellite_source_and_target!(repo)
repo.git.checkout(default_options({b: true}), merge_request.source_branch, "source/#{merge_request.source_branch}")
repo.git.merge(default_options({no_ff: true}), "origin/#{merge_request.target_branch}")
output, status = popen(%W(git rebase origin/#{merge_request.target_branch}), repo.working_dir)
output, status = popen(%W(git pull --rebase origin #{merge_request.target_branch}), repo.working_dir)
if status == 0
Gitlab::AppLogger.info "Rebasing before merge in #{merge_request.source_project.path_with_namespace} MR!#{merge_request.id}: #{output}."
repo.git.checkout(default_options, merge_request.target_branch)
repo.git.merge(default_options, "source/#{merge_request.source_branch}")
if merge_request.source_branch && merge_request.target_branch
repo.git.push(default_options, "origin", "#{merge_request.source_branch}:#{merge_request.target_branch}")
end
else
repo.git.rebase(default_options, "--abort")
Gitlab::AppLogger.info "Rebasing in in #{merge_request.source_project.path_with_namespace} MR!#{merge_request.id} aborted, rebase manually."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment