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
in_locked_and_timed_satellite do |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 rebase_in_satellite!(merge_repo)
merge_repo.git.push(default_options, :origin, merge_request.target_branch)
remove_source_branch(merge_repo)
return true
else
prepare_satellite!(merge_repo)
end
end
......@@ -45,10 +47,7 @@ module Gitlab
merge_repo.git.push(default_options, :origin, merge_request.target_branch)
# remove source branch
if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) && !merge_request.for_fork?
# will raise CommandFailed when push fails
merge_repo.git.push(default_options, :origin, ":#{merge_request.source_branch}")
end
remove_source_branch(merge_repo)
# merge, push and branch removal successful
true
end
......@@ -145,6 +144,21 @@ module Gitlab
handle_exception(ex)
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)
update_satellite_source_and_target!(repo)
repo.git.checkout(default_options({b: true}), merge_request.source_branch, "source/#{merge_request.source_branch}")
......@@ -158,6 +172,7 @@ module Gitlab
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."
prepare_satellite!(repo)
false
end
rescue Grit::Git::CommandFailed => ex
......@@ -172,6 +187,15 @@ module Gitlab
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
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
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