Commit 99b83964 authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Decoupled model-facing logic from Gitlab::Git on squash/rebase

parent 707225fa
...@@ -38,5 +38,20 @@ module EE ...@@ -38,5 +38,20 @@ module EE
def delete_remote_branches(remote, branches) def delete_remote_branches(remote, branches)
gitlab_shell.delete_remote_branches(repository_storage_path, disk_path, remote, branches) gitlab_shell.delete_remote_branches(repository_storage_path, disk_path, remote, branches)
end end
def rebase(user, merge_request)
raw.rebase(user, merge_request.id, branch: merge_request.source_branch,
branch_sha: merge_request.source_branch_sha,
remote_repository: merge_request.target_project.repository.raw,
remote_branch: merge_request.target_branch)
end
def squash(user, merge_request)
raw.squash(user, merge_request.id, branch: merge_request.target_branch,
start_sha: merge_request.diff_start_sha,
end_sha: merge_request.diff_head_sha,
author: merge_request.author,
message: merge_request.title)
end
end end
end end
...@@ -16,11 +16,7 @@ module MergeRequests ...@@ -16,11 +16,7 @@ module MergeRequests
return false return false
end end
rebase_sha = repository.rebase(current_user, merge_request.id, rebase_sha = repository.rebase(current_user, merge_request)
source_branch: merge_request.source_branch,
source_branch_sha: merge_request.source_branch_sha,
target_repository: target_project.repository.raw,
target_branch: merge_request.target_branch)
merge_request.update_attributes(rebase_commit_sha: rebase_sha) merge_request.update_attributes(rebase_commit_sha: rebase_sha)
......
...@@ -22,12 +22,7 @@ module MergeRequests ...@@ -22,12 +22,7 @@ module MergeRequests
return error('Squash task canceled: another squash is already in progress.') return error('Squash task canceled: another squash is already in progress.')
end end
squash_sha = repository.squash(current_user, merge_request.id, squash_sha = repository.squash(current_user, merge_request)
target_branch: merge_request.target_branch,
start_sha: merge_request.diff_start_sha,
end_sha: merge_request.diff_head_sha,
author: merge_request.author,
message: merge_request.title)
success(squash_sha: squash_sha) success(squash_sha: squash_sha)
rescue => e rescue => e
......
...@@ -1212,20 +1212,20 @@ module Gitlab ...@@ -1212,20 +1212,20 @@ module Gitlab
raise GitError.new("Could not fsck repository:\n#{output}") unless status.zero? raise GitError.new("Could not fsck repository:\n#{output}") unless status.zero?
end end
def rebase(user, rebase_id, source_branch:, source_branch_sha:, target_repository:, target_branch:) def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
rebase_path = rebase_dir_path(rebase_id) rebase_path = rebase_dir_path(rebase_id)
env = git_env_for_user(user) env = git_env_for_user(user)
with_worktree(rebase_path, source_branch, env: env) do with_worktree(rebase_path, branch, env: env) do
run_git!( run_git!(
%W(pull --rebase #{target_repository.path} #{target_branch}), %W(pull --rebase #{remote_repository.path} #{remote_branch}),
chdir: rebase_path, env: env chdir: rebase_path, env: env
) )
rebase_sha = run_git!(%w(rev-parse HEAD), chdir: rebase_path, env: env).strip rebase_sha = run_git!(%w(rev-parse HEAD), chdir: rebase_path, env: env).strip
Gitlab::Git::OperationService.new(user, self) Gitlab::Git::OperationService.new(user, self)
.update_branch(source_branch, rebase_sha, source_branch_sha) .update_branch(branch, rebase_sha, branch_sha)
rebase_sha rebase_sha
end end
...@@ -1235,7 +1235,7 @@ module Gitlab ...@@ -1235,7 +1235,7 @@ module Gitlab
fresh_worktree?(rebase_dir_path(rebase_id)) fresh_worktree?(rebase_dir_path(rebase_id))
end end
def squash(user, squash_id, target_branch:, start_sha:, end_sha:, author:, message:) def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:)
squash_path = squash_dir_path(squash_id) squash_path = squash_dir_path(squash_id)
env = git_env_for_user(user).merge( env = git_env_for_user(user).merge(
'GIT_AUTHOR_NAME' => author.name, 'GIT_AUTHOR_NAME' => author.name,
...@@ -1246,7 +1246,7 @@ module Gitlab ...@@ -1246,7 +1246,7 @@ module Gitlab
%W(diff --name-only --diff-filter=a --binary #{diff_range}) %W(diff --name-only --diff-filter=a --binary #{diff_range})
).chomp ).chomp
with_worktree(squash_path, target_branch, sparse_checkout_files: diff_files, env: env) do with_worktree(squash_path, branch, sparse_checkout_files: diff_files, env: env) do
# Apply diff of the `diff_range` to the worktree # Apply diff of the `diff_range` to the worktree
diff = run_git!(%W(diff --binary #{diff_range})) diff = run_git!(%W(diff --binary #{diff_range}))
run_git!(%w(apply --index), chdir: squash_path, env: env) do |stdin| run_git!(%w(apply --index), chdir: squash_path, env: env) do |stdin|
......
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