Move methods that are not related to mirroring to the repository model
This commit is contained in:
parent
6e64071e20
commit
35fe9c660c
|
@ -1,21 +1,4 @@
|
||||||
module RepositoryMirroring
|
module RepositoryMirroring
|
||||||
def storage_path
|
|
||||||
@project.repository_storage_path
|
|
||||||
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)
|
def set_remote_as_mirror(name)
|
||||||
config = raw_repository.rugged.config
|
config = raw_repository.rugged.config
|
||||||
|
|
||||||
|
@ -25,7 +8,10 @@ module RepositoryMirroring
|
||||||
config["remote.#{name}.prune"] = true
|
config["remote.#{name}.prune"] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_remote(remote, forced: false, no_tags: false)
|
def fetch_mirror(remote, url)
|
||||||
gitlab_shell.fetch_remote(storage_path, path_with_namespace, remote, forced: forced, no_tags: no_tags)
|
add_remote(remote, url)
|
||||||
|
set_remote_as_mirror(remote)
|
||||||
|
fetch_remote(remote, forced: true)
|
||||||
|
remove_remote(remote)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Repository
|
||||||
# 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(repository_storage_path, path_with_namespace + ".git")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1034,11 +1034,21 @@ class Repository
|
||||||
rugged.references.delete(tmp_ref) if tmp_ref
|
rugged.references.delete(tmp_ref) if tmp_ref
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_mirror(remote, url)
|
def add_remote(name, url)
|
||||||
add_remote(remote, url)
|
raw_repository.remote_add(name, url)
|
||||||
set_remote_as_mirror(remote)
|
rescue Rugged::ConfigError
|
||||||
fetch_remote(remote, forced: true)
|
raw_repository.remote_update(name, url: url)
|
||||||
remove_remote(remote)
|
end
|
||||||
|
|
||||||
|
def remove_remote(name)
|
||||||
|
raw_repository.remote_delete(name)
|
||||||
|
true
|
||||||
|
rescue Rugged::ConfigError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_remote(remote, forced: false, no_tags: false)
|
||||||
|
gitlab_shell.fetch_remote(repository_storage_path, path_with_namespace, remote, forced: forced, no_tags: no_tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_ref(source_path, source_ref, target_ref)
|
def fetch_ref(source_path, source_ref, target_ref)
|
||||||
|
@ -1158,4 +1168,8 @@ class Repository
|
||||||
def repository_event(event, tags = {})
|
def repository_event(event, tags = {})
|
||||||
Gitlab::Metrics.add_event(event, { path: path_with_namespace }.merge(tags))
|
Gitlab::Metrics.add_event(event, { path: path_with_namespace }.merge(tags))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def repository_storage_path
|
||||||
|
@project.repository_storage_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue