Commit 220f1ed5 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rebase_using_custom_worktree' into 'master'

Rebase using git worktree

Closes #1604

See merge request gitlab-org/gitlab-ee!2962
parents d0b8999d 74d435c6
......@@ -17,14 +17,14 @@ module MergeRequests
end
run_git_command(
%W(clone -b #{merge_request.source_branch} -- #{source_project.repository.path_to_repo} #{tree_path}),
nil,
%W(worktree add --detach #{tree_path} #{merge_request.source_branch}),
repository.path_to_repo,
git_env,
'clone repository for rebase'
'add worktree for rebase'
)
run_git_command(
%W(pull --rebase #{target_project.repository.path_to_repo} #{merge_request.target_branch}),
%W(rebase #{merge_request.target_branch}),
tree_path,
git_env.merge('GIT_COMMITTER_NAME' => current_user.name,
'GIT_COMMITTER_EMAIL' => current_user.email),
......@@ -32,20 +32,16 @@ module MergeRequests
)
rebase_sha = run_git_command(
%W(rev-parse #{merge_request.source_branch}),
%w(rev-parse HEAD),
tree_path,
git_env,
'get SHA of rebased branch'
)
merge_request.update_attributes(rebase_commit_sha: rebase_sha)
Gitlab::Git::OperationService.new(current_user, project.repository.raw_repository)
.update_branch(merge_request.source_branch, rebase_sha, merge_request.source_branch_sha)
run_git_command(
%W(push -f origin #{merge_request.source_branch}),
tree_path,
git_env,
'push rebased branch'
)
merge_request.update_attributes(rebase_commit_sha: rebase_sha)
true
rescue GitCommandError
......@@ -58,6 +54,8 @@ module MergeRequests
clean_dir
end
private
def tree_path
@tree_path ||= merge_request.rebase_dir_path
end
......
---
title: Improve performance of rebasing by using worktree
merge_request:
author:
type: changed
......@@ -91,6 +91,11 @@ module Gitlab
end
end
def update_branch(branch_name, newrev, oldrev)
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
update_ref_in_hooks(ref, newrev, oldrev)
end
private
# Returns [newrev, should_run_after_create, should_run_after_create_branch]
......
......@@ -95,7 +95,7 @@ describe MergeRequests::RebaseService do
context 'git commands' do
it 'sets GL_REPOSITORY env variable when calling git commands' do
expect_any_instance_of(described_class)
.to receive(:run_git_command).exactly(4).with(
.to receive(:run_git_command).exactly(3).with(
anything,
anything,
hash_including('GL_REPOSITORY'),
......
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