Commit d6bc1e2e authored by Ruben Davila's avatar Ruben Davila

Add missing `storage` argument to some methods in `Gitlab::Shell`

The affected methods are EE only and were basically related to the sync
of local and remote mirrors.
parent f1326cd1
...@@ -17,8 +17,6 @@ class Repository ...@@ -17,8 +17,6 @@ class Repository
attr_accessor :path_with_namespace, :project attr_accessor :path_with_namespace, :project
delegate :push_remote_branches, :delete_remote_branches, to: :gitlab_shell
def self.clean_old_archives def self.clean_old_archives
Gitlab::Metrics.measure(:clean_old_archives) do Gitlab::Metrics.measure(:clean_old_archives) do
repository_downloads_path = Gitlab.config.gitlab.repository_downloads_path repository_downloads_path = Gitlab.config.gitlab.repository_downloads_path
...@@ -44,10 +42,14 @@ class Repository ...@@ -44,10 +42,14 @@ class Repository
raw_repository.autocrlf = :input if raw_repository.autocrlf != :input raw_repository.autocrlf = :input if raw_repository.autocrlf != :input
end end
def storage_path
@project.repository_storage_path
end
# Return absolute path to repository # Return absolute path to repository
def path_to_repo def path_to_repo
@path_to_repo ||= File.expand_path( @path_to_repo ||= File.expand_path(
File.join(@project.repository_storage_path, path_with_namespace + ".git") File.join(storage_path, path_with_namespace + ".git")
) )
end end
...@@ -162,6 +164,10 @@ class Repository ...@@ -162,6 +164,10 @@ class Repository
find_branch(branch_name) find_branch(branch_name)
end end
def push_remote_branches(remote, branches)
gitlab_shell.push_remote_branches(storage_path, path_with_namespace, remote, branches)
end
def add_tag(user, tag_name, target, message = nil) def add_tag(user, tag_name, target, message = nil)
oldrev = Gitlab::Git::BLANK_SHA oldrev = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::TAG_REF_PREFIX + tag_name ref = Gitlab::Git::TAG_REF_PREFIX + tag_name
...@@ -194,6 +200,10 @@ class Repository ...@@ -194,6 +200,10 @@ class Repository
true true
end end
def delete_remote_branches(remote, branches)
gitlab_shell.delete_remote_branches(storage_path, path_with_namespace, remote, branches)
end
def rm_tag(tag_name) def rm_tag(tag_name)
before_remove_tag before_remove_tag
...@@ -230,17 +240,17 @@ class Repository ...@@ -230,17 +240,17 @@ class Repository
end end
def fetch_remote(remote, forced: false, no_tags: false) def fetch_remote(remote, forced: false, no_tags: false)
gitlab_shell.fetch_remote(path_with_namespace, remote, forced: forced, no_tags: no_tags) gitlab_shell.fetch_remote(storage_path, path_with_namespace, remote, forced: forced, no_tags: no_tags)
end end
def remote_tags(remote) def remote_tags(remote)
gitlab_shell.list_remote_tags(path_with_namespace, remote).map do |name, target| gitlab_shell.list_remote_tags(storage_path, path_with_namespace, remote).map do |name, target|
Gitlab::Git::Tag.new(name, target) Gitlab::Git::Tag.new(name, target)
end end
end end
def fetch_remote_forced!(remote) def fetch_remote_forced!(remote)
gitlab_shell.fetch_remote(path_with_namespace, remote, forced: true) gitlab_shell.fetch_remote(storage_path, path_with_namespace, remote, forced: true)
end end
def ref_names def ref_names
......
...@@ -49,11 +49,11 @@ module Projects ...@@ -49,11 +49,11 @@ module Projects
# Push the default branch first so it works fine when remote mirror is empty. # Push the default branch first so it works fine when remote mirror is empty.
branches.unshift(*default_branch) branches.unshift(*default_branch)
repository.push_remote_branches(project.path_with_namespace, mirror.ref_name, branches) repository.push_remote_branches(mirror.ref_name, branches)
end end
def delete_branches def delete_branches
repository.delete_remote_branches(project.path_with_namespace, mirror.ref_name, deleted_branches) repository.delete_remote_branches(mirror.ref_name, deleted_branches)
end end
def deleted_branches def deleted_branches
...@@ -101,11 +101,11 @@ module Projects ...@@ -101,11 +101,11 @@ module Projects
end end
def push_tags def push_tags
repository.push_remote_branches(project.path_with_namespace, mirror.ref_name, changed_tags) repository.push_remote_branches(mirror.ref_name, changed_tags)
end end
def delete_tags def delete_tags
repository.delete_remote_branches(project.path_with_namespace, mirror.ref_name, deleted_tags) repository.delete_remote_branches(mirror.ref_name, deleted_tags)
end end
def changed_tags def changed_tags
......
...@@ -46,8 +46,8 @@ module Gitlab ...@@ -46,8 +46,8 @@ module Gitlab
true true
end end
def list_remote_tags(name, remote) def list_remote_tags(storage, name, remote)
output, status = Popen::popen([gitlab_shell_projects_path, 'list-remote-tags', "#{name}.git", remote]) output, status = Popen::popen([gitlab_shell_projects_path, 'list-remote-tags', storage, "#{name}.git", remote])
tags_with_targets = [] tags_with_targets = []
raise Error, output unless status.zero? raise Error, output unless status.zero?
...@@ -83,8 +83,8 @@ module Gitlab ...@@ -83,8 +83,8 @@ module Gitlab
# Ex. # Ex.
# fetch_remote("gitlab/gitlab-ci", "upstream") # fetch_remote("gitlab/gitlab-ci", "upstream")
# #
def fetch_remote(name, remote, forced: false, no_tags: false) def fetch_remote(storage, name, remote, forced: false, no_tags: false)
args = [gitlab_shell_projects_path, 'fetch-remote', "#{name}.git", remote, '600'] args = [gitlab_shell_projects_path, 'fetch-remote', storage, "#{name}.git", remote, '600']
args << '--force' if forced args << '--force' if forced
args << '--no-tags' if no_tags args << '--no-tags' if no_tags
...@@ -261,8 +261,8 @@ module Gitlab ...@@ -261,8 +261,8 @@ module Gitlab
# Ex. # Ex.
# push_remote_branches('upstream', 'feature') # push_remote_branches('upstream', 'feature')
# #
def push_remote_branches(project_name, remote_name, branch_names) def push_remote_branches(storage, project_name, remote_name, branch_names)
args = [gitlab_shell_projects_path, 'push-branches', "#{project_name}.git", remote_name, *branch_names] args = [gitlab_shell_projects_path, 'push-branches', storage, "#{project_name}.git", remote_name, *branch_names]
output, status = Popen::popen(args) output, status = Popen::popen(args)
raise Error, output unless status.zero? raise Error, output unless status.zero?
true true
...@@ -277,8 +277,8 @@ module Gitlab ...@@ -277,8 +277,8 @@ module Gitlab
# Ex. # Ex.
# delete_remote_branches('upstream', 'feature') # delete_remote_branches('upstream', 'feature')
# #
def delete_remote_branches(project_name, remote_name, branch_names) def delete_remote_branches(storage, project_name, remote_name, branch_names)
args = [gitlab_shell_projects_path, 'delete-remote-branches', "#{project_name}.git", remote_name, *branch_names] args = [gitlab_shell_projects_path, 'delete-remote-branches', storage, "#{project_name}.git", remote_name, *branch_names]
output, status = Popen::popen(args) output, status = Popen::popen(args)
raise Error, output unless status.zero? raise Error, output unless status.zero?
true true
......
...@@ -1133,18 +1133,18 @@ describe Repository, models: true do ...@@ -1133,18 +1133,18 @@ describe Repository, models: true do
describe '#push_remote_branches' do describe '#push_remote_branches' do
it 'push branches to the remote repo' do it 'push branches to the remote repo' do
expect_any_instance_of(Gitlab::Shell).to receive(:push_remote_branches). expect_any_instance_of(Gitlab::Shell).to receive(:push_remote_branches).
with('project_name', 'remote_name', ['branch']) with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
repository.push_remote_branches('project_name', 'remote_name', ['branch']) repository.push_remote_branches('remote_name', ['branch'])
end end
end end
describe '#delete_remote_branches' do describe '#delete_remote_branches' do
it 'delete branches to the remote repo' do it 'delete branches to the remote repo' do
expect_any_instance_of(Gitlab::Shell).to receive(:delete_remote_branches). expect_any_instance_of(Gitlab::Shell).to receive(:delete_remote_branches).
with('project_name', 'remote_name', ['branch']) with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
repository.delete_remote_branches('project_name', 'remote_name', ['branch']) repository.delete_remote_branches('remote_name', ['branch'])
end end
end end
...@@ -1161,7 +1161,7 @@ describe Repository, models: true do ...@@ -1161,7 +1161,7 @@ describe Repository, models: true do
masterrev = repository.find_branch('master').target masterrev = repository.find_branch('master').target
expect_any_instance_of(Gitlab::Shell).to receive(:list_remote_tags). expect_any_instance_of(Gitlab::Shell).to receive(:list_remote_tags).
with(repository.path_with_namespace, 'upstream'). with(repository.storage_path, repository.path_with_namespace, 'upstream').
and_return({ 'v0.0.1' => masterrev }) and_return({ 'v0.0.1' => masterrev })
tags = repository.remote_tags('upstream') tags = repository.remote_tags('upstream')
......
...@@ -34,7 +34,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -34,7 +34,7 @@ describe Projects::UpdateRemoteMirrorService do
it "push all the branches the first time" do it "push all the branches the first time" do
allow(repository).to receive(:fetch_remote) allow(repository).to receive(:fetch_remote)
expect(repository).to receive(:push_remote_branches).with(project.path_with_namespace, remote_mirror.ref_name, local_branch_names) expect(repository).to receive(:push_remote_branches).with(remote_mirror.ref_name, local_branch_names)
subject.execute(remote_mirror) subject.execute(remote_mirror)
end end
...@@ -53,7 +53,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -53,7 +53,7 @@ describe Projects::UpdateRemoteMirrorService do
allow(repository).to receive(:fetch_remote) { sync_remote(repository, remote_mirror.ref_name, current_branches) } allow(repository).to receive(:fetch_remote) { sync_remote(repository, remote_mirror.ref_name, current_branches) }
create_branch(repository, 'my-new-branch') create_branch(repository, 'my-new-branch')
expect(repository).to receive(:push_remote_branches).with(project.path_with_namespace, remote_mirror.ref_name, ['my-new-branch']) expect(repository).to receive(:push_remote_branches).with(remote_mirror.ref_name, ['my-new-branch'])
subject.execute(remote_mirror) subject.execute(remote_mirror)
end end
...@@ -64,7 +64,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -64,7 +64,7 @@ describe Projects::UpdateRemoteMirrorService do
update_branch(repository, 'existing-branch') update_branch(repository, 'existing-branch')
end end
expect(repository).to receive(:push_remote_branches).with(project.path_with_namespace, remote_mirror.ref_name, ['existing-branch']) expect(repository).to receive(:push_remote_branches).with(remote_mirror.ref_name, ['existing-branch'])
subject.execute(remote_mirror) subject.execute(remote_mirror)
end end
...@@ -75,7 +75,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -75,7 +75,7 @@ describe Projects::UpdateRemoteMirrorService do
delete_branch(repository, 'existing-branch') delete_branch(repository, 'existing-branch')
end end
expect(repository).to receive(:delete_remote_branches).with(project.path_with_namespace, remote_mirror.ref_name, ['existing-branch']) expect(repository).to receive(:delete_remote_branches).with(remote_mirror.ref_name, ['existing-branch'])
subject.execute(remote_mirror) subject.execute(remote_mirror)
end end
...@@ -101,9 +101,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -101,9 +101,7 @@ describe Projects::UpdateRemoteMirrorService do
it 'should push tags to remote' do it 'should push tags to remote' do
allow(repository).to receive(:remote_tags) { {} } allow(repository).to receive(:remote_tags) { {} }
expect(repository).to receive(:push_remote_branches).with( expect(repository).to receive(:push_remote_branches).with(remote_mirror.ref_name, ['v1.0.0', 'v1.1.0'])
project.path_with_namespace, remote_mirror.ref_name, ['v1.0.0', 'v1.1.0']
)
subject.execute(remote_mirror) subject.execute(remote_mirror)
end end
...@@ -114,9 +112,7 @@ describe Projects::UpdateRemoteMirrorService do ...@@ -114,9 +112,7 @@ describe Projects::UpdateRemoteMirrorService do
allow(repository).to receive(:remote_tags) { generate_tags(repository, 'v1.0.0', 'v1.1.0') } allow(repository).to receive(:remote_tags) { generate_tags(repository, 'v1.0.0', 'v1.1.0') }
repository.rm_tag('v1.0.0') repository.rm_tag('v1.0.0')
expect(repository).to receive(:delete_remote_branches).with( expect(repository).to receive(:delete_remote_branches).with(remote_mirror.ref_name, ['v1.0.0'])
project.path_with_namespace, remote_mirror.ref_name, ['v1.0.0']
)
subject.execute(remote_mirror) subject.execute(remote_mirror)
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