Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
461e3979
Commit
461e3979
authored
Mar 07, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move empty_repo check on its own
parent
333097d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
19 deletions
+24
-19
lib/gitlab/checks/branch_check.rb
lib/gitlab/checks/branch_check.rb
+3
-1
spec/lib/gitlab/checks/branch_check_spec.rb
spec/lib/gitlab/checks/branch_check_spec.rb
+21
-18
No files found.
lib/gitlab/checks/branch_check.rb
View file @
461e3979
...
...
@@ -46,7 +46,9 @@ module Gitlab
end
end
if
creation?
&&
protected_branch_creation_enabled?
&&
!
project
.
empty_repo?
if
project
.
empty_repo?
protected_branch_push_checks
elsif
creation?
&&
protected_branch_creation_enabled?
protected_branch_creation_checks
elsif
deletion?
protected_branch_deletion_checks
...
...
spec/lib/gitlab/checks/branch_check_spec.rb
View file @
461e3979
...
...
@@ -48,10 +48,28 @@ describe Gitlab::Checks::BranchCheck do
context
'when project repository is empty'
do
let
(
:project
)
{
create
(
:project
)
}
it
'raises an error if the user is not allowed to push to protected branches'
do
expect
(
user_access
).
to
receive
(
:can_push_to_branch?
).
and_return
(
false
)
context
'user is not allowed to push to protected branches'
do
before
do
allow
(
user_access
)
.
to
receive
(
:can_push_to_branch?
)
.
and_return
(
false
)
end
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
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
UnauthorizedError
,
/Ask a project Owner or Maintainer to create a default branch/
)
it
'allows branch creation'
do
expect
{
subject
.
validate!
}.
not_to
raise_error
end
end
end
...
...
@@ -116,21 +134,6 @@ describe Gitlab::Checks::BranchCheck do
.
and_return
([
'branch'
])
end
context
"when repo is empty"
do
let
(
:project
)
{
create
(
:project
,
:empty_repo
)
}
let
(
:ref
)
{
'refs/heads/master'
}
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
context
"newrev isn't in any protected branches"
do
before
do
allow
(
ProtectedBranch
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment