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
254c5686
Commit
254c5686
authored
Nov 15, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up repository fetch and mirror methods
parent
78dcafe8
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
110 additions
and
168 deletions
+110
-168
app/models/repository.rb
app/models/repository.rb
+17
-11
app/services/geo/base_sync_service.rb
app/services/geo/base_sync_service.rb
+2
-2
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+6
-14
ee/app/models/concerns/ee/repository_mirroring.rb
ee/app/models/concerns/ee/repository_mirroring.rb
+0
-15
ee/app/models/ee/repository.rb
ee/app/models/ee/repository.rb
+8
-1
ee/app/models/remote_mirror.rb
ee/app/models/remote_mirror.rb
+0
-1
ee/app/services/projects/update_repository_storage_service.rb
...pp/services/projects/update_repository_storage_service.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+6
-4
lib/gitlab/git/repository_mirroring.rb
lib/gitlab/git/repository_mirroring.rb
+27
-19
lib/gitlab/github_import.rb
lib/gitlab/github_import.rb
+4
-0
lib/gitlab/github_import/importer/repository_importer.rb
lib/gitlab/github_import/importer/repository_importer.rb
+2
-15
lib/gitlab/legacy_github_import/importer.rb
lib/gitlab/legacy_github_import/importer.rb
+4
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+5
-20
spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
...gitlab/github_import/importer/repository_importer_spec.rb
+2
-39
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+2
-2
spec/services/geo/repository_sync_service_spec.rb
spec/services/geo/repository_sync_service_spec.rb
+10
-10
spec/services/geo/wiki_sync_service_spec.rb
spec/services/geo/wiki_sync_service_spec.rb
+8
-8
spec/services/projects/update_repository_storage_service_spec.rb
...rvices/projects/update_repository_storage_service_spec.rb
+6
-6
No files found.
app/models/repository.rb
View file @
254c5686
...
@@ -28,7 +28,6 @@ class Repository
...
@@ -28,7 +28,6 @@ class Repository
CreateTreeError
=
Class
.
new
(
StandardError
)
CreateTreeError
=
Class
.
new
(
StandardError
)
MIRROR_REMOTE
=
"upstream"
.
freeze
MIRROR_REMOTE
=
"upstream"
.
freeze
MIRROR_GEO
=
"geo"
.
freeze
# Methods that cache data from the Git repository.
# Methods that cache data from the Git repository.
#
#
...
@@ -940,12 +939,6 @@ class Repository
...
@@ -940,12 +939,6 @@ class Repository
fetch_remote
(
Repository
::
MIRROR_REMOTE
,
ssh_auth:
project
&
.
import_data
)
fetch_remote
(
Repository
::
MIRROR_REMOTE
,
ssh_auth:
project
&
.
import_data
)
end
end
def
fetch_geo_mirror
(
url
)
add_remote
(
Repository
::
MIRROR_GEO
,
url
)
set_remote_as_mirror
(
Repository
::
MIRROR_GEO
)
fetch_remote
(
Repository
::
MIRROR_GEO
,
forced:
true
)
end
def
upstream_branches
def
upstream_branches
@upstream_branches
||=
remote_branches
(
Repository
::
MIRROR_REMOTE
)
@upstream_branches
||=
remote_branches
(
Repository
::
MIRROR_REMOTE
)
end
end
...
@@ -1027,6 +1020,19 @@ class Repository
...
@@ -1027,6 +1020,19 @@ class Repository
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
end
end
def
fetch_as_mirror
(
url
,
forced:
false
,
fetch_refs: :all
,
remote_name:
nil
)
unless
remote_name
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
tmp_remote_name
=
true
end
add_remote
(
remote_name
,
url
)
set_remote_as_mirror
(
remote_name
,
fetch_refs:
fetch_refs
)
fetch_remote
(
remote_name
,
forced:
forced
)
ensure
remove_remote
(
remote_name
)
if
tmp_remote_name
end
def
fetch_remote
(
remote
,
forced:
false
,
ssh_auth:
nil
,
no_tags:
false
)
def
fetch_remote
(
remote
,
forced:
false
,
ssh_auth:
nil
,
no_tags:
false
)
gitlab_shell
.
fetch_remote
(
raw_repository
,
remote
,
ssh_auth:
ssh_auth
,
forced:
forced
,
no_tags:
no_tags
)
gitlab_shell
.
fetch_remote
(
raw_repository
,
remote
,
ssh_auth:
ssh_auth
,
forced:
forced
,
no_tags:
no_tags
)
end
end
...
@@ -1130,6 +1136,10 @@ class Repository
...
@@ -1130,6 +1136,10 @@ class Repository
raw_repository
.
fetch_ref
(
source_repository
.
raw_repository
,
source_ref:
source_ref
,
target_ref:
target_ref
)
raw_repository
.
fetch_ref
(
source_repository
.
raw_repository
,
source_ref:
source_ref
,
target_ref:
target_ref
)
end
end
def
repository_storage_path
@project
.
repository_storage_path
end
private
private
# TODO Generice finder, later split this on finders by Ref or Oid
# TODO Generice finder, later split this on finders by Ref or Oid
...
@@ -1195,10 +1205,6 @@ class Repository
...
@@ -1195,10 +1205,6 @@ class Repository
raw_repository
.
run_git_with_timeout
(
args
,
Gitlab
::
Git
::
Popen
::
FAST_GIT_PROCESS_TIMEOUT
).
first
.
strip
raw_repository
.
run_git_with_timeout
(
args
,
Gitlab
::
Git
::
Popen
::
FAST_GIT_PROCESS_TIMEOUT
).
first
.
strip
end
end
def
repository_storage_path
@project
.
repository_storage_path
end
def
initialize_raw_repository
def
initialize_raw_repository
Gitlab
::
Git
::
Repository
.
new
(
project
.
repository_storage
,
disk_path
+
'.git'
,
Gitlab
::
GlRepository
.
gl_repository
(
project
,
is_wiki
))
Gitlab
::
Git
::
Repository
.
new
(
project
.
repository_storage
,
disk_path
+
'.git'
,
Gitlab
::
GlRepository
.
gl_repository
(
project
,
is_wiki
))
end
end
...
...
app/services/geo/base_sync_service.rb
View file @
254c5686
...
@@ -114,13 +114,13 @@ module Geo
...
@@ -114,13 +114,13 @@ module Geo
authorization
=
::
Gitlab
::
Geo
::
BaseRequest
.
new
.
authorization
authorization
=
::
Gitlab
::
Geo
::
BaseRequest
.
new
.
authorization
header
=
{
"http.
#{
url
}
.extraHeader"
=>
"Authorization:
#{
authorization
}
"
}
header
=
{
"http.
#{
url
}
.extraHeader"
=>
"Authorization:
#{
authorization
}
"
}
repository
.
with_config
(
header
)
{
repository
.
fetch_
geo_mirror
(
url
)
}
repository
.
with_config
(
header
)
{
repository
.
fetch_
as_mirror
(
url
,
forced:
true
)
}
end
end
def
fetch_ssh_geo_mirror
(
repository
)
def
fetch_ssh_geo_mirror
(
repository
)
url
=
build_repository_url
(
primary_ssh_path_prefix
,
repository
)
url
=
build_repository_url
(
primary_ssh_path_prefix
,
repository
)
repository
.
fetch_
geo_mirror
(
url
)
repository
.
fetch_
as_mirror
(
url
,
forced:
true
)
end
end
def
registry
def
registry
...
...
app/services/projects/import_service.rb
View file @
254c5686
...
@@ -51,10 +51,13 @@ module Projects
...
@@ -51,10 +51,13 @@ module Projects
def
import_repository
def
import_repository
begin
begin
if
project
.
gitea_import?
fetch_refs
=
importer_class
.
try
(
:fetch_refs
)
if
has_importer?
fetch_repository
if
fetch_refs
project
.
ensure_repository
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
fetch_refs:
fetch_refs
)
else
else
clone_repository
gitlab_shell
.
import_repository
(
project
.
repository_storage_path
,
project
.
disk_path
,
project
.
import_url
)
end
end
rescue
Gitlab
::
Shell
::
Error
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
=>
e
rescue
Gitlab
::
Shell
::
Error
,
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
=>
e
# Expire cache to prevent scenarios such as:
# Expire cache to prevent scenarios such as:
...
@@ -66,17 +69,6 @@ module Projects
...
@@ -66,17 +69,6 @@ module Projects
end
end
end
end
def
clone_repository
gitlab_shell
.
import_repository
(
project
.
repository_storage_path
,
project
.
disk_path
,
project
.
import_url
)
end
def
fetch_repository
project
.
ensure_repository
project
.
repository
.
add_remote
(
project
.
import_type
,
project
.
import_url
)
project
.
repository
.
set_remote_as_mirror
(
project
.
import_type
)
project
.
repository
.
fetch_remote
(
project
.
import_type
,
forced:
true
)
end
def
import_data
def
import_data
return
unless
has_importer?
return
unless
has_importer?
...
...
ee/app/models/concerns/ee/repository_mirroring.rb
deleted
100644 → 0
View file @
78dcafe8
module
EE
module
RepositoryMirroring
def
storage_path
@project
.
repository_storage_path
end
def
push_remote_branches
(
remote
,
branches
)
gitlab_shell
.
push_remote_branches
(
storage_path
,
disk_path
,
remote
,
branches
)
end
def
delete_remote_branches
(
remote
,
branches
)
gitlab_shell
.
delete_remote_branches
(
storage_path
,
disk_path
,
remote
,
branches
)
end
end
end
ee/app/models/ee/repository.rb
View file @
254c5686
...
@@ -4,7 +4,6 @@ module EE
...
@@ -4,7 +4,6 @@ module EE
# This module is intended to encapsulate EE-specific model logic
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `Repository` model
# and be prepended in the `Repository` model
module
Repository
module
Repository
prepend
RepositoryMirroring
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
# Transiently sets a configuration variable
# Transiently sets a configuration variable
...
@@ -31,5 +30,13 @@ module EE
...
@@ -31,5 +30,13 @@ module EE
refs
.
map
{
|
sha
|
commit
(
sha
.
strip
)
}
refs
.
map
{
|
sha
|
commit
(
sha
.
strip
)
}
end
end
def
push_remote_branches
(
remote
,
branches
)
gitlab_shell
.
push_remote_branches
(
repository_storage_path
,
disk_path
,
remote
,
branches
)
end
def
delete_remote_branches
(
remote
,
branches
)
gitlab_shell
.
delete_remote_branches
(
repository_storage_path
,
disk_path
,
remote
,
branches
)
end
end
end
end
end
ee/app/models/remote_mirror.rb
View file @
254c5686
...
@@ -165,7 +165,6 @@ class RemoteMirror < ActiveRecord::Base
...
@@ -165,7 +165,6 @@ class RemoteMirror < ActiveRecord::Base
def
refresh_remote
def
refresh_remote
return
unless
project
return
unless
project
project
.
repository
.
remove_remote
(
ref_name
)
project
.
repository
.
add_remote
(
ref_name
,
url
)
project
.
repository
.
add_remote
(
ref_name
,
url
)
end
end
...
...
ee/app/services/projects/update_repository_storage_service.rb
View file @
254c5686
...
@@ -35,7 +35,7 @@ module Projects
...
@@ -35,7 +35,7 @@ module Projects
repository
.
relative_path
,
repository
.
relative_path
,
repository
.
gl_repository
)
repository
.
gl_repository
)
new_repository
.
fetch_
mirror
(
repository
.
path
)
new_repository
.
fetch_
as_mirror_without_shell
(
repository
.
path
)
end
end
def
mark_old_paths_for_archive
def
mark_old_paths_for_archive
...
...
lib/gitlab/git/repository.rb
View file @
254c5686
...
@@ -1145,10 +1145,12 @@ module Gitlab
...
@@ -1145,10 +1145,12 @@ module Gitlab
@has_visible_content
=
has_local_branches?
@has_visible_content
=
has_local_branches?
end
end
def
fetch
(
remote
=
'origin'
)
# Like all public `Gitlab::Git::Repository` methods, this method is part
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch
#{
remote
}
)
# of `Repository`'s interface through `method_missing`.
# `Repository` has its own `fetch_remote` which uses `gitlab-shell` and
popen
(
args
,
@path
).
last
.
zero?
# takes some extra attributes, so we qualify this method name to prevent confusion.
def
fetch_remote_without_shell
(
remote
=
'origin'
)
run_git
([
'fetch'
,
remote
]).
last
.
zero?
end
end
def
blob_at
(
sha
,
path
)
def
blob_at
(
sha
,
path
)
...
...
lib/gitlab/git/repository_mirroring.rb
View file @
254c5686
module
Gitlab
module
Gitlab
module
Git
module
Git
module
RepositoryMirroring
module
RepositoryMirroring
IMPORT_HEAD_REFS
=
'+refs/heads/*:refs/heads/*'
.
freeze
FETCH_REFS
=
{
IMPORT_TAG_REFS
=
'+refs/tags/*:refs/tags/*'
.
freeze
# `:all` is used to define repository as equivalent as "git clone --mirror"
MIRROR_REMOTE
=
'mirror'
.
freeze
all:
'+refs/*:refs/*'
,
heads:
'+refs/heads/*:refs/heads/*'
,
tags:
'+refs/tags/*:refs/tags/*'
}.
freeze
RemoteError
=
Class
.
new
(
StandardError
)
RemoteError
=
Class
.
new
(
StandardError
)
def
set_remote_as_mirror
(
remote_name
)
def
set_remote_as_mirror
(
remote_name
,
fetch_refs: :all
)
# This is used to define repository as equivalent as "git clone --mirror"
Array
(
fetch_refs
).
each_with_index
do
|
fetch_ref
,
i
|
rugged
.
config
[
"remote.
#{
remote_name
}
.fetch"
]
=
'refs/*:refs/*'
fetch_ref
=
FETCH_REFS
[
fetch_ref
]
||
fetch_ref
rugged
.
config
[
"remote.
#{
remote_name
}
.mirror"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.prune"
]
=
true
end
def
set_import_remote_as_mirror
(
remote_name
)
# Add first fetch with Rugged so it does not create its own.
# Add first fetch with Rugged so it does not create its own.
if
i
==
0
rugged
.
config
[
"remote.
#{
remote_name
}
.fetch"
]
=
IMPORT_HEAD_REFS
rugged
.
config
[
"remote.
#{
remote_name
}
.fetch"
]
=
fetch_ref
else
add_remote_fetch_config
(
remote_name
,
IMPORT_TAG_REFS
)
add_remote_fetch_config
(
remote_name
,
fetch_ref
)
end
end
rugged
.
config
[
"remote.
#{
remote_name
}
.mirror"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.mirror"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.prune"
]
=
true
rugged
.
config
[
"remote.
#{
remote_name
}
.prune"
]
=
true
...
@@ -28,11 +30,17 @@ module Gitlab
...
@@ -28,11 +30,17 @@ module Gitlab
run_git
(
%W[config --add remote.
#{
remote_name
}
.fetch
#{
refspec
}
]
)
run_git
(
%W[config --add remote.
#{
remote_name
}
.fetch
#{
refspec
}
]
)
end
end
def
fetch_mirror
(
url
)
# Like all public `Gitlab::Git::Repository` methods, this method is part
add_remote
(
MIRROR_REMOTE
,
url
)
# of `Repository`'s interface through `method_missing`.
set_remote_as_mirror
(
MIRROR_REMOTE
)
# `Repository` has its own `fetch_as_mirror` which uses `gitlab-shell` and
fetch
(
MIRROR_REMOTE
)
# takes some extra attributes, so we qualify this method name to prevent confusion.
remove_remote
(
MIRROR_REMOTE
)
def
fetch_as_mirror_without_shell
(
url
)
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
add_remote
(
remote_name
,
url
)
set_remote_as_mirror
(
remote_name
)
fetch_remote_without_shell
(
remote_name
)
ensure
remove_remote
(
remote_name
)
if
remote_name
end
end
def
remote_tags
(
remote
)
def
remote_tags
(
remote
)
...
...
lib/gitlab/github_import.rb
View file @
254c5686
module
Gitlab
module
Gitlab
module
GithubImport
module
GithubImport
def
self
.
fetch_refs
[
:heads
,
:tags
,
'+refs/pull/*/head:refs/merge-requests/*/head'
]
end
def
self
.
new_client_for
(
project
,
token:
nil
,
parallel:
true
)
def
self
.
new_client_for
(
project
,
token:
nil
,
parallel:
true
)
token_to_use
=
token
||
project
.
import_data
&
.
credentials
&
.
fetch
(
:user
)
token_to_use
=
token
||
project
.
import_data
&
.
credentials
&
.
fetch
(
:user
)
...
...
lib/gitlab/github_import/importer/repository_importer.rb
View file @
254c5686
...
@@ -45,27 +45,14 @@ module Gitlab
...
@@ -45,27 +45,14 @@ module Gitlab
def
import_repository
def
import_repository
project
.
ensure_repository
project
.
ensure_repository
configure_repository_remote
fetch_refs
=
Gitlab
::
GithubImport
.
fetch_refs
project
.
repository
.
fetch_as_mirror
(
project
.
import_url
,
fetch_refs:
fetch_refs
,
forced:
true
,
remote_name:
'github'
)
project
.
repository
.
fetch_remote
(
'github'
,
forced:
true
)
true
true
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
=>
e
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
,
Gitlab
::
Shell
::
Error
=>
e
fail_import
(
"Failed to import the repository:
#{
e
.
message
}
"
)
fail_import
(
"Failed to import the repository:
#{
e
.
message
}
"
)
end
end
def
configure_repository_remote
return
if
project
.
repository
.
remote_exists?
(
'github'
)
project
.
repository
.
add_remote
(
'github'
,
project
.
import_url
)
project
.
repository
.
set_import_remote_as_mirror
(
'github'
)
project
.
repository
.
add_remote_fetch_config
(
'github'
,
'+refs/pull/*/head:refs/merge-requests/*/head'
)
end
def
import_wiki_repository
def
import_wiki_repository
wiki_path
=
"
#{
project
.
disk_path
}
.wiki"
wiki_path
=
"
#{
project
.
disk_path
}
.wiki"
wiki_url
=
project
.
import_url
.
sub
(
/\.git\z/
,
'.wiki.git'
)
wiki_url
=
project
.
import_url
.
sub
(
/\.git\z/
,
'.wiki.git'
)
...
...
lib/gitlab/legacy_github_import/importer.rb
View file @
254c5686
...
@@ -3,6 +3,10 @@ module Gitlab
...
@@ -3,6 +3,10 @@ module Gitlab
class
Importer
class
Importer
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
def
self
.
fetch_refs
Gitlab
::
GithubImport
.
fetch_refs
end
attr_reader
:errors
,
:project
,
:repo
,
:repo_url
attr_reader
:errors
,
:project
,
:repo
,
:repo_url
def
initialize
(
project
)
def
initialize
(
project
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
254c5686
...
@@ -588,12 +588,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -588,12 +588,12 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#fetch_
mirror
'
do
describe
'#fetch_
as_mirror_without_shell
'
do
let
(
:new_repository
)
do
let
(
:new_repository
)
do
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
'my_project.git'
,
''
)
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
'my_project.git'
,
''
)
end
end
subject
{
new_repository
.
fetch_
mirror
(
repository
.
path
)
}
subject
{
new_repository
.
fetch_
as_mirror_without_shell
(
repository
.
path
)
}
before
do
before
do
Gitlab
::
Shell
.
new
.
add_repository
(
'default'
,
'my_project'
)
Gitlab
::
Shell
.
new
.
add_repository
(
'default'
,
'my_project'
)
...
@@ -1643,15 +1643,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1643,15 +1643,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#fetch'
do
describe
'#fetch
_remote_without_shell
'
do
let
(
:git_path
)
{
Gitlab
.
config
.
git
.
bin_path
}
let
(
:git_path
)
{
Gitlab
.
config
.
git
.
bin_path
}
let
(
:remote_name
)
{
'my_remote'
}
let
(
:remote_name
)
{
'my_remote'
}
subject
{
repository
.
fetch
(
remote_name
)
}
subject
{
repository
.
fetch
_remote_without_shell
(
remote_name
)
}
it
'fetches the remote and returns true if the command was successful'
do
it
'fetches the remote and returns true if the command was successful'
do
expect
(
repository
).
to
receive
(
:popen
)
expect
(
repository
).
to
receive
(
:popen
)
.
with
(
%W(
#{
git_path
}
fetch
#{
remote_name
}
)
,
repository
.
path
)
.
with
(
%W(
#{
git_path
}
fetch
#{
remote_name
}
)
,
repository
.
path
,
{}
)
.
and_return
([
''
,
0
])
.
and_return
([
''
,
0
])
expect
(
subject
).
to
be
(
true
)
expect
(
subject
).
to
be
(
true
)
...
@@ -1768,21 +1768,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1768,21 +1768,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#fetch'
do
let
(
:git_path
)
{
Gitlab
.
config
.
git
.
bin_path
}
let
(
:remote_name
)
{
'my_remote'
}
subject
{
repository
.
fetch
(
remote_name
)
}
it
'fetches the remote and returns true if the command was successful'
do
expect
(
repository
).
to
receive
(
:popen
)
.
with
(
%W(
#{
git_path
}
fetch
#{
remote_name
}
)
,
repository
.
path
)
.
and_return
([
''
,
0
])
expect
(
subject
).
to
be
(
true
)
end
end
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
rugged
=
repository
.
rugged
rugged
=
repository
.
rugged
...
...
spec/lib/gitlab/github_import/importer/repository_importer_spec.rb
View file @
254c5686
...
@@ -164,12 +164,9 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
...
@@ -164,12 +164,9 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
expect
(
project
)
expect
(
project
)
.
to
receive
(
:ensure_repository
)
.
to
receive
(
:ensure_repository
)
expect
(
importer
)
.
to
receive
(
:configure_repository_remote
)
expect
(
repository
)
expect
(
repository
)
.
to
receive
(
:fetch_
remote
)
.
to
receive
(
:fetch_
as_mirror
)
.
with
(
'github'
,
forced:
true
)
.
with
(
project
.
import_url
,
fetch_refs:
Gitlab
::
GithubImport
.
fetch_refs
,
forced:
true
,
remote_name:
'github'
)
expect
(
importer
.
import_repository
).
to
eq
(
true
)
expect
(
importer
.
import_repository
).
to
eq
(
true
)
end
end
...
@@ -186,40 +183,6 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
...
@@ -186,40 +183,6 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
end
end
end
end
describe
'#configure_repository_remote'
do
it
'configures the remote details'
do
expect
(
repository
)
.
to
receive
(
:remote_exists?
)
.
with
(
'github'
)
.
and_return
(
false
)
expect
(
repository
)
.
to
receive
(
:add_remote
)
.
with
(
'github'
,
'foo.git'
)
expect
(
repository
)
.
to
receive
(
:set_import_remote_as_mirror
)
.
with
(
'github'
)
expect
(
repository
)
.
to
receive
(
:add_remote_fetch_config
)
importer
.
configure_repository_remote
end
it
'does not configure the remote if already configured'
do
expect
(
repository
)
.
to
receive
(
:remote_exists?
)
.
with
(
'github'
)
.
and_return
(
true
)
expect
(
repository
)
.
not_to
receive
(
:add_remote
)
importer
.
configure_repository_remote
end
end
describe
'#import_wiki_repository'
do
describe
'#import_wiki_repository'
do
it
'imports the wiki repository'
do
it
'imports the wiki repository'
do
expect
(
importer
.
gitlab_shell
)
expect
(
importer
.
gitlab_shell
)
...
...
spec/models/repository_spec.rb
View file @
254c5686
...
@@ -2133,7 +2133,7 @@ describe Repository do
...
@@ -2133,7 +2133,7 @@ describe Repository do
describe
'#push_remote_branches'
do
describe
'#push_remote_branches'
do
it
'push branches to the remote repo'
do
it
'push branches to the remote repo'
do
expect_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:push_remote_branches
)
expect_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:push_remote_branches
)
.
with
(
repository
.
storage_path
,
repository
.
disk_path
,
'remote_name'
,
[
'branch'
])
.
with
(
repository
.
repository_
storage_path
,
repository
.
disk_path
,
'remote_name'
,
[
'branch'
])
repository
.
push_remote_branches
(
'remote_name'
,
[
'branch'
])
repository
.
push_remote_branches
(
'remote_name'
,
[
'branch'
])
end
end
...
@@ -2142,7 +2142,7 @@ describe Repository do
...
@@ -2142,7 +2142,7 @@ describe Repository do
describe
'#delete_remote_branches'
do
describe
'#delete_remote_branches'
do
it
'delete branches to the remote repo'
do
it
'delete branches to the remote repo'
do
expect_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:delete_remote_branches
)
expect_any_instance_of
(
Gitlab
::
Shell
).
to
receive
(
:delete_remote_branches
)
.
with
(
repository
.
storage_path
,
repository
.
disk_path
,
'remote_name'
,
[
'branch'
])
.
with
(
repository
.
repository_
storage_path
,
repository
.
disk_path
,
'remote_name'
,
[
'branch'
])
repository
.
delete_remote_branches
(
'remote_name'
,
[
'branch'
])
repository
.
delete_remote_branches
(
'remote_name'
,
[
'branch'
])
end
end
...
...
spec/services/geo/repository_sync_service_spec.rb
View file @
254c5686
...
@@ -26,13 +26,13 @@ describe Geo::RepositorySyncService do
...
@@ -26,13 +26,13 @@ describe Geo::RepositorySyncService do
.
with
(
subject
.
lease_key
,
anything
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_
geo
_mirror
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_
as
_mirror
)
.
and_return
(
true
)
.
and_return
(
true
)
end
end
it
'fetches project repository with JWT credentials'
do
it
'fetches project repository with JWT credentials'
do
expect
(
repository
).
to
receive
(
:with_config
).
with
(
"http.
#{
url_to_repo
}
.extraHeader"
=>
anything
).
and_call_original
expect
(
repository
).
to
receive
(
:with_config
).
with
(
"http.
#{
url_to_repo
}
.extraHeader"
=>
anything
).
and_call_original
expect
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
).
once
expect
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
).
once
subject
.
execute
subject
.
execute
end
end
...
@@ -53,7 +53,7 @@ describe Geo::RepositorySyncService do
...
@@ -53,7 +53,7 @@ describe Geo::RepositorySyncService do
end
end
it
'returns the lease when sync fail'
do
it
'returns the lease when sync fail'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Shell
::
Error
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Shell
::
Error
}
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
once
.
with
(
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
once
.
with
(
subject
.
__send__
(
:lease_key
),
anything
).
and_call_original
subject
.
__send__
(
:lease_key
),
anything
).
and_call_original
...
@@ -64,26 +64,26 @@ describe Geo::RepositorySyncService do
...
@@ -64,26 +64,26 @@ describe Geo::RepositorySyncService do
it
'does not fetch project repository if cannot obtain a lease'
do
it
'does not fetch project repository if cannot obtain a lease'
do
allow
(
lease
).
to
receive
(
:try_obtain
)
{
false
}
allow
(
lease
).
to
receive
(
:try_obtain
)
{
false
}
expect
(
repository
).
not_to
receive
(
:fetch_
geo
_mirror
)
expect
(
repository
).
not_to
receive
(
:fetch_
as
_mirror
)
subject
.
execute
subject
.
execute
end
end
it
'rescues when Gitlab::Shell::Error is raised'
do
it
'rescues when Gitlab::Shell::Error is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Shell
::
Error
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Shell
::
Error
}
expect
{
subject
.
execute
}.
not_to
raise_error
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
it
'rescues when Gitlab::Git::RepositoryMirroring::RemoteError is raised'
do
it
'rescues when Gitlab::Git::RepositoryMirroring::RemoteError is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
.
and_raise
(
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
)
.
and_raise
(
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
)
expect
{
subject
.
execute
}.
not_to
raise_error
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
it
'rescues exception and fires after_create hook when Gitlab::Git::Repository::NoRepository is raised'
do
it
'rescues exception and fires after_create hook when Gitlab::Git::Repository::NoRepository is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Git
::
Repository
::
NoRepository
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Git
::
Repository
::
NoRepository
}
expect
(
repository
).
to
receive
(
:after_create
)
expect
(
repository
).
to
receive
(
:after_create
)
...
@@ -137,7 +137,7 @@ describe Geo::RepositorySyncService do
...
@@ -137,7 +137,7 @@ describe Geo::RepositorySyncService do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
before
do
before
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Shell
::
Error
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
subject
.
execute
end
end
...
@@ -180,7 +180,7 @@ describe Geo::RepositorySyncService do
...
@@ -180,7 +180,7 @@ describe Geo::RepositorySyncService do
# gitlab-shell always appends .git to the end of the repository, so
# gitlab-shell always appends .git to the end of the repository, so
# we're relying on the fact that projects can't contain + in the name
# we're relying on the fact that projects can't contain + in the name
deleted_dir
=
File
.
join
(
project
.
repository
.
storage_path
,
project
.
path
)
+
"+failed-geo-sync.git"
deleted_dir
=
File
.
join
(
project
.
repository
_
storage_path
,
project
.
path
)
+
"+failed-geo-sync.git"
expect
(
File
.
directory?
(
deleted_dir
)).
to
be
false
expect
(
File
.
directory?
(
deleted_dir
)).
to
be
false
expect
(
File
.
directory?
(
project
.
repository
.
path
)).
to
be
true
expect
(
File
.
directory?
(
project
.
repository
.
path
)).
to
be
true
end
end
...
@@ -228,7 +228,7 @@ describe Geo::RepositorySyncService do
...
@@ -228,7 +228,7 @@ describe Geo::RepositorySyncService do
end
end
it
'fetches wiki repository over SSH'
do
it
'fetches wiki repository over SSH'
do
expect
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
).
once
expect
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
).
once
subject
.
execute
subject
.
execute
end
end
...
...
spec/services/geo/wiki_sync_service_spec.rb
View file @
254c5686
...
@@ -26,13 +26,13 @@ RSpec.describe Geo::WikiSyncService do
...
@@ -26,13 +26,13 @@ RSpec.describe Geo::WikiSyncService do
.
with
(
subject
.
lease_key
,
anything
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_
geo
_mirror
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_
as
_mirror
)
.
and_return
(
true
)
.
and_return
(
true
)
end
end
it
'fetches wiki repository with JWT credentials'
do
it
'fetches wiki repository with JWT credentials'
do
expect
(
repository
).
to
receive
(
:with_config
).
with
(
"http.
#{
url_to_repo
}
.extraHeader"
=>
anything
).
and_call_original
expect
(
repository
).
to
receive
(
:with_config
).
with
(
"http.
#{
url_to_repo
}
.extraHeader"
=>
anything
).
and_call_original
expect
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
).
once
expect
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
).
once
subject
.
execute
subject
.
execute
end
end
...
@@ -47,26 +47,26 @@ RSpec.describe Geo::WikiSyncService do
...
@@ -47,26 +47,26 @@ RSpec.describe Geo::WikiSyncService do
it
'does not fetch wiki repository if cannot obtain a lease'
do
it
'does not fetch wiki repository if cannot obtain a lease'
do
allow
(
lease
).
to
receive
(
:try_obtain
)
{
false
}
allow
(
lease
).
to
receive
(
:try_obtain
)
{
false
}
expect
(
repository
).
not_to
receive
(
:fetch_
geo
_mirror
)
expect
(
repository
).
not_to
receive
(
:fetch_
as
_mirror
)
subject
.
execute
subject
.
execute
end
end
it
'rescues exception when Gitlab::Shell::Error is raised'
do
it
'rescues exception when Gitlab::Shell::Error is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Shell
::
Error
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Shell
::
Error
}
expect
{
subject
.
execute
}.
not_to
raise_error
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
it
'rescues exception when Gitlab::Git::RepositoryMirroring::RemoteError is raised'
do
it
'rescues exception when Gitlab::Git::RepositoryMirroring::RemoteError is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
.
and_raise
(
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
)
.
and_raise
(
Gitlab
::
Git
::
RepositoryMirroring
::
RemoteError
)
expect
{
subject
.
execute
}.
not_to
raise_error
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
it
'rescues exception when Gitlab::Git::Repository::NoRepository is raised'
do
it
'rescues exception when Gitlab::Git::Repository::NoRepository is raised'
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Git
::
Repository
::
NoRepository
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Git
::
Repository
::
NoRepository
}
expect
{
subject
.
execute
}.
not_to
raise_error
expect
{
subject
.
execute
}.
not_to
raise_error
end
end
...
@@ -109,7 +109,7 @@ RSpec.describe Geo::WikiSyncService do
...
@@ -109,7 +109,7 @@ RSpec.describe Geo::WikiSyncService do
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
let
(
:registry
)
{
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
}
before
do
before
do
allow
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
)
{
raise
Gitlab
::
Shell
::
Error
}
allow
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
subject
.
execute
end
end
...
@@ -134,7 +134,7 @@ RSpec.describe Geo::WikiSyncService do
...
@@ -134,7 +134,7 @@ RSpec.describe Geo::WikiSyncService do
end
end
it
'fetches wiki repository over SSH'
do
it
'fetches wiki repository over SSH'
do
expect
(
repository
).
to
receive
(
:fetch_
geo_mirror
).
with
(
url_to_repo
).
once
expect
(
repository
).
to
receive
(
:fetch_
as_mirror
).
with
(
url_to_repo
,
forced:
true
).
once
subject
.
execute
subject
.
execute
end
end
...
...
spec/services/projects/update_repository_storage_service_spec.rb
View file @
254c5686
...
@@ -31,7 +31,7 @@ describe Projects::UpdateRepositoryStorageService do
...
@@ -31,7 +31,7 @@ describe Projects::UpdateRepositoryStorageService do
context
'when the move succeeds'
do
context
'when the move succeeds'
do
it
'moves the repository to the new storage and unmarks the repository as read only'
do
it
'moves the repository to the new storage and unmarks the repository as read only'
do
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:fetch_
mirror
)
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
.
with
(
:mv_repository
,
.
with
(
:mv_repository
,
...
@@ -48,7 +48,7 @@ describe Projects::UpdateRepositoryStorageService do
...
@@ -48,7 +48,7 @@ describe Projects::UpdateRepositoryStorageService do
context
'when the move fails'
do
context
'when the move fails'
do
it
'unmarks the repository as read-only without updating the repository storage'
do
it
'unmarks the repository as read-only without updating the repository storage'
do
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:fetch_
mirror
)
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
false
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
false
)
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
...
@@ -84,7 +84,7 @@ describe Projects::UpdateRepositoryStorageService do
...
@@ -84,7 +84,7 @@ describe Projects::UpdateRepositoryStorageService do
context
'when the move succeeds'
do
context
'when the move succeeds'
do
it
'moves the repository and its wiki to the new storage and unmarks the repository as read only'
do
it
'moves the repository and its wiki to the new storage and unmarks the repository as read only'
do
expect
(
repository_double
).
to
receive
(
:fetch_
mirror
)
expect
(
repository_double
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
.
with
(
:mv_repository
,
.
with
(
:mv_repository
,
...
@@ -92,7 +92,7 @@ describe Projects::UpdateRepositoryStorageService do
...
@@ -92,7 +92,7 @@ describe Projects::UpdateRepositoryStorageService do
project
.
disk_path
,
project
.
disk_path
,
"
#{
project
.
disk_path
}
+
#{
project
.
id
}
+moved+
#{
time
.
to_i
}
"
)
"
#{
project
.
disk_path
}
+
#{
project
.
id
}
+moved+
#{
time
.
to_i
}
"
)
expect
(
wiki_repository_double
).
to
receive
(
:fetch_
mirror
)
expect
(
wiki_repository_double
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
wiki
.
repository
.
raw
.
path
).
and_return
(
true
)
.
with
(
project
.
wiki
.
repository
.
raw
.
path
).
and_return
(
true
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
expect
(
GitlabShellWorker
).
to
receive
(
:perform_async
)
.
with
(
:mv_repository
,
.
with
(
:mv_repository
,
...
@@ -109,9 +109,9 @@ describe Projects::UpdateRepositoryStorageService do
...
@@ -109,9 +109,9 @@ describe Projects::UpdateRepositoryStorageService do
context
'when the move of the wiki fails'
do
context
'when the move of the wiki fails'
do
it
'unmarks the repository as read-only without updating the repository storage'
do
it
'unmarks the repository as read-only without updating the repository storage'
do
expect
(
repository_double
).
to
receive
(
:fetch_
mirror
)
expect
(
repository_double
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
.
with
(
project
.
repository
.
raw
.
path
).
and_return
(
true
)
expect
(
wiki_repository_double
).
to
receive
(
:fetch_
mirror
)
expect
(
wiki_repository_double
).
to
receive
(
:fetch_
as_mirror_without_shell
)
.
with
(
project
.
wiki
.
repository
.
raw
.
path
).
and_return
(
false
)
.
with
(
project
.
wiki
.
repository
.
raw
.
path
).
and_return
(
false
)
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
expect
(
GitlabShellWorker
).
not_to
receive
(
:perform_async
)
...
...
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