BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e6b57167
Commit
e6b57167
authored
Apr 01, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Repository#local_branches from gitlab-ee.
This will help us to avoid posible merge conflicts when merging gitlab-ce to gitlab-ee
parent
09b7b766
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
10 deletions
+33
-10
repository.rb
app/models/repository.rb
+10
-6
repository_spec.rb
spec/models/repository_spec.rb
+21
-4
merge_worker_spec.rb
spec/workers/merge_worker_spec.rb
+2
-0
No files found.
app/models/repository.rb
View file @
e6b57167
...
@@ -72,7 +72,7 @@ class Repository
...
@@ -72,7 +72,7 @@ class Repository
return
@has_visible_content
unless
@has_visible_content
.
nil?
return
@has_visible_content
unless
@has_visible_content
.
nil?
@has_visible_content
=
cache
.
fetch
(
:has_visible_content?
)
do
@has_visible_content
=
cache
.
fetch
(
:has_visible_content?
)
do
raw_repository
.
branch_count
>
0
branch_count
>
0
end
end
end
end
...
@@ -173,7 +173,7 @@ class Repository
...
@@ -173,7 +173,7 @@ class Repository
end
end
def
branch_names
def
branch_names
cache
.
fetch
(
:branch_names
)
{
raw_repository
.
branch_names
}
cache
.
fetch
(
:branch_names
)
{
branches
.
map
(
&
:name
)
}
end
end
def
tag_names
def
tag_names
...
@@ -191,7 +191,7 @@ class Repository
...
@@ -191,7 +191,7 @@ class Repository
end
end
def
branch_count
def
branch_count
@branch_count
||=
cache
.
fetch
(
:branch_count
)
{
raw_repository
.
branch_count
}
@branch_count
||=
cache
.
fetch
(
:branch_count
)
{
branches
.
size
}
end
end
def
tag_count
def
tag_count
...
@@ -239,7 +239,7 @@ class Repository
...
@@ -239,7 +239,7 @@ class Repository
def
expire_branches_cache
def
expire_branches_cache
cache
.
expire
(
:branch_names
)
cache
.
expire
(
:branch_names
)
@branches
=
nil
@
local_
branches
=
nil
end
end
def
expire_cache
(
branch_name
=
nil
,
revision
=
nil
)
def
expire_cache
(
branch_name
=
nil
,
revision
=
nil
)
...
@@ -614,10 +614,14 @@ class Repository
...
@@ -614,10 +614,14 @@ class Repository
refs_contains_sha
(
'tag'
,
sha
)
refs_contains_sha
(
'tag'
,
sha
)
end
end
def
branches
def
local_branches
@branches
||=
raw_repository
.
branches
@local_branches
||=
rugged
.
branches
.
each
(
:local
).
map
do
|
branch
|
Gitlab
::
Git
::
Branch
.
new
(
branch
.
name
,
branch
.
target
)
end
end
end
alias_method
:branches
,
:local_branches
def
tags
def
tags
@tags
||=
raw_repository
.
tags
@tags
||=
raw_repository
.
tags
end
end
...
...
spec/models/repository_spec.rb
View file @
e6b57167
...
@@ -303,7 +303,7 @@ describe Repository, models: true do
...
@@ -303,7 +303,7 @@ describe Repository, models: true do
describe
'when there are no branches'
do
describe
'when there are no branches'
do
before
do
before
do
allow
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
and_return
(
0
)
allow
(
repository
).
to
receive
(
:branch_count
).
and_return
(
0
)
end
end
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
false
)
}
...
@@ -311,13 +311,13 @@ describe Repository, models: true do
...
@@ -311,13 +311,13 @@ describe Repository, models: true do
describe
'when there are branches'
do
describe
'when there are branches'
do
it
'returns true'
do
it
'returns true'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
and_return
(
3
)
expect
(
repository
).
to
receive
(
:branch_count
).
and_return
(
3
)
expect
(
subject
).
to
eq
(
true
)
expect
(
subject
).
to
eq
(
true
)
end
end
it
'caches the output'
do
it
'caches the output'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
expect
(
repository
).
to
receive
(
:branch_count
).
once
.
once
.
and_return
(
3
)
and_return
(
3
)
...
@@ -436,7 +436,7 @@ describe Repository, models: true do
...
@@ -436,7 +436,7 @@ describe Repository, models: true do
it
'expires the visible content cache'
do
it
'expires the visible content cache'
do
repository
.
has_visible_content?
repository
.
has_visible_content?
expect
(
repository
.
raw_repository
).
to
receive
(
:branch_count
).
expect
(
repository
).
to
receive
(
:branch_count
).
once
.
once
.
and_return
(
0
)
and_return
(
0
)
...
@@ -865,4 +865,21 @@ describe Repository, models: true do
...
@@ -865,4 +865,21 @@ describe Repository, models: true do
repository
.
build_cache
repository
.
build_cache
end
end
end
end
describe
'#local_branches'
do
it
'returns the local branches'
do
masterrev
=
repository
.
find_branch
(
'master'
).
target
create_remote_branch
(
'joe'
,
'remote_branch'
,
masterrev
)
repository
.
add_branch
(
user
,
'local_branch'
,
masterrev
)
expect
(
repository
.
local_branches
.
any?
{
|
branch
|
branch
.
name
==
'remote_branch'
}).
to
eq
(
false
)
expect
(
repository
.
local_branches
.
any?
{
|
branch
|
branch
.
name
==
'local_branch'
}).
to
eq
(
true
)
end
end
def
create_remote_branch
(
remote_name
,
branch_name
,
target
)
rugged
=
repository
.
rugged
rugged
.
references
.
create
(
"refs/remotes/
#{
remote_name
}
/
#{
branch_name
}
"
,
target
)
end
end
end
spec/workers/merge_worker_spec.rb
View file @
e6b57167
...
@@ -22,6 +22,8 @@ describe MergeWorker do
...
@@ -22,6 +22,8 @@ describe MergeWorker do
merge_request
.
reload
merge_request
.
reload
expect
(
merge_request
).
to
be_merged
expect
(
merge_request
).
to
be_merged
source_project
.
repository
.
expire_branches_cache
expect
(
source_project
.
repository
.
branch_names
).
not_to
include
(
'markdown'
)
expect
(
source_project
.
repository
.
branch_names
).
not_to
include
(
'markdown'
)
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