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
8065adcc
Commit
8065adcc
authored
Jul 22, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Gitlab::Git::Repository specs for #branches
parent
432bb223
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
14 deletions
+39
-14
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+39
-14
No files found.
spec/lib/gitlab/git/repository_spec.rb
View file @
8065adcc
...
@@ -911,8 +911,34 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -911,8 +911,34 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#branches with deleted branch'
do
describe
'#branches'
do
before
(
:each
)
do
subject
{
repository
.
branches
}
context
'with local and remote branches'
do
let
(
:repository
)
do
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
File
.
join
(
TEST_MUTABLE_REPO_PATH
,
'.git'
))
end
before
do
create_remote_branch
(
repository
,
'joe'
,
'remote_branch'
,
'master'
)
repository
.
create_branch
(
'local_branch'
,
'master'
)
end
after
do
FileUtils
.
rm_rf
(
TEST_MUTABLE_REPO_PATH
)
ensure_seeds
end
it
'returns the local and remote branches'
do
expect
(
subject
.
any?
{
|
b
|
b
.
name
==
'joe/remote_branch'
}).
to
eq
(
true
)
expect
(
subject
.
any?
{
|
b
|
b
.
name
==
'local_branch'
}).
to
eq
(
true
)
end
end
# With Gitaly enabled, Gitaly just doesn't return deleted branches.
context
'with deleted branch with Gitaly disabled'
do
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
and_return
(
false
)
ref
=
double
()
ref
=
double
()
allow
(
ref
).
to
receive
(
:name
)
{
'bad-branch'
}
allow
(
ref
).
to
receive
(
:name
)
{
'bad-branch'
}
allow
(
ref
).
to
receive
(
:target
)
{
raise
Rugged
::
ReferenceError
}
allow
(
ref
).
to
receive
(
:target
)
{
raise
Rugged
::
ReferenceError
}
...
@@ -921,8 +947,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -921,8 +947,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
allow
(
repository
.
rugged
).
to
receive
(
:branches
)
{
branches
}
allow
(
repository
.
rugged
).
to
receive
(
:branches
)
{
branches
}
end
end
it
'should return empty branches'
do
it
{
is_expected
.
to
eq
([])
}
expect
(
repository
.
branches
).
to
eq
([])
end
end
end
end
...
@@ -1070,7 +1095,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1070,7 +1095,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
it
'returns the local branches'
do
it
'returns the local branches'
do
create_remote_branch
(
'joe'
,
'remote_branch'
,
'master'
)
create_remote_branch
(
@repo
,
'joe'
,
'remote_branch'
,
'master'
)
@repo
.
create_branch
(
'local_branch'
,
'master'
)
@repo
.
create_branch
(
'local_branch'
,
'master'
)
expect
(
@repo
.
local_branches
.
any?
{
|
branch
|
branch
.
name
==
'remote_branch'
}).
to
eq
(
false
)
expect
(
@repo
.
local_branches
.
any?
{
|
branch
|
branch
.
name
==
'remote_branch'
}).
to
eq
(
false
)
...
@@ -1097,9 +1122,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1097,9 +1122,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
def
create_remote_branch
(
remote_name
,
branch_name
,
source_branch_name
)
def
create_remote_branch
(
re
pository
,
re
mote_name
,
branch_name
,
source_branch_name
)
source_branch
=
@repo
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
rugged
=
@repo
.
rugged
rugged
=
repository
.
rugged
rugged
.
references
.
create
(
"refs/remotes/
#{
remote_name
}
/
#{
branch_name
}
"
,
source_branch
.
dereferenced_target
.
sha
)
rugged
.
references
.
create
(
"refs/remotes/
#{
remote_name
}
/
#{
branch_name
}
"
,
source_branch
.
dereferenced_target
.
sha
)
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