Try to make reserved ref names more obvious

So that whenever we want to reserve more, we're aware,
and don't mess it up.
This commit is contained in:
Lin Jen-Shin 2017-08-25 23:00:06 +08:00
parent d1054bd3dd
commit 081e2fce82
5 changed files with 19 additions and 10 deletions

View file

@ -114,7 +114,7 @@ class Environment < ActiveRecord::Base
end
def ref_path
"refs/environments/#{Shellwords.shellescape(name)}"
"refs/#{Repository::REF_ENVIRONMENTS}/#{Shellwords.shellescape(name)}"
end
def formatted_external_url

View file

@ -797,7 +797,7 @@ class MergeRequest < ActiveRecord::Base
end
def ref_path
"refs/merge-requests/#{iid}/head"
"refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head"
end
def ref_fetched?

View file

@ -1,6 +1,18 @@
require 'securerandom'
class Repository
REF_MERGE_REQUEST = 'merge-requests'
REF_KEEP_AROUND = 'keep-around'
REF_ENVIRONMENTS = 'environments'
RESERVED_REFS_NAMES = %W[
heads
tags
#{REF_ENVIRONMENTS}
#{REF_KEEP_AROUND}
#{REF_ENVIRONMENTS}
].freeze
include Gitlab::ShellAdapter
include RepositoryMirroring
@ -228,10 +240,10 @@ class Repository
begin
write_ref(keep_around_ref_name(sha), sha)
rescue Rugged::ReferenceError => ex
Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}"
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
rescue Rugged::OSError => ex
raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/
Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}"
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
end
end
@ -1152,7 +1164,7 @@ class Repository
end
def keep_around_ref_name(sha)
"refs/keep-around/#{sha}"
"refs/#{REF_KEEP_AROUND}/#{sha}"
end
def repository_event(event, tags = {})

View file

@ -1,10 +1,7 @@
module Projects
class AfterImportService
RESERVED_REFS_NAMES =
%w[heads tags merge-requests keep-around environments].freeze
RESERVED_REFS_REGEXP =
%r{\Arefs/(?:#{Regexp.union(*RESERVED_REFS_NAMES)})/}
%r{\Arefs/(?:#{Regexp.union(*Repository::RESERVED_REFS_NAMES)})/}
def initialize(project)
@project = project

View file

@ -37,7 +37,7 @@ describe Projects::AfterImportService do
end
end
described_class::RESERVED_REFS_NAMES.each do |name|
Repository::RESERVED_REFS_NAMES.each do |name|
context "with a ref in refs/#{name}/tmp" do
before do
repository.write_ref("refs/#{name}/tmp", sha)