Commit 325a2fb7 authored by Nick Thomas's avatar Nick Thomas

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

parent 7fb9d56a
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'
class Repository
include Gitlab::ShellAdapter
include Elastic::RepositoriesSearch
include RepositoryMirroring
attr_accessor :path_with_namespace, :project
......@@ -70,10 +71,6 @@ class Repository
@raw_repository ||= Gitlab::Git::Repository.new(path_to_repo)
end
def storage_path
@project.repository_storage_path
end
# Return absolute path to repository
def path_to_repo
@path_to_repo ||= File.expand_path(
......@@ -185,10 +182,6 @@ class Repository
find_branch(branch_name)
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)
newrev = commit(target).try(:id)
options = { message: message, tagger: user_to_committer(user) } if message
......@@ -210,10 +203,6 @@ class Repository
true
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)
before_remove_tag
tag = find_tag(tag_name)
......@@ -224,40 +213,6 @@ class Repository
true
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
branch_names + tag_names
end
......@@ -805,22 +760,6 @@ class Repository
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
@tags ||= raw_repository.tags
end
......
......@@ -50,7 +50,8 @@ describe RemoteMirror do
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
......
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