diff options
-rw-r--r-- | app/services/projects/import_export/cleanup_service.rb | 20 | ||||
-rw-r--r-- | spec/services/projects/import_export/cleanup_service_spec.rb | 2 |
2 files changed, 15 insertions, 7 deletions
diff --git a/app/services/projects/import_export/cleanup_service.rb b/app/services/projects/import_export/cleanup_service.rb index 75eaee0cb7b..2e6bfb99189 100644 --- a/app/services/projects/import_export/cleanup_service.rb +++ b/app/services/projects/import_export/cleanup_service.rb @@ -1,11 +1,15 @@ module Projects module ImportExport class CleanupService - RESERVED_REFS_NAMES = + def self.reserved_refs_names %w[heads tags merge-requests keep-around environments] - RESERVED_REFS_REGEXP = - %r{\Arefs/(?:#{ - RESERVED_REFS_NAMES.map(&Regexp.method(:escape)).join('|')})/}x + end + + def self.reserved_refs_regexp + names = reserved_refs_names.map(&Regexp.method(:escape)).join('|') + + %r{\Arefs/(?:#{names})/} + end attr_reader :project @@ -23,8 +27,12 @@ module Projects private def garbage_refs - @garbage_refs ||= rugged.references.reject do |ref| - ref.name =~ RESERVED_REFS_REGEXP + @garbage_refs ||= begin + reserved_refs_regexp = self.class.reserved_refs_regexp + + rugged.references.reject do |ref| + ref.name =~ reserved_refs_regexp + end end end diff --git a/spec/services/projects/import_export/cleanup_service_spec.rb b/spec/services/projects/import_export/cleanup_service_spec.rb index b46efc40a2f..108d0ea2ecc 100644 --- a/spec/services/projects/import_export/cleanup_service_spec.rb +++ b/spec/services/projects/import_export/cleanup_service_spec.rb @@ -37,7 +37,7 @@ describe Projects::ImportExport::CleanupService do end end - described_class::RESERVED_REFS_NAMES.each do |name| + described_class.reserved_refs_names.each do |name| context "with a ref in refs/#{name}/tmp" do before do repository.write_ref("refs/#{name}/tmp", sha) |