Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
8acb0f55
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,发现更多精彩内容 >>
提交
8acb0f55
编写于
6月 07, 2017
作者:
J
James Lopez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor code and spec
上级
e2eb0b6f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
34 deletion
+25
-34
lib/backup/repository.rb
lib/backup/repository.rb
+21
-25
spec/lib/gitlab/backup/repository_spec.rb
spec/lib/gitlab/backup/repository_spec.rb
+4
-9
未找到文件。
lib/backup/repository.rb
浏览文件 @
8acb0f55
...
...
@@ -7,7 +7,7 @@ module Backup
prepare
Project
.
find_each
(
batch_size:
1000
)
do
|
project
|
$
progress
.
print
" *
#{
project
.
path_with_namespace
}
... "
progress
.
print
" *
#{
project
.
path_with_namespace
}
... "
path_to_project_repo
=
path_to_repo
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
...
...
@@ -15,7 +15,7 @@ module Backup
FileUtils
.
mkdir_p
(
File
.
join
(
backup_repos_path
,
project
.
namespace
.
full_path
))
if
project
.
namespace
if
empty_repo?
(
project
)
$
progress
.
puts
"[SKIPPED]"
.
color
(
:cyan
)
progress
.
puts
"[SKIPPED]"
.
color
(
:cyan
)
else
in_path
(
path_to_project_repo
)
do
|
dir
|
FileUtils
.
mkdir_p
(
path_to_tars
(
project
))
...
...
@@ -31,7 +31,7 @@ module Backup
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
$
progress
.
puts
"[DONE]"
.
color
(
:green
)
progress
.
puts
"[DONE]"
.
color
(
:green
)
else
progress_warn
(
project
,
cmd
.
join
(
' '
),
output
)
end
...
...
@@ -42,14 +42,14 @@ module Backup
path_to_wiki_bundle
=
path_to_bundle
(
wiki
)
if
File
.
exist?
(
path_to_wiki_repo
)
$
progress
.
print
" *
#{
wiki
.
path_with_namespace
}
... "
progress
.
print
" *
#{
wiki
.
path_with_namespace
}
... "
if
empty_wiki_repo?
(
wiki
)
$
progress
.
puts
" [SKIPPED]"
.
color
(
:cyan
)
progress
.
puts
" [SKIPPED]"
.
color
(
:cyan
)
else
cmd
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
--git-dir=
#{
path_to_wiki_repo
}
bundle create
#{
path_to_wiki_bundle
}
--all)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
$
progress
.
puts
" [DONE]"
.
color
(
:green
)
progress
.
puts
" [DONE]"
.
color
(
:green
)
else
progress_warn
(
wiki
,
cmd
.
join
(
' '
),
output
)
end
...
...
@@ -71,7 +71,7 @@ module Backup
end
Project
.
find_each
(
batch_size:
1000
)
do
|
project
|
$
progress
.
print
" *
#{
project
.
path_with_namespace
}
... "
progress
.
print
" *
#{
project
.
path_with_namespace
}
... "
path_to_project_repo
=
path_to_repo
(
project
)
path_to_project_bundle
=
path_to_bundle
(
project
)
...
...
@@ -85,7 +85,7 @@ module Backup
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
$
progress
.
puts
"[DONE]"
.
color
(
:green
)
progress
.
puts
"[DONE]"
.
color
(
:green
)
else
progress_warn
(
project
,
cmd
.
join
(
' '
),
output
)
end
...
...
@@ -104,7 +104,7 @@ module Backup
path_to_wiki_bundle
=
path_to_bundle
(
wiki
)
if
File
.
exist?
(
path_to_wiki_bundle
)
$
progress
.
print
" *
#{
wiki
.
path_with_namespace
}
... "
progress
.
print
" *
#{
wiki
.
path_with_namespace
}
... "
# If a wiki bundle exists, first remove the empty repo
# that was initialized with ProjectWiki.new() and then
...
...
@@ -114,19 +114,19 @@ module Backup
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
$
progress
.
puts
" [DONE]"
.
color
(
:green
)
progress
.
puts
" [DONE]"
.
color
(
:green
)
else
progress_warn
(
project
,
cmd
.
join
(
' '
),
output
)
end
end
end
$
progress
.
print
'Put GitLab hooks in repositories dirs'
.
color
(
:yellow
)
progress
.
print
'Put GitLab hooks in repositories dirs'
.
color
(
:yellow
)
cmd
=
%W(
#{
Gitlab
.
config
.
gitlab_shell
.
path
}
/bin/create-hooks)
+
repository_storage_paths_args
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
$
progress
.
puts
" [DONE]"
.
color
(
:green
)
progress
.
puts
" [DONE]"
.
color
(
:green
)
else
puts
" [FAILED]"
.
color
(
:red
)
puts
"failed:
#{
cmd
}
"
...
...
@@ -184,22 +184,14 @@ module Backup
private
def
progress_warn
(
project
,
cmd
,
output
)
$
progress
.
puts
"[WARNING] Executing
#{
cmd
}
"
.
color
(
:orange
)
$
progress
.
puts
"Ignoring error on
#{
project
.
path_with_namespace
}
-
#{
output
}
"
.
color
(
:orange
)
progress
.
puts
"[WARNING] Executing
#{
cmd
}
"
.
color
(
:orange
)
progress
.
puts
"Ignoring error on
#{
project
.
path_with_namespace
}
-
#{
output
}
"
.
color
(
:orange
)
end
def
empty_repo?
(
project
)
project
.
empty_repo?
def
empty_repo?
(
project
_or_wiki
)
project
_or_wiki
.
repository
.
empty_repo?
rescue
=>
e
$progress
.
puts
"Ignoring error on
#{
project
.
full_path
}
repository -
#{
e
.
message
}
"
.
color
(
:orange
)
false
end
def
empty_wiki_repo?
(
wiki
)
wiki
.
repository
.
empty?
rescue
=>
e
$progress
.
puts
"Ignoring error on
#{
wiki
.
path_with_namespace
}
repository -
#{
e
.
message
}
"
.
color
(
:orange
)
progress
.
puts
"Ignoring repository error and continuing backing up project:
#{
project_or_wiki
.
path_with_namespace
}
-
#{
e
.
message
}
"
.
color
(
:orange
)
false
end
...
...
@@ -207,5 +199,9 @@ module Backup
def
repository_storage_paths_args
Gitlab
.
config
.
repositories
.
storages
.
values
.
map
{
|
rs
|
rs
[
'path'
]
}
end
def
progress
progress
end
end
end
spec/lib/gitlab/backup/repository_spec.rb
浏览文件 @
8acb0f55
...
...
@@ -12,18 +12,13 @@ describe Backup::Repository, lib: true do
string
end
@old_progress
=
$progress
# rubocop:disable Style/GlobalVars
$progress
=
progress
# rubocop:disable Style/GlobalVars
end
after
do
$progress
=
@old_progress
# rubocop:disable Style/GlobalVars
allow_any_instance_of
(
described_class
).
to
receive
(
:progress
).
and_return
(
progress
)
end
describe
'#dump'
do
describe
'repo failure'
do
before
do
allow_any_instance_of
(
Project
).
to
receive
(
:empty_repo?
).
and_raise
(
Rugged
::
OdbError
)
allow_any_instance_of
(
Repository
).
to
receive
(
:empty_repo?
).
and_raise
(
Rugged
::
OdbError
)
allow
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
and_return
([
'normal output'
,
0
])
end
...
...
@@ -34,13 +29,13 @@ describe Backup::Repository, lib: true do
it
'shows the appropriate error'
do
described_class
.
new
.
dump
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"Ignoring
error on
#{
project
.
full_path
}
repository
- Rugged::OdbError"
)
expect
(
progress
).
to
have_received
(
:puts
).
with
(
"Ignoring
repository error and continuing backing up project:
#{
project
.
full_path
}
- Rugged::OdbError"
)
end
end
describe
'command failure'
do
before
do
allow_any_instance_of
(
Project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
allow_any_instance_of
(
Repository
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
allow
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
and_return
([
'error'
,
1
])
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录