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
37ef9c23
Commit
37ef9c23
authored
Dec 02, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure default_branch from settings is not blank
parent
f0afb27e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
app/models/concerns/has_repository.rb
app/models/concerns/has_repository.rb
+1
-1
changelogs/unreleased/fj-disallow-empty-strings-in-default-branch.yml
...nreleased/fj-disallow-empty-strings-in-default-branch.yml
+5
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+18
-10
No files found.
app/models/concerns/has_repository.rb
View file @
37ef9c23
...
@@ -88,7 +88,7 @@ module HasRepository
...
@@ -88,7 +88,7 @@ module HasRepository
group_branch_default_name
=
group
&
.
default_branch_name
if
respond_to?
(
:group
)
group_branch_default_name
=
group
&
.
default_branch_name
if
respond_to?
(
:group
)
group_branch_default_name
||
Gitlab
::
CurrentSettings
.
default_branch_nam
e
(
group_branch_default_name
||
Gitlab
::
CurrentSettings
.
default_branch_name
).
presenc
e
end
end
def
reload_default_branch
def
reload_default_branch
...
...
changelogs/unreleased/fj-disallow-empty-strings-in-default-branch.yml
0 → 100644
View file @
37ef9c23
---
title
:
Ensure default_branch from settings is not blank
merge_request
:
49018
author
:
type
:
fixed
spec/models/project_spec.rb
View file @
37ef9c23
...
@@ -5071,11 +5071,11 @@ RSpec.describe Project, factory_default: :keep do
...
@@ -5071,11 +5071,11 @@ RSpec.describe Project, factory_default: :keep do
end
end
end
end
describe
"#default_branch"
do
describe
'#default_branch'
do
context
"with an empty repository"
do
context
'with an empty repository'
do
let_it_be
(
:project
)
{
create
(
:project_empty_repo
)
}
let_it_be
(
:project
)
{
create
(
:project_empty_repo
)
}
context
"group.default_branch_name is available"
do
context
'group.default_branch_name is available'
do
let
(
:project_group
)
{
create
(
:group
)
}
let
(
:project_group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
path:
'avatar'
,
namespace:
project_group
)
}
let
(
:project
)
{
create
(
:project
,
path:
'avatar'
,
namespace:
project_group
)
}
...
@@ -5088,19 +5088,19 @@ RSpec.describe Project, factory_default: :keep do
...
@@ -5088,19 +5088,19 @@ RSpec.describe Project, factory_default: :keep do
.
and_return
(
'example_branch'
)
.
and_return
(
'example_branch'
)
end
end
it
"returns the group default value"
do
it
'returns the group default value'
do
expect
(
project
.
default_branch
).
to
eq
(
"example_branch"
)
expect
(
project
.
default_branch
).
to
eq
(
'example_branch'
)
end
end
end
end
context
"Gitlab::CurrentSettings.default_branch_name is available"
do
context
'Gitlab::CurrentSettings.default_branch_name is available'
do
before
do
before
do
expect
(
Gitlab
::
CurrentSettings
)
expect
(
Gitlab
::
CurrentSettings
)
.
to
receive
(
:default_branch_name
)
.
to
receive
(
:default_branch_name
)
.
and_return
(
example_branch_name
)
.
and_return
(
example_branch_name
)
end
end
context
"is missing or nil"
do
context
'is missing or nil'
do
let
(
:example_branch_name
)
{
nil
}
let
(
:example_branch_name
)
{
nil
}
it
"returns nil"
do
it
"returns nil"
do
...
@@ -5108,10 +5108,18 @@ RSpec.describe Project, factory_default: :keep do
...
@@ -5108,10 +5108,18 @@ RSpec.describe Project, factory_default: :keep do
end
end
end
end
context
"is present"
do
context
'is blank'
do
let
(
:example_branch_name
)
{
"example_branch_name"
}
let
(
:example_branch_name
)
{
''
}
it
"returns the expected branch name"
do
it
'returns nil'
do
expect
(
project
.
default_branch
).
to
be_nil
end
end
context
'is present'
do
let
(
:example_branch_name
)
{
'example_branch_name'
}
it
'returns the expected branch name'
do
expect
(
project
.
default_branch
).
to
eq
(
example_branch_name
)
expect
(
project
.
default_branch
).
to
eq
(
example_branch_name
)
end
end
end
end
...
...
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