Commit 7aaa8e8d authored by Marin Jankovski's avatar Marin Jankovski

Add comments around code to make it easier to understand, move remove_branch...

Add comments around code to make it easier to understand, move remove_branch code into a separate method.
parent bd2a29a8
...@@ -30,12 +30,14 @@ module Gitlab ...@@ -30,12 +30,14 @@ module Gitlab
in_locked_and_timed_satellite do |merge_repo| in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo) prepare_satellite!(merge_repo)
# If rebase before merge
# Attempt a rebase and return if succesful.
# If unsuccesful, continue with regular merge.
if merge_request.should_rebase if merge_request.should_rebase
if rebase_in_satellite!(merge_repo) if rebase_in_satellite!(merge_repo)
merge_repo.git.push(default_options, :origin, merge_request.target_branch) merge_repo.git.push(default_options, :origin, merge_request.target_branch)
remove_source_branch(merge_repo)
return true return true
else
prepare_satellite!(merge_repo)
end end
end end
...@@ -45,10 +47,7 @@ module Gitlab ...@@ -45,10 +47,7 @@ module Gitlab
merge_repo.git.push(default_options, :origin, merge_request.target_branch) merge_repo.git.push(default_options, :origin, merge_request.target_branch)
# remove source branch # remove source branch
if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) && !merge_request.for_fork? remove_source_branch(merge_repo)
# will raise CommandFailed when push fails
merge_repo.git.push(default_options, :origin, ":#{merge_request.source_branch}")
end
# merge, push and branch removal successful # merge, push and branch removal successful
true true
end end
...@@ -145,6 +144,21 @@ module Gitlab ...@@ -145,6 +144,21 @@ module Gitlab
handle_exception(ex) handle_exception(ex)
end end
# Rebases before merging the source_branch into the target_branch in the satellite.
# Before starting the rebase, clears out the satellite.
# Returns false if rebase cannot be done cleanly and resets the satellite.
# Returns true otherwise.
# Eg. of clean rebase
# source_branch: feature
# target_branch: master
#
# git checkout feature
# git merge master
# git rebase master
# git checkout master
# git merge feature
# git push remote master
def rebase_in_satellite!(repo) def rebase_in_satellite!(repo)
update_satellite_source_and_target!(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.checkout(default_options({b: true}), merge_request.source_branch, "source/#{merge_request.source_branch}")
...@@ -158,6 +172,7 @@ module Gitlab ...@@ -158,6 +172,7 @@ module Gitlab
else else
repo.git.rebase(default_options, "--abort") 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." Gitlab::AppLogger.info "Rebasing in in #{merge_request.source_project.path_with_namespace} MR!#{merge_request.id} aborted, rebase manually."
prepare_satellite!(repo)
false false
end end
rescue Grit::Git::CommandFailed => ex rescue Grit::Git::CommandFailed => ex
...@@ -172,6 +187,15 @@ module Gitlab ...@@ -172,6 +187,15 @@ module Gitlab
rescue Grit::Git::CommandFailed => ex rescue Grit::Git::CommandFailed => ex
handle_exception(ex) handle_exception(ex)
end end
def remove_source_branch(repo)
if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) && !merge_request.for_fork?
# will raise CommandFailed when push fails
repo.git.push(default_options, :origin, ":#{merge_request.source_branch}")
end
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
end
end end
end end
end end
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