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
b9ec197c
Commit
b9ec197c
authored
Oct 03, 2019
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests to pull mirroring
parent
4055c2fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
131 additions
and
105 deletions
+131
-105
ee/spec/services/projects/update_mirror_service_spec.rb
ee/spec/services/projects/update_mirror_service_spec.rb
+131
-105
No files found.
ee/spec/services/projects/update_mirror_service_spec.rb
View file @
b9ec197c
...
...
@@ -139,158 +139,158 @@ describe Projects::UpdateMirrorService do
end
end
context
"updating branches"
do
context
'when pull_mirror_branch_prefix is set'
do
let
(
:pull_mirror_branch_prefix
)
{
'upstream/'
}
before
do
project
.
update
(
pull_mirror_branch_prefix:
pull_mirror_branch_prefix
)
end
context
'updating branches'
do
shared_examples
'a working pull mirror'
do
|
branch_prefix
|
context
'when the mirror has a repository'
do
let
(
:master
)
{
"
#{
branch_prefix
}
master"
}
it
"creates new branches"
do
stub_fetch_mirror
(
project
)
service
.
execute
expect
(
project
.
repository
.
branch_names
).
to
include
(
"
#{
pull_mirror_branch_prefix
}
new-branch"
)
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
'new-branch'
)
end
context
'when pull_mirror_branch_prefix feature flag is disabled'
do
before
do
stub_feature_flags
(
pull_mirror_branch_prefix:
false
)
end
it
"creates new branches"
do
stub_fetch_mirror
(
project
)
end
it
'creates new branches'
do
service
.
execute
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
"
#{
pull_mirror_branch_prefix
}
new-branch"
)
expect
(
project
.
repository
.
branch_names
).
to
include
(
'new-branch'
)
expect
(
project
.
repository
.
branch_names
).
to
include
(
"
#{
branch_prefix
}
new-branch"
)
end
end
end
context
'when mirror only protected branches option is set'
do
let
(
:new_protected_branch_name
)
{
'new-branch'
}
let
(
:protected_branch_name
)
{
'existing-branch'
}
it
'updates existing branches'
do
service
.
execute
before
do
project
.
update
(
only_mirror_protected_branches:
true
)
end
expect
(
project
.
repository
.
find_branch
(
"
#{
branch_prefix
}
existing-branch"
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
it
'creates a new protected branch
'
do
create
(
:protected_branch
,
project:
project
,
name:
new_protected_branch_name
)
project
.
reload
context
'when mirror only protected branches option is set
'
do
let
(
:new_protected_branch_name
)
{
"
#{
branch_prefix
}
new-branch"
}
let
(
:protected_branch_name
)
{
"
#{
branch_prefix
}
existing-branch"
}
stub_fetch_mirror
(
project
)
before
do
project
.
update
(
only_mirror_protected_branches:
true
)
end
service
.
execute
it
'creates a new protected branch'
do
create
(
:protected_branch
,
project:
project
,
name:
new_protected_branch_name
)
project
.
reload
expect
(
project
.
repository
.
branch_names
).
to
include
(
new_protected_branch_name
)
end
service
.
execute
it
'does not create an unprotected branch'
do
stub_fetch_mirror
(
project
)
expect
(
project
.
repository
.
branch_names
).
to
include
(
new_protected_branch_name
)
end
service
.
execute
it
'does not create an unprotected branch'
do
service
.
execute
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
new_protected_branch_name
)
end
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
new_protected_branch_name
)
end
it
'updates existing protected branches'
do
create
(
:protected_branch
,
project:
project
,
name:
protected_branch_name
)
project
.
reload
it
'updates existing protected branches'
do
create
(
:protected_branch
,
project:
project
,
name:
protected_branch_name
)
project
.
reload
stub_fetch_mirror
(
project
)
service
.
execute
service
.
execute
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
it
'does not update unprotected branches'
do
service
.
execute
it
"does not update unprotected branches"
do
stub_fetch_mirror
(
project
)
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
end
service
.
execute
context
'with diverged branches'
do
let
(
:diverged_branch
)
{
"
#{
branch_prefix
}
markdown"
}
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
end
context
'when mirror_overwrites_diverged_branches is true'
do
it
'update diverged branches'
do
project
.
mirror_overwrites_diverged_branches
=
true
it
"creates new branches"
do
stub_fetch_mirror
(
project
)
service
.
execute
service
.
execute
expect
(
project
.
repository
.
find_branch
(
diverged_branch
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
end
expect
(
project
.
repository
.
branch_names
).
to
include
(
'new-branch'
)
end
context
'when mirror_overwrites_diverged_branches is false'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
false
it
"updates existing branches"
do
stub_fetch_mirror
(
project
)
service
.
execute
service
.
execute
expect
(
project
.
repository
.
find_branch
(
diverged_branch
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
end
expect
(
project
.
repository
.
find_branch
(
'existing-branch'
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
context
'when mirror_overwrites_diverged_branches is nil'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
nil
context
'with diverged branches'
do
before
do
stub_fetch_mirror
(
project
)
service
.
execute
expect
(
project
.
repository
.
find_branch
(
diverged_branch
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
master
).
dereferenced_target
)
end
end
end
end
context
'when mirror_overwrites_diverged_branches is true'
do
it
'update diverged branches'
do
project
.
mirror_overwrites_diverged_branches
=
true
context
'when project is empty'
do
it
'does not add a default master branch'
do
project
=
create
(
:project_empty_repo
,
:mirror
,
import_url:
Project
::
UNKNOWN_IMPORT_URL
)
repository
=
project
.
repository
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
create_file
(
repository
)
}
expect
(
CreateBranchService
).
not_to
receive
(
:create_master_branch
)
service
.
execute
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
expect
(
repository
.
branch_names
).
not_to
include
(
'master'
)
end
end
end
context
'when mirror_overwrites_diverged_branches is false'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
false
service
.
execute
context
'when pull_mirror_branch_prefix is set'
do
let
(
:pull_mirror_branch_prefix
)
{
'upstream/'
}
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
before
do
project
.
update
(
pull_mirror_branch_prefix:
pull_mirror_branch_prefix
)
end
context
'when mirror_overwrites_diverged_branches is nil'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
nil
it
"doesn't create unprefixed branches"
do
stub_fetch_mirror
(
project
)
service
.
execute
service
.
execute
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
'new-branch'
)
end
end
context
'when project is empty'
do
it
'does not add a default master branch'
do
project
=
create
(
:project_empty_repo
,
:mirror
,
import_url:
Project
::
UNKNOWN_IMPORT_URL
)
repository
=
project
.
repository
it_behaves_like
'a working pull mirror'
,
'upstream/'
context
'when pull_mirror_branch_prefix feature flag is disabled'
do
before
do
stub_feature_flags
(
pull_mirror_branch_prefix:
false
)
end
it_behaves_like
'a working pull mirror'
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
create_file
(
repository
)
}
expect
(
CreateBranchService
).
not_to
receive
(
:create_master_branch
)
it
"doesn't create prefixed branches"
do
stub_fetch_mirror
(
project
)
service
.
execute
service
.
execute
expect
(
repository
.
branch_names
).
not_to
include
(
'master'
)
expect
(
project
.
repository
.
branch_names
).
not_to
include
(
"
#{
pull_mirror_branch_prefix
}
new-branch"
)
end
end
end
it_behaves_like
'a working pull mirror'
def
create_file
(
repository
)
repository
.
create_file
(
project
.
owner
,
...
...
@@ -385,16 +385,42 @@ describe Projects::UpdateMirrorService do
end
end
def
rewrite_refs_as_pull_mirror
(
project
)
return
unless
project
.
pull_mirror_branch_prefix
return
unless
Feature
.
enabled?
(
:pull_mirror_branch_prefix
)
repository
=
project
.
repository
old_branches
=
repository
.
branches
.
each_with_object
({})
do
|
branch
,
branches
|
branches
[
branch
.
name
]
=
branch
.
dereferenced_target
.
id
end
rugged
=
rugged_repo
(
repository
)
old_branches
.
each
do
|
name
,
target
|
mirrored_branch_ref
=
"refs/heads/
#{
project
.
pull_mirror_branch_prefix
}#{
name
}
"
rugged
.
references
.
create
(
mirrored_branch_ref
,
target
)
rugged
.
head
=
mirrored_branch_ref
if
name
==
'master'
rugged
.
branches
.
delete
(
name
)
end
repository
.
expire_branches_cache
repository
.
branches
end
def
stub_fetch_mirror
(
project
,
repository:
project
.
repository
)
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
branch_prefix
=
project
.
pull_mirror_branch_prefix
branch_prefix
=
''
unless
Feature
.
enabled?
(
:pull_mirror_branch_prefix
)
rewrite_refs_as_pull_mirror
(
project
)
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
,
branch_prefix:
branch_prefix
)
}
end
def
fetch_mirror
(
repository
)
def
fetch_mirror
(
repository
,
branch_prefix:
''
)
rugged
=
rugged_repo
(
repository
)
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
.
id
masterrev
=
repository
.
find_branch
(
"
#{
branch_prefix
}
master"
).
dereferenced_target
.
id
parentrev
=
repository
.
commit
(
masterrev
).
parent_id
rugged
.
references
.
create
(
'refs/heads/existing-branch'
,
parentrev
)
rugged
.
references
.
create
(
"refs/heads/
#{
branch_prefix
}
existing-branch"
,
parentrev
)
repository
.
expire_branches_cache
repository
.
branches
...
...
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