diff options
author | Hannes Rosenögger <123haynes@gmail.com> | 2016-08-12 16:29:13 +0200 |
---|---|---|
committer | Hannes Rosenögger <123haynes@gmail.com> | 2016-08-25 14:52:14 +0200 |
commit | f16eabfc3335119015302798cb270445ddc0dc89 (patch) | |
tree | 37c45616519c782e01749cb1783fd9b1819b1db9 | |
parent | 7bbb523b23638c52b3c0ba43d8f3dbef8840aad6 (diff) | |
download | gitlab-ce-f16eabfc3335119015302798cb270445ddc0dc89.tar.gz |
Display project icon from default branch
This commit makes sure that the project icon is
being read from the default branch instead of
'master'
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/projects/avatars_controller.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 31 |
5 files changed, 35 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index 518e80a360a..ab675653138 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ v 8.11.1 (unreleased) - Does not halt the GitHub import process when an error occurs - Fix file links on project page when default view is Files !5933 - Change using size to use count and caching it for number of group members + - Use the default branch for displaying the project icon instead of master !5792 (Hannes Rosenögger) v 8.11.0 - Use test coverage value from the latest successful pipeline in badge. !5862 diff --git a/app/controllers/projects/avatars_controller.rb b/app/controllers/projects/avatars_controller.rb index 5962f74c39b..ada7db3c552 100644 --- a/app/controllers/projects/avatars_controller.rb +++ b/app/controllers/projects/avatars_controller.rb @@ -4,7 +4,7 @@ class Projects::AvatarsController < Projects::ApplicationController before_action :authorize_admin_project!, only: [:destroy] def show - @blob = @repository.blob_at_branch('master', @project.avatar_in_git) + @blob = @repository.blob_at_branch(@repository.root_ref, @project.avatar_in_git) if @blob headers['X-Content-Type-Options'] = 'nosniff' diff --git a/app/models/project.rb b/app/models/project.rb index 8cf093be4c3..0e4fb94f8eb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1035,6 +1035,7 @@ class Project < ActiveRecord::Base "refs/heads/#{branch}", force: true) repository.copy_gitattributes(branch) + repository.expire_avatar_cache(branch) reload_default_branch end diff --git a/app/models/repository.rb b/app/models/repository.rb index bdc3b9d1c1c..91bdafdac99 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1065,7 +1065,7 @@ class Repository @avatar ||= cache.fetch(:avatar) do AVATAR_FILES.find do |file| - blob_at_branch('master', file) + blob_at_branch(root_ref, file) end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9a3660012f9..b2baeeb31bb 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1442,4 +1442,35 @@ describe Project, models: true do expect(shared_project.authorized_for_user?(master, Gitlab::Access::MASTER)).to be(true) end end + + describe 'change_head' do + let(:project) { create(:project) } + + it 'calls the before_change_head method' do + expect(project.repository).to receive(:before_change_head) + project.change_head(project.default_branch) + end + + it 'creates the new reference with rugged' do + expect(project.repository.rugged.references).to receive(:create).with('HEAD', + "refs/heads/#{project.default_branch}", + force: true) + project.change_head(project.default_branch) + end + + it 'copies the gitattributes' do + expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch) + project.change_head(project.default_branch) + end + + it 'expires the avatar cache' do + expect(project.repository).to receive(:expire_avatar_cache).with(project.default_branch) + project.change_head(project.default_branch) + end + + it 'reloads the default branch' do + expect(project).to receive(:reload_default_branch) + project.change_head(project.default_branch) + end + end end |