diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/models/snippet.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 817f9d014eb..c4a7c5e25dc 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -20,6 +20,7 @@ class Snippet < ApplicationRecord extend ::Gitlab::Utils::Override MAX_FILE_COUNT = 10 + MASTER_BRANCH = 'master' cache_markdown_field :title, pipeline: :single_line cache_markdown_field :description @@ -82,6 +83,7 @@ class Snippet < ApplicationRecord scope :inc_author, -> { includes(:author) } scope :inc_relations_for_view, -> { includes(author: :status) } scope :with_statistics, -> { joins(:statistics) } + scope :inc_projects_namespace_route, -> { includes(project: [:route, :namespace]) } attr_mentionable :description @@ -311,13 +313,27 @@ class Snippet < ApplicationRecord override :default_branch def default_branch - super || 'master' + super || MASTER_BRANCH end def repository_storage snippet_repository&.shard_name || self.class.pick_repository_storage end + # Repositories are created by default with the `master` branch. + # This method changes the `HEAD` file to point to the existing + # default branch in case it's not master. + def change_head_to_default_branch + return unless repository.exists? + return if default_branch == MASTER_BRANCH + # All snippets must have at least 1 file. Therefore, if + # `HEAD` is empty is because it's pointing to the wrong + # default branch + return unless repository.empty? || list_files('HEAD').empty? + + repository.raw_repository.write_ref('HEAD', "refs/heads/#{default_branch}") + end + def create_repository return if repository_exists? && snippet_repository |