Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4023d9f8
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4023d9f8
编写于
11月 24, 2012
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
class for moving project
上级
d71a68af
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
56 addition
and
24 deletion
+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
未找到文件。
app/observers/project_observer.rb
浏览文件 @
4023d9f8
...
...
@@ -4,7 +4,10 @@ class ProjectObserver < ActiveRecord::Observer
# Move repository if namespace changed
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
...
...
@@ -23,20 +26,4 @@ class ProjectObserver < ActiveRecord::Observer
def
log_info
message
Gitlab
::
AppLogger
.
info
message
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
features/support/env.rb
浏览文件 @
4023d9f8
...
...
@@ -5,7 +5,7 @@ require 'rspec'
require
'database_cleaner'
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
)
end
...
...
lib/gitlab/project_mover.rb
0 → 100644
浏览文件 @
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
浏览文件 @
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
浏览文件 @
4023d9f8
...
...
@@ -28,10 +28,4 @@ module StubbedRepository
end
end
class
Namespace
def
ensure_dir_exist
true
end
end
Project
.
send
(
:include
,
StubbedRepository
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录