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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
4fc46007
Commit
4fc46007
authored
Jun 14, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default branch detection happens through Gitaly
Migration:
https://gitlab.com/gitlab-org/gitaly/issues/220
parent
f195a743
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
83 deletions
+5
-83
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+5
-32
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+0
-51
No files found.
lib/gitlab/git/repository.rb
View file @
4fc46007
...
...
@@ -120,13 +120,11 @@ module Gitlab
# Default branch in the repository
def
root_ref
@root_ref
||=
gitaly_migrate
(
:root_ref
,
status:
Gitlab
::
GitalyClient
::
MigrationStatus
::
OPT_OUT
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_client
.
default_branch_name
els
e
discover_default_branch
end
end
rescue
GRPC
::
NotFound
=>
e
raise
NoRepository
.
new
(
e
.
message
)
rescue
GRPC
::
Unknown
=>
e
raise
Gitlab
::
Git
::
CommandError
.
new
(
e
.
message
)
end
def
rugged
...
...
@@ -364,31 +362,6 @@ module Gitlab
end
.
map
(
&
:name
)
end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
# - If one branch is present, returns its name
# - If two or more branches are present, returns current HEAD or master or first branch
def
discover_default_branch
names
=
branch_names
return
if
names
.
empty?
return
names
[
0
]
if
names
.
length
==
1
if
rugged_head
extracted_name
=
Ref
.
extract_branch_name
(
rugged_head
.
name
)
return
extracted_name
if
names
.
include?
(
extracted_name
)
end
if
names
.
include?
(
'master'
)
'master'
else
names
[
0
]
end
end
def
rugged_head
rugged
.
head
rescue
Rugged
::
ReferenceError
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
4fc46007
...
...
@@ -77,17 +77,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe
'#root_ref'
do
context
'with gitaly disabled'
do
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
and_return
(
false
)
end
it
'calls #discover_default_branch'
do
expect
(
repository
).
to
receive
(
:discover_default_branch
)
repository
.
root_ref
end
end
it
'returns UTF-8'
do
expect
(
repository
.
root_ref
).
to
be_utf8
end
...
...
@@ -153,46 +142,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
"#discover_default_branch"
do
let
(
:master
)
{
'master'
}
let
(
:feature
)
{
'feature'
}
let
(
:feature2
)
{
'feature2'
}
around
do
|
example
|
# discover_default_branch will be moved to gitaly-ruby
Gitlab
::
GitalyClient
::
StorageSettings
.
allow_disk_access
do
example
.
run
end
end
it
"returns 'master' when master exists"
do
expect
(
repository
).
to
receive
(
:branch_names
).
at_least
(
:once
).
and_return
([
feature
,
master
])
expect
(
repository
.
discover_default_branch
).
to
eq
(
'master'
)
end
it
"returns non-master when master exists but default branch is set to something else"
do
File
.
write
(
File
.
join
(
repository_path
,
'HEAD'
),
'ref: refs/heads/feature'
)
expect
(
repository
).
to
receive
(
:branch_names
).
at_least
(
:once
).
and_return
([
feature
,
master
])
expect
(
repository
.
discover_default_branch
).
to
eq
(
'feature'
)
File
.
write
(
File
.
join
(
repository_path
,
'HEAD'
),
'ref: refs/heads/master'
)
end
it
"returns a non-master branch when only one exists"
do
expect
(
repository
).
to
receive
(
:branch_names
).
at_least
(
:once
).
and_return
([
feature
])
expect
(
repository
.
discover_default_branch
).
to
eq
(
'feature'
)
end
it
"returns a non-master branch when more than one exists and master does not"
do
expect
(
repository
).
to
receive
(
:branch_names
).
at_least
(
:once
).
and_return
([
feature
,
feature2
])
expect
(
repository
.
discover_default_branch
).
to
eq
(
'feature'
)
end
it
"returns nil when no branch exists"
do
expect
(
repository
).
to
receive
(
:branch_names
).
at_least
(
:once
).
and_return
([])
expect
(
repository
.
discover_default_branch
).
to
be_nil
end
end
describe
'#branch_names'
do
subject
{
repository
.
branch_names
}
...
...
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