summaryrefslogtreecommitdiff
path: root/lib/gitlab/git
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-11-23 16:51:55 +0100
committerDouwe Maan <douwe@selenight.nl>2017-11-23 16:59:58 +0100
commit7a1e93d35b7280db8bc4128862c86223d76a8d6d (patch)
treeaf2ef540c8a93a7739aa581a114a604fe03006dc /lib/gitlab/git
parent0e6beaf50c9233ca03083691856dea2883f71773 (diff)
downloadgitlab-ce-7a1e93d35b7280db8bc4128862c86223d76a8d6d.tar.gz
Rename fetch_refs to refmap
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/repository_mirroring.rb35
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/gitlab/git/repository_mirroring.rb b/lib/gitlab/git/repository_mirroring.rb
index 49e2b833fa7..392bef69e80 100644
--- a/lib/gitlab/git/repository_mirroring.rb
+++ b/lib/gitlab/git/repository_mirroring.rb
@@ -1,36 +1,37 @@
module Gitlab
module Git
module RepositoryMirroring
- FETCH_REFS = {
- # `:all` is used to define repository as equivalent as "git clone --mirror"
- all: '+refs/*:refs/*',
+ REFMAPS = {
+ # With `:all_refs`, the repository is equivalent to the result of `git clone --mirror`
+ all_refs: '+refs/*:refs/*',
heads: '+refs/heads/*:refs/heads/*',
tags: '+refs/tags/*:refs/tags/*'
}.freeze
RemoteError = Class.new(StandardError)
- def set_remote_as_mirror(remote_name, fetch_refs: :all)
- Array(fetch_refs).each_with_index do |fetch_ref, i|
- fetch_ref = FETCH_REFS[fetch_ref] || fetch_ref
-
- # Add first fetch with Rugged so it does not create its own.
- if i == 0
- rugged.config["remote.#{remote_name}.fetch"] = fetch_ref
- else
- add_remote_fetch_config(remote_name, fetch_ref)
- end
- end
+ def set_remote_as_mirror(remote_name, refmap: :all_refs)
+ set_remote_refmap(remote_name, refmap)
rugged.config["remote.#{remote_name}.mirror"] = true
rugged.config["remote.#{remote_name}.prune"] = true
end
- def add_remote_fetch_config(remote_name, refspec)
- run_git(%W[config --add remote.#{remote_name}.fetch #{refspec}])
+ def set_remote_refmap(remote_name, refmap)
+ Array(refmap).each_with_index do |refspec, i|
+ refspec = REFMAPS[refspec] || refspec
+
+ # We need multiple `fetch` entries, but Rugged only allows replacing a config, not adding to it.
+ # To make sure we start from scratch, we set the first using rugged, and use `git` for any others
+ if i == 0
+ rugged.config["remote.#{remote_name}.fetch"] = refspec
+ else
+ run_git(%W[config --add remote.#{remote_name}.fetch #{refspec}])
+ end
+ end
end
- # Like all public `Gitlab::Git::Repository` methods, this method is part
+ # Like all_refs public `Gitlab::Git::Repository` methods, this method is part
# of `Repository`'s interface through `method_missing`.
# `Repository` has its own `fetch_as_mirror` which uses `gitlab-shell` and
# takes some extra attributes, so we qualify this method name to prevent confusion.