diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-16 15:10:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-16 15:10:15 +0300 |
commit | 591b0e86e3dbaa31b68340a14dc32859306a27b1 (patch) | |
tree | 48f44f6a1de3fe9f38d314bf95988bc6efc527c4 /app/models/snippet.rb | |
parent | 984357420ab0a91e8c73f04393a83b5ade63b460 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index f4c3fa5acc3..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 @@ -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,17 +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(repository.root_ref).size > 1 + list_files.size > 1 end class << self |