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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
59b36f20
Commit
59b36f20
authored
Mar 12, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use gitlab-shell to move repos. Requires gitlab-shell v1.1.0
parent
b1e42551
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
125 deletions
+71
-125
app/services/project_transfer_service.rb
app/services/project_transfer_service.rb
+11
-13
lib/gitlab/backend/shell.rb
lib/gitlab/backend/shell.rb
+13
-1
lib/gitlab/project_mover.rb
lib/gitlab/project_mover.rb
+0
-45
spec/lib/project_mover_spec.rb
spec/lib/project_mover_spec.rb
+0
-66
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+0
-0
spec/services/project_transfer_service_spec.rb
spec/services/project_transfer_service_spec.rb
+47
-0
No files found.
app/services/project_transfer_service.rb
View file @
59b36f20
...
...
@@ -3,29 +3,27 @@
# Used for transfer project to another namespace
#
class
ProjectTransferService
include
Gitolited
attr_accessor
:project
def
transfer
(
project
,
new_namespace
)
Project
.
transaction
do
old_namespace
=
project
.
namespace
project
.
namespace
=
new_namespace
old_dir
=
old_namespace
.
try
(
:path
)
||
''
new_dir
=
new_namespace
.
try
(
:path
)
||
''
old_repo
=
if
old_dir
.
present?
File
.
join
(
old_dir
,
project
.
path
)
else
project
.
path
end
old_path
=
project
.
path_with_namespace
new_path
=
File
.
join
(
new_namespace
.
try
(
:path
)
||
''
,
project
.
path
)
if
Project
.
where
(
path:
project
.
path
,
namespace_id:
new_namespace
.
try
(
:id
)).
present?
raise
TransferError
.
new
(
"Project with same path in target namespace already exists"
)
end
Gitlab
::
ProjectMover
.
new
(
project
,
old_dir
,
new_dir
).
execute
project
.
namespace
=
new_namespace
project
.
save!
unless
gitlab_shell
.
mv_repository
(
old_path
,
new_path
)
raise
TransferError
.
new
(
'Cannot move project'
)
end
true
end
rescue
Gitlab
::
ProjectMover
::
ProjectMoveError
=>
ex
raise
Project
::
TransferError
.
new
(
ex
.
message
)
...
...
lib/gitlab/backend/shell.rb
View file @
59b36f20
...
...
@@ -24,6 +24,18 @@ module Gitlab
system
(
"
#{
gitlab_shell_user_home
}
/gitlab-shell/bin/gitlab-projects import-project
#{
name
}
.git
#{
url
}
"
)
end
# Move repository
#
# path - project path with namespace
# new_path - new project path with namespace
#
# Ex.
# mv_repository("gitlab/gitlab-ci", "randx/gitlab-ci-new.git")
#
def
mv_repository
(
path
,
new_path
)
system
(
"
#{
gitlab_shell_user_home
}
/gitlab-shell/bin/gitlab-projects mv-project
#{
path
}
.git
#{
new_path
}
.git"
)
end
# Remove repository from file system
#
# name - project path with namespace
...
...
lib/gitlab/project_mover.rb
deleted
100644 → 0
View file @
b1e42551
# ProjectMover class
#
# Used for moving project repositories from one subdir to another
module
Gitlab
class
ProjectMover
class
ProjectMoveError
<
StandardError
;
end
attr_reader
:project
,
:old_dir
,
:new_dir
def
initialize
(
project
,
old_dir
,
new_dir
)
@project
=
project
@old_dir
=
old_dir
@new_dir
=
new_dir
end
def
execute
# Create new dir if missing
new_dir_path
=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
repos_path
,
new_dir
)
FileUtils
.
mkdir
(
new_dir_path
,
mode:
0770
)
unless
File
.
exists?
(
new_dir_path
)
old_path
=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
repos_path
,
old_dir
,
"
#{
project
.
path
}
.git"
)
new_path
=
File
.
join
(
new_dir_path
,
"
#{
project
.
path
}
.git"
)
if
File
.
exists?
new_path
raise
ProjectMoveError
.
new
(
"Destination
#{
new_path
}
already exists"
)
end
begin
FileUtils
.
mv
(
old_path
,
new_path
)
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
true
rescue
Exception
=>
e
message
=
"Project
#{
project
.
name
}
cannot be moved from
#{
old_path
}
to
#{
new_path
}
"
log_info
"Error!
#{
message
}
(
#{
e
.
message
}
)"
raise
ProjectMoveError
.
new
(
message
)
end
end
protected
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
end
end
spec/lib/project_mover_spec.rb
deleted
100644 → 0
View file @
b1e42551
require
'spec_helper'
describe
Gitlab
::
ProjectMover
do
let
(
:base_path
)
{
Rails
.
root
.
join
(
'tmp'
,
'rspec-sandbox'
)
}
before
do
FileUtils
.
rm_rf
base_path
if
File
.
exists?
base_path
FileUtils
.
mkdir_p
base_path
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
base_path
)
@project
=
create
(
:project
)
end
after
do
FileUtils
.
rm_rf
base_path
end
it
"should move project to subdir"
do
mk_dir
base_path
,
''
,
@project
.
path
mover
=
Gitlab
::
ProjectMover
.
new
(
@project
,
''
,
'opensource'
)
mover
.
execute
.
should
be_true
moved?
(
'opensource'
,
@project
.
path
).
should
be_true
end
it
"should move project from one subdir to another"
do
mk_dir
base_path
,
'vsizov'
,
@project
.
path
mover
=
Gitlab
::
ProjectMover
.
new
(
@project
,
'vsizov'
,
'randx'
)
mover
.
execute
.
should
be_true
moved?
(
'randx'
,
@project
.
path
).
should
be_true
end
it
"should move project from subdir to base"
do
mk_dir
base_path
,
'vsizov'
,
@project
.
path
mover
=
Gitlab
::
ProjectMover
.
new
(
@project
,
'vsizov'
,
''
)
mover
.
execute
.
should
be_true
moved?
(
''
,
@project
.
path
).
should
be_true
end
it
"should raise if destination exists"
do
mk_dir
base_path
,
''
,
@project
.
path
mk_dir
base_path
,
'vsizov'
,
@project
.
path
mover
=
Gitlab
::
ProjectMover
.
new
(
@project
,
'vsizov'
,
''
)
expect
{
mover
.
execute
}.
to
raise_error
(
Gitlab
::
ProjectMover
::
ProjectMoveError
)
end
it
"should raise if move failed"
do
mk_dir
base_path
mover
=
Gitlab
::
ProjectMover
.
new
(
@project
,
'vsizov'
,
''
)
expect
{
mover
.
execute
}.
to
raise_error
(
Gitlab
::
ProjectMover
::
ProjectMoveError
)
end
def
mk_dir
base_path
,
namespace
=
''
,
project_path
=
''
FileUtils
.
mkdir_p
File
.
join
(
base_path
,
namespace
,
project_path
+
".git"
)
end
def
moved?
namespace
,
path
File
.
exists?
(
File
.
join
(
base_path
,
namespace
,
path
+
'.git'
))
end
end
spec/services/git_push_service.rb
→
spec/services/git_push_service
_spec
.rb
View file @
59b36f20
File moved
spec/services/project_transfer_service_spec.rb
0 → 100644
View file @
59b36f20
require
'spec_helper'
describe
ProjectTransferService
do
context
'namespace -> namespace'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
before
do
@result
=
service
.
transfer
(
project
,
group
)
end
it
{
@result
.
should
be_true
}
it
{
project
.
namespace
.
should
==
group
}
end
context
'namespace -> no namespace'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
before
do
@result
=
service
.
transfer
(
project
,
nil
)
end
it
{
@result
.
should
be_true
}
it
{
project
.
namespace
.
should
==
nil
}
end
context
'no namespace -> namespace'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
@result
=
service
.
transfer
(
project
,
user
.
namespace
)
end
it
{
@result
.
should
be_true
}
it
{
project
.
namespace
.
should
==
user
.
namespace
}
end
def
service
service
=
ProjectTransferService
.
new
service
.
gitlab_shell
.
stub
(
mv_repository:
true
)
service
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