diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 09:10:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 09:10:13 +0000 |
commit | 65fdda8d39a9af414dbe5aa3a385b9bcba00960b (patch) | |
tree | 8cdac4fe05966ae74301044522ad5be1e7087ed1 /app/models/snippet.rb | |
parent | de64b03b15fb40a3fc2f1897e8e4f6be50fd4403 (diff) | |
download | gitlab-ce-65fdda8d39a9af414dbe5aa3a385b9bcba00960b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 817f9d014eb..23aab22fc09 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 @@ -311,13 +312,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 |