Commit 7ffc7982 authored by Stan Hu's avatar Stan Hu

Merge branch 'refresh-commit-count-after-head-change' into 'master'

Refresh commit count after repository head changes

Closes #59346

See merge request gitlab-org/gitlab-ce!26473
parents 85a1acbe e64589a3
...@@ -1384,6 +1384,7 @@ class Project < ActiveRecord::Base ...@@ -1384,6 +1384,7 @@ class Project < ActiveRecord::Base
repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}") repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}")
repository.copy_gitattributes(branch) repository.copy_gitattributes(branch)
repository.after_change_head repository.after_change_head
ProjectCacheWorker.perform_async(self.id, [], [:commit_count])
reload_default_branch reload_default_branch
else else
errors.add(:base, "Could not change HEAD: branch '#{branch}' does not exist") errors.add(:base, "Could not change HEAD: branch '#{branch}' does not exist")
......
...@@ -27,6 +27,7 @@ class ProjectCacheWorker ...@@ -27,6 +27,7 @@ class ProjectCacheWorker
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def update_statistics(project, statistics = []) def update_statistics(project, statistics = [])
return if Gitlab::Database.read_only?
return unless try_obtain_lease_for(project.id, :update_statistics) return unless try_obtain_lease_for(project.id, :update_statistics)
Rails.logger.info("Updating statistics for project #{project.id}") Rails.logger.info("Updating statistics for project #{project.id}")
......
---
title: Refresh commit count after repository head changes
merge_request: 26473
author:
type: fixed
...@@ -2379,6 +2379,12 @@ describe Project do ...@@ -2379,6 +2379,12 @@ describe Project do
project.change_head(project.default_branch) project.change_head(project.default_branch)
end end
it 'updates commit count' do
expect(ProjectCacheWorker).to receive(:perform_async).with(project.id, [], [:commit_count])
project.change_head(project.default_branch)
end
it 'copies the gitattributes' do it 'copies the gitattributes' do
expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch) expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch)
project.change_head(project.default_branch) project.change_head(project.default_branch)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment