diff options
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index eb3960ff12b..1cf3097861c 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -214,7 +214,7 @@ class Snippet < ApplicationRecord def blobs return [] unless repository_exists? - repository.ls_files(repository.root_ref).map { |file| Blob.lazy(repository, repository.root_ref, file) } + repository.ls_files(default_branch).map { |file| Blob.lazy(repository, default_branch, file) } end def hook_attrs @@ -275,7 +275,7 @@ class Snippet < ApplicationRecord override :repository def repository - @repository ||= Repository.new(full_path, self, shard: repository_storage, disk_path: disk_path, repo_type: Gitlab::GlRepository::SNIPPET) + @repository ||= Gitlab::GlRepository::SNIPPET.repository_for(self) end override :repository_size_checker @@ -309,6 +309,11 @@ class Snippet < ApplicationRecord end end + override :default_branch + def default_branch + super || 'master' + end + def repository_storage snippet_repository&.shard_name || self.class.pick_repository_storage end @@ -336,13 +341,17 @@ class Snippet < ApplicationRecord def file_name_on_repo return if repository.empty? - list_files(repository.root_ref).first + list_files(default_branch).first end def list_files(ref = nil) return [] if repository.empty? - repository.ls_files(ref) + repository.ls_files(ref || default_branch) + end + + def multiple_files? + list_files.size > 1 end class << self |