Commit f728c0d6 authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-guard-repository-mirrors-read-only' into 'master'

Disable pull mirror if repository is in read-only state

See merge request gitlab-org/gitlab!19182
parents 9ff6da73 0ec751c8
---
title: Disable pull mirror if repository is in read-only state
merge_request: 19182
author:
type: fixed
...@@ -10,6 +10,12 @@ module Projects ...@@ -10,6 +10,12 @@ module Projects
return success return success
end end
# This should be an error, but to prevent the mirroring
# from being disabled when moving between shards
# we make it "success" for time being
# Ref: https://gitlab.com/gitlab-org/gitlab/merge_requests/19182
return success if project.repository_read_only?
unless can?(current_user, :push_code_to_protected_branches, project) unless can?(current_user, :push_code_to_protected_branches, project)
return error("The mirror user is not allowed to push code to all branches on this project.") return error("The mirror user is not allowed to push code to all branches on this project.")
end end
......
...@@ -72,6 +72,19 @@ describe Projects::UpdateMirrorService do ...@@ -72,6 +72,19 @@ describe Projects::UpdateMirrorService do
end end
end end
context 'when repository is in read-only mode' do
before do
project.update_attribute(:repository_read_only, true)
end
it 'does not run if repository is set to read-only' do
expect(service).not_to receive(:update_tags)
expect(service).not_to receive(:update_branches)
expect(service.execute).to be_truthy
end
end
context 'when tags on mirror are modified' do context 'when tags on mirror are modified' do
let(:mirror_project) { create(:project, :repository)} let(:mirror_project) { create(:project, :repository)}
let(:mirror_path) { File.join(TestEnv.repos_path, mirror_project.repository.relative_path) } let(:mirror_path) { File.join(TestEnv.repos_path, mirror_project.repository.relative_path) }
......
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