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
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
Hide 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
...
@@ -120,13 +120,11 @@ module Gitlab
# Default branch in the repository
# Default branch in the repository
def
root_ref
def
root_ref
@root_ref
||=
gitaly_migrate
(
:root_ref
,
status:
Gitlab
::
GitalyClient
::
MigrationStatus
::
OPT_OUT
)
do
|
is_enabled
|
gitaly_ref_client
.
default_branch_name
if
is_enabled
rescue
GRPC
::
NotFound
=>
e
gitaly_ref_client
.
default_branch_name
raise
NoRepository
.
new
(
e
.
message
)
else
rescue
GRPC
::
Unknown
=>
e
discover_default_branch
raise
Gitlab
::
Git
::
CommandError
.
new
(
e
.
message
)
end
end
end
end
def
rugged
def
rugged
...
@@ -364,31 +362,6 @@ module Gitlab
...
@@ -364,31 +362,6 @@ module Gitlab
end
.
map
(
&
:name
)
end
.
map
(
&
:name
)
end
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
def
rugged_head
rugged
.
head
rugged
.
head
rescue
Rugged
::
ReferenceError
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
...
@@ -77,17 +77,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#root_ref'
do
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
it
'returns UTF-8'
do
expect
(
repository
.
root_ref
).
to
be_utf8
expect
(
repository
.
root_ref
).
to
be_utf8
end
end
...
@@ -153,46 +142,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -153,46 +142,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
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
describe
'#branch_names'
do
subject
{
repository
.
branch_names
}
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