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
4023d9f8
Commit
4023d9f8
authored
Nov 24, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class for moving project
parent
d71a68af
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
24 deletions
+56
-24
app/observers/project_observer.rb
app/observers/project_observer.rb
+4
-17
features/support/env.rb
features/support/env.rb
+1
-1
lib/gitlab/project_mover.rb
lib/gitlab/project_mover.rb
+37
-0
spec/support/namespaces_stub.rb
spec/support/namespaces_stub.rb
+14
-0
spec/support/stubbed_repository.rb
spec/support/stubbed_repository.rb
+0
-6
No files found.
app/observers/project_observer.rb
View file @
4023d9f8
...
@@ -4,7 +4,10 @@ class ProjectObserver < ActiveRecord::Observer
...
@@ -4,7 +4,10 @@ class ProjectObserver < ActiveRecord::Observer
# Move repository if namespace changed
# Move repository if namespace changed
if
project
.
namespace_id_changed?
and
not
project
.
new_record?
if
project
.
namespace_id_changed?
and
not
project
.
new_record?
move_project
(
project
)
old_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id_was
).
try
(
:path
)
||
''
new_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id
).
try
(
:path
)
||
''
Gitlab
::
ProjectMover
.
new
(
project
,
old_dir
,
new_dir
).
execute
end
end
end
end
...
@@ -23,20 +26,4 @@ class ProjectObserver < ActiveRecord::Observer
...
@@ -23,20 +26,4 @@ class ProjectObserver < ActiveRecord::Observer
def
log_info
message
def
log_info
message
Gitlab
::
AppLogger
.
info
message
Gitlab
::
AppLogger
.
info
message
end
end
def
move_project
(
project
)
old_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id_was
).
try
(
:path
)
||
''
new_dir
=
Namespace
.
find_by_id
(
project
.
namespace_id
).
try
(
:path
)
||
''
# Create new dir if missing
new_dir_path
=
File
.
join
(
Gitlab
.
config
.
git_base_path
,
new_dir
)
Dir
.
mkdir
(
new_dir_path
)
unless
File
.
exists?
(
new_dir_path
)
old_path
=
File
.
join
(
Gitlab
.
config
.
git_base_path
,
old_dir
,
"
#{
project
.
path
}
.git"
)
new_path
=
File
.
join
(
new_dir_path
,
"
#{
project
.
path
}
.git"
)
`mv
#{
old_path
}
#{
new_path
}
`
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
end
end
end
features/support/env.rb
View file @
4023d9f8
...
@@ -5,7 +5,7 @@ require 'rspec'
...
@@ -5,7 +5,7 @@ require 'rspec'
require
'database_cleaner'
require
'database_cleaner'
require
'spinach/capybara'
require
'spinach/capybara'
%w(gitolite_stub stubbed_repository valid_commit)
.
each
do
|
f
|
%w(
namespaces_stub
gitolite_stub stubbed_repository valid_commit)
.
each
do
|
f
|
require
Rails
.
root
.
join
(
'spec'
,
'support'
,
f
)
require
Rails
.
root
.
join
(
'spec'
,
'support'
,
f
)
end
end
...
...
lib/gitlab/project_mover.rb
0 → 100644
View file @
4023d9f8
# ProjectMover class
#
# Used for moving project repositories from one subdir to another
module
Gitlab
class
ProjectMover
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
.
git_base_path
,
new_dir
)
Dir
.
mkdir
(
new_dir_path
)
unless
File
.
exists?
(
new_dir_path
)
old_path
=
File
.
join
(
Gitlab
.
config
.
git_base_path
,
old_dir
,
"
#{
project
.
path
}
.git"
)
new_path
=
File
.
join
(
new_dir_path
,
"
#{
project
.
path
}
.git"
)
if
system
(
"mv
#{
old_path
}
#{
new_path
}
"
)
log_info
"Project
#{
project
.
name
}
was moved from
#{
old_path
}
to
#{
new_path
}
"
true
else
log_info
"Error! Project
#{
project
.
name
}
cannot be moved from
#{
old_path
}
to
#{
new_path
}
"
false
end
end
protected
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
end
end
spec/support/namespaces_stub.rb
0 → 100644
View file @
4023d9f8
require
'namespace'
require
'gitlab/project_mover'
class
Namespace
def
ensure_dir_exist
true
end
end
class
Gitlab::ProjectMover
def
execute
true
end
end
spec/support/stubbed_repository.rb
View file @
4023d9f8
...
@@ -28,10 +28,4 @@ module StubbedRepository
...
@@ -28,10 +28,4 @@ module StubbedRepository
end
end
end
end
class
Namespace
def
ensure_dir_exist
true
end
end
Project
.
send
(
:include
,
StubbedRepository
)
Project
.
send
(
:include
,
StubbedRepository
)
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