Commit 0b51f3ce authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'extract-ee-repository-rb' into 'master'

Extract some EE-specific functionality in app/models/repository.rb

See merge request !1171
parents e419b30d 325a2fb7
module RepositoryMirroring
def storage_path
@project.repository_storage_path
end
def push_remote_branches(remote, branches)
gitlab_shell.push_remote_branches(storage_path, path_with_namespace, remote, branches)
end
def delete_remote_branches(remote, branches)
gitlab_shell.delete_remote_branches(storage_path, path_with_namespace, remote, branches)
end
def add_remote(name, url)
raw_repository.remote_add(name, url)
rescue Rugged::ConfigError
raw_repository.remote_update(name, url: url)
end
def remove_remote(name)
raw_repository.remote_delete(name)
true
rescue Rugged::ConfigError
false
end
def set_remote_as_mirror(name)
config = raw_repository.rugged.config
# This is used by Gitlab Geo to define repository as equivalent as "git clone --mirror"
config["remote.#{name}.fetch"] = 'refs/*:refs/*'
config["remote.#{name}.mirror"] = true
config["remote.#{name}.prune"] = true
end
def fetch_remote(remote, forced: false, no_tags: false)
gitlab_shell.fetch_remote(storage_path, path_with_namespace, remote, forced: forced, no_tags: no_tags)
end
def remote_tags(remote)
gitlab_shell.list_remote_tags(storage_path, path_with_namespace, remote).map do |name, target|
Gitlab::Git::Tag.new(raw_repository, name, target)
end
end
def remote_branches(remote_name)
branches = []
rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref|
name = ref.name.sub(/\Arefs\/remotes\/#{remote_name}\//, '')
begin
branches << Gitlab::Git::Branch.new(raw_repository, name, ref.target)
rescue Rugged::ReferenceError
# Omit invalid branch
end
end
branches
end
end
...@@ -5,6 +5,7 @@ require 'forwardable' ...@@ -5,6 +5,7 @@ require 'forwardable'
class Repository class Repository
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include Elastic::RepositoriesSearch include Elastic::RepositoriesSearch
include RepositoryMirroring
attr_accessor :path_with_namespace, :project attr_accessor :path_with_namespace, :project
...@@ -70,10 +71,6 @@ class Repository ...@@ -70,10 +71,6 @@ class Repository
@raw_repository ||= Gitlab::Git::Repository.new(path_to_repo) @raw_repository ||= Gitlab::Git::Repository.new(path_to_repo)
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(
...@@ -185,10 +182,6 @@ class Repository ...@@ -185,10 +182,6 @@ 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)
newrev = commit(target).try(:id) newrev = commit(target).try(:id)
options = { message: message, tagger: user_to_committer(user) } if message options = { message: message, tagger: user_to_committer(user) } if message
...@@ -210,10 +203,6 @@ class Repository ...@@ -210,10 +203,6 @@ 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(user, tag_name) def rm_tag(user, tag_name)
before_remove_tag before_remove_tag
tag = find_tag(tag_name) tag = find_tag(tag_name)
...@@ -224,40 +213,6 @@ class Repository ...@@ -224,40 +213,6 @@ class Repository
true true
end end
def config
raw_repository.rugged.config
end
def add_remote(name, url)
raw_repository.remote_add(name, url)
rescue Rugged::ConfigError
raw_repository.remote_update(name, url: url)
end
def remove_remote(name)
raw_repository.remote_delete(name)
true
rescue Rugged::ConfigError
false
end
def set_remote_as_mirror(name)
# This is used by Gitlab Geo to define repository as equivalent as "git clone --mirror"
config["remote.#{name}.fetch"] = 'refs/*:refs/*'
config["remote.#{name}.mirror"] = true
config["remote.#{name}.prune"] = true
end
def fetch_remote(remote, forced: false, no_tags: false)
gitlab_shell.fetch_remote(storage_path, path_with_namespace, remote, forced: forced, no_tags: no_tags)
end
def remote_tags(remote)
gitlab_shell.list_remote_tags(storage_path, path_with_namespace, remote).map do |name, target|
Gitlab::Git::Tag.new(raw_repository, name, target)
end
end
def ref_names def ref_names
branch_names + tag_names branch_names + tag_names
end end
...@@ -805,22 +760,6 @@ class Repository ...@@ -805,22 +760,6 @@ class Repository
alias_method :branches, :local_branches alias_method :branches, :local_branches
def remote_branches(remote_name)
branches = []
rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref|
name = ref.name.sub(/\Arefs\/remotes\/#{remote_name}\//, '')
begin
branches << Gitlab::Git::Branch.new(raw_repository, name, ref.target)
rescue Rugged::ReferenceError
# Omit invalid branch
end
end
branches
end
def tags def tags
@tags ||= raw_repository.tags @tags ||= raw_repository.tags
end end
......
...@@ -50,7 +50,8 @@ describe RemoteMirror do ...@@ -50,7 +50,8 @@ describe RemoteMirror do
mirror.update_attribute(:url, 'http://foo:baz@test.com') mirror.update_attribute(:url, 'http://foo:baz@test.com')
expect(repo.config["remote.#{mirror.ref_name}.url"]).to eq('http://foo:baz@test.com') config = repo.raw_repository.rugged.config
expect(config["remote.#{mirror.ref_name}.url"]).to eq('http://foo:baz@test.com')
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