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
Jérome Perrin
gitlab-ce
Commits
b3fb5b4f
Commit
b3fb5b4f
authored
Feb 13, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use gitlab shell import instead of manually creating the webhooks
Also update repo restorer to use project wiki method.
parent
01dfedbc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
32 deletions
+49
-32
app/models/project_wiki.rb
app/models/project_wiki.rb
+4
-0
lib/gitlab/import_export/command_line_util.rb
lib/gitlab/import_export/command_line_util.rb
+0
-12
lib/gitlab/import_export/repo_restorer.rb
lib/gitlab/import_export/repo_restorer.rb
+2
-19
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+3
-1
spec/lib/gitlab/import_export/repo_restorer_spec.rb
spec/lib/gitlab/import_export/repo_restorer_spec.rb
+40
-0
No files found.
app/models/project_wiki.rb
View file @
b3fb5b4f
...
@@ -160,6 +160,10 @@ class ProjectWiki
...
@@ -160,6 +160,10 @@ class ProjectWiki
}
}
end
end
def
repository_storage_path
project
.
repository_storage_path
end
private
private
def
init_repo
(
path_with_namespace
)
def
init_repo
(
path_with_namespace
)
...
...
lib/gitlab/import_export/command_line_util.rb
View file @
b3fb5b4f
...
@@ -15,14 +15,6 @@ module Gitlab
...
@@ -15,14 +15,6 @@ module Gitlab
execute
(
%W(
#{
git_bin_path
}
--git-dir=
#{
repo_path
}
bundle create
#{
bundle_path
}
--all)
)
execute
(
%W(
#{
git_bin_path
}
--git-dir=
#{
repo_path
}
bundle create
#{
bundle_path
}
--all)
)
end
end
def
git_unbundle
(
repo_path
:,
bundle_path
:)
execute
(
%W(
#{
git_bin_path
}
clone --bare
#{
bundle_path
}
#{
repo_path
}
)
)
end
def
git_restore_hooks
execute
(
%W(
#{
Gitlab
.
config
.
gitlab_shell
.
path
}
/bin/create-hooks)
+
repository_storage_paths_args
)
end
def
mkdir_p
(
path
)
def
mkdir_p
(
path
)
FileUtils
.
mkdir_p
(
path
,
mode:
DEFAULT_MODE
)
FileUtils
.
mkdir_p
(
path
,
mode:
DEFAULT_MODE
)
FileUtils
.
chmod
(
DEFAULT_MODE
,
path
)
FileUtils
.
chmod
(
DEFAULT_MODE
,
path
)
...
@@ -56,10 +48,6 @@ module Gitlab
...
@@ -56,10 +48,6 @@ module Gitlab
FileUtils
.
copy_entry
(
source
,
destination
)
FileUtils
.
copy_entry
(
source
,
destination
)
true
true
end
end
def
repository_storage_paths_args
Gitlab
.
config
.
repositories
.
storages
.
values
end
end
end
end
end
end
end
lib/gitlab/import_export/repo_restorer.rb
View file @
b3fb5b4f
...
@@ -2,6 +2,7 @@ module Gitlab
...
@@ -2,6 +2,7 @@ module Gitlab
module
ImportExport
module
ImportExport
class
RepoRestorer
class
RepoRestorer
include
Gitlab
::
ImportExport
::
CommandLineUtil
include
Gitlab
::
ImportExport
::
CommandLineUtil
include
Gitlab
::
ShellAdapter
def
initialize
(
project
:,
shared
:,
path_to_bundle
:)
def
initialize
(
project
:,
shared
:,
path_to_bundle
:)
@project
=
project
@project
=
project
...
@@ -12,29 +13,11 @@ module Gitlab
...
@@ -12,29 +13,11 @@ module Gitlab
def
restore
def
restore
return
true
unless
File
.
exist?
(
@path_to_bundle
)
return
true
unless
File
.
exist?
(
@path_to_bundle
)
mkdir_p
(
path_to_repo
)
gitlab_shell
.
import_repository
(
@project
.
repository_storage_path
,
@project
.
path_with_namespace
,
@path_to_bundle
)
git_unbundle
(
repo_path:
path_to_repo
,
bundle_path:
@path_to_bundle
)
&&
repo_restore_hooks
rescue
=>
e
rescue
=>
e
@shared
.
error
(
e
)
@shared
.
error
(
e
)
false
false
end
end
private
def
path_to_repo
@project
.
repository
.
path_to_repo
end
def
repo_restore_hooks
return
true
if
wiki?
git_restore_hooks
end
def
wiki?
@project
.
class
.
name
==
'ProjectWiki'
end
end
end
end
end
end
end
lib/gitlab/shell.rb
View file @
b3fb5b4f
...
@@ -80,8 +80,10 @@ module Gitlab
...
@@ -80,8 +80,10 @@ module Gitlab
# import_repository("/path/to/storage", "gitlab/gitlab-ci", "https://github.com/randx/six.git")
# import_repository("/path/to/storage", "gitlab/gitlab-ci", "https://github.com/randx/six.git")
#
#
def
import_repository
(
storage
,
name
,
url
)
def
import_repository
(
storage
,
name
,
url
)
# Timeout should be less than 900 ideally, to prevent the memory killer
# to silently kill the process without knowing we are timing out here.
output
,
status
=
Popen
::
popen
([
gitlab_shell_projects_path
,
'import-project'
,
output
,
status
=
Popen
::
popen
([
gitlab_shell_projects_path
,
'import-project'
,
storage
,
"
#{
name
}
.git"
,
url
,
'
9
00'
])
storage
,
"
#{
name
}
.git"
,
url
,
'
8
00'
])
raise
Error
,
output
unless
status
.
zero?
raise
Error
,
output
unless
status
.
zero?
true
true
end
end
...
...
spec/lib/gitlab/import_export/repo_restorer_spec.rb
0 → 100644
View file @
b3fb5b4f
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
RepoRestorer
,
services:
true
do
describe
'bundle a project Git repo'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project_with_repo
)
{
create
(
:project
,
:test_repo
,
name:
'test-repo-restorer'
,
path:
'test-repo-restorer'
)
}
let!
(
:project
)
{
create
(
:empty_project
)
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:bundler
)
{
Gitlab
::
ImportExport
::
RepoSaver
.
new
(
project:
project_with_repo
,
shared:
shared
)
}
let
(
:bundle_path
)
{
File
.
join
(
shared
.
export_path
,
Gitlab
::
ImportExport
.
project_bundle_filename
)
}
let
(
:restorer
)
do
described_class
.
new
(
path_to_bundle:
bundle_path
,
shared:
shared
,
project:
project
)
end
before
do
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
bundler
.
save
end
after
do
FileUtils
.
rm_rf
(
export_path
)
FileUtils
.
rm_rf
(
project_with_repo
.
repository
.
path_to_repo
)
FileUtils
.
rm_rf
(
project
.
repository
.
path_to_repo
)
end
it
'restores the repo successfully'
do
expect
(
restorer
.
restore
).
to
be
true
end
it
'has the webhooks'
do
restorer
.
restore
expect
(
Gitlab
::
Git
::
Hook
.
new
(
'post-receive'
,
project
.
repository
.
path_to_repo
)).
to
exist
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