Merge branch '58613-protected-branches-error' into 'master'
Allow protected branch creation for empty project Closes #58613 See merge request gitlab-org/gitlab-ce!25834
This commit is contained in:
commit
ca402c1aef
|
@ -46,7 +46,9 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if creation? && protected_branch_creation_enabled?
|
if project.empty_repo?
|
||||||
|
protected_branch_push_checks
|
||||||
|
elsif creation? && protected_branch_creation_enabled?
|
||||||
protected_branch_creation_checks
|
protected_branch_creation_checks
|
||||||
elsif deletion?
|
elsif deletion?
|
||||||
protected_branch_deletion_checks
|
protected_branch_deletion_checks
|
||||||
|
|
|
@ -48,10 +48,28 @@ describe Gitlab::Checks::BranchCheck do
|
||||||
context 'when project repository is empty' do
|
context 'when project repository is empty' do
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
it 'raises an error if the user is not allowed to push to protected branches' do
|
context 'user is not allowed to push to protected branches' do
|
||||||
expect(user_access).to receive(:can_push_to_branch?).and_return(false)
|
before do
|
||||||
|
allow(user_access)
|
||||||
|
.to receive(:can_push_to_branch?)
|
||||||
|
.and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::UnauthorizedError, /Ask a project Owner or Maintainer to create a default branch/)
|
it 'raises an error' do
|
||||||
|
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::UnauthorizedError, /Ask a project Owner or Maintainer to create a default branch/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'user is allowed to push to protected branches' do
|
||||||
|
before do
|
||||||
|
allow(user_access)
|
||||||
|
.to receive(:can_push_to_branch?)
|
||||||
|
.and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'allows branch creation' do
|
||||||
|
expect { subject.validate! }.not_to raise_error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue