Commit 081e2fce authored by Lin Jen-Shin's avatar Lin Jen-Shin

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.
parent d1054bd3
......@@ -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
......
......@@ -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?
......
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 = {})
......
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
......
......@@ -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)
......
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