Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
79620c50
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,体验更适合开发者的 AI 搜索 >>
提交
79620c50
编写于
5月 12, 2016
作者:
Z
Zeger-Jan van de Weg
提交者:
Alfredo Sumaran
5月 20, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update API and fetching task
上级
1f5fcb63
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
41 deletion
+51
-41
lib/gitlab/gitignore.rb
lib/gitlab/gitignore.rb
+14
-26
lib/tasks/gitlab/update_gitignore.rake
lib/tasks/gitlab/update_gitignore.rake
+32
-12
spec/lib/gitlab/gitignore_spec.rb
spec/lib/gitlab/gitignore_spec.rb
+3
-1
spec/requests/api/gitignores_spec.rb
spec/requests/api/gitignores_spec.rb
+2
-2
未找到文件。
lib/gitlab/gitignore.rb
浏览文件 @
79620c50
...
...
@@ -2,15 +2,16 @@ module Gitlab
class
Gitignore
FILTER_REGEX
=
/\.gitignore\z/
.
freeze
attr_accessor
:name
,
:directory
def
initialize
(
path
)
@path
=
path
end
def
initialize
(
name
,
directory
)
@name
=
name
@directory
=
directory
def
name
File
.
basename
(
@path
,
'.gitignore'
)
end
def
content
File
.
read
(
path
)
File
.
read
(
@
path
)
end
class
<<
self
...
...
@@ -22,46 +23,33 @@ module Gitlab
file_name
=
"
#{
key
}
.gitignore"
directory
=
select_directory
(
file_name
)
directory
?
new
(
key
,
directory
)
:
nil
directory
?
new
(
File
.
join
(
directory
,
file_name
)
)
:
nil
end
def
global
files_for_folder
(
global_dir
).
map
{
|
f
|
new
(
f
,
global_dir
)
}
files_for_folder
(
global_dir
).
map
{
|
f
ile
|
new
(
File
.
join
(
global_dir
,
file
)
)
}
end
def
languages_frameworks
files_for_folder
(
gitignore_dir
).
map
{
|
f
|
new
(
f
,
gitignore_dir
)
}
files_for_folder
(
gitignore_dir
).
map
{
|
f
ile
|
new
(
File
.
join
(
gitignore_dir
,
file
)
)
}
end
end
private
def
path
File
.
expand_path
(
"
#{
name
}
.gitignore"
,
directory
)
end
private
class
<<
self
def
select_directory
(
file_name
)
[
self
.
gitignore_dir
,
self
.
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
expand_path
(
file_name
,
dir
))
}
[
gitignore_dir
,
global_dir
].
find
{
|
dir
|
File
.
exist?
(
File
.
join
(
dir
,
file_name
))
}
end
def
global_dir
File
.
expand_path
(
'Global'
,
gitignore_dir
)
File
.
join
(
gitignore_dir
,
'Global'
)
end
def
gitignore_dir
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
)
Rails
.
root
.
join
(
'vendor/gitignore'
)
end
def
files_for_folder
(
dir
)
gitignores
=
[]
Dir
.
entries
(
dir
).
each
do
|
e
|
next
unless
e
.
end_with?
(
'.gitignore'
)
gitignores
<<
e
.
gsub
(
FILTER_REGEX
,
''
)
end
gitignores
Dir
.
glob
(
"
#{
dir
.
to_s
}
/*.gitignore"
).
map
{
|
file
|
file
.
gsub
(
FILTER_REGEX
,
''
)
}
end
end
end
...
...
lib/tasks/gitlab/update_gitignore.rake
浏览文件 @
79620c50
namespace
:gitlab
do
desc
"GitLab | Update gitignore"
task
:update_gitignore
do
dir
=
File
.
expand_path
(
'vendor'
,
Rails
.
root
)
FileUtils
.
cd
(
dir
)
unless
clone_gitignores
puts
"Cloning the gitignores failed"
.
red
return
end
dir
=
File
.
expand_path
(
'gitignore'
,
dir
)
clone_gitignores
(
dir
)
remove_unneeded_files
(
dir
)
remove_unneeded_files
(
gitignore_directory
)
remove_unneeded_files
(
global_directory
)
puts
"Done"
.
green
end
def
clone_gitignores
(
dir
)
FileUtils
.
rm_rf
(
dir
)
if
Dir
.
exist?
(
dir
)
def
clone_gitignores
FileUtils
.
rm_rf
(
gitignore_directory
)
if
Dir
.
exist?
(
gitignore_directory
)
FileUtils
.
cd
vendor_directory
system
(
'git clone --depth=1 --branch=master https://github.com/github/gitignore.git'
)
end
def
remove_unneeded_files
(
dir
)
[
File
.
expand_path
(
'Global'
,
dir
),
dir
].
each
do
|
path
|
Dir
.
entries
(
path
).
reject
{
|
e
|
e
=~
/(\.{1,2}|Global|\.gitignore)\z/
}.
each
do
|
file
|
FileUtils
.
rm_rf
File
.
expand_path
(
file
,
path
)
end
# Retain only certain files:
# - The LICENSE, because we have to
# - The sub dir global
# - The gitignores themself
# - Dir.entires returns also the entries '.' and '..'
def
remove_unneeded_files
(
path
)
Dir
.
foreach
(
path
)
do
|
file
|
FileUtils
.
rm_rf
(
File
.
join
(
path
,
file
))
unless
file
=~
/(\.{1,2}|LICENSE|Global|\.gitignore)\z/
end
end
private
def
vendor_directory
Rails
.
root
.
join
(
'vendor'
)
end
def
gitignore_directory
File
.
join
(
vendor_directory
,
'gitignore'
)
end
def
global_directory
File
.
join
(
gitignore_directory
,
'Global'
)
end
end
spec/lib/gitlab/gitignore_spec.rb
浏览文件 @
79620c50
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Gitignore
do
subject
{
Gitlab
::
Gitignore
}
describe
'.all'
do
it
'strips the gitignore suffix'
do
expect
(
subject
.
all
.
first
.
name
).
not_to
end_with
(
'.gitignore'
)
...
...
@@ -24,12 +25,13 @@ describe Gitlab::Gitignore do
ruby
=
subject
.
find
(
'Ruby'
)
expect
(
ruby
).
to
be_a
Gitlab
::
Gitignore
expect
(
ruby
.
name
).
to
eq
(
'Ruby'
)
end
end
describe
'#content'
do
it
'loads the full file'
do
gitignore
=
subject
.
new
(
'Ruby'
,
File
.
expand_path
(
'vendor/gitignore'
,
Rails
.
root
))
gitignore
=
subject
.
new
(
Rails
.
root
.
join
(
'vendor/gitignore/Ruby.gitignore'
))
expect
(
gitignore
.
name
).
to
eq
'Ruby'
expect
(
gitignore
.
content
).
to
start_with
(
'*.gem'
)
...
...
spec/requests/api/gitignores_spec.rb
浏览文件 @
79620c50
...
...
@@ -13,8 +13,8 @@ describe API::Gitignores, api: true do
describe
'Entity GitignoresList'
do
before
{
get
api
(
'/gitignores'
)
}
it
{
expect
(
json_response
.
first
[
'name'
]).
to
be_truthy
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
falsey
}
it
{
expect
(
json_response
.
first
[
'name'
]).
not_to
be_nil
}
it
{
expect
(
json_response
.
first
[
'content'
]).
to
be_
nil
}
end
describe
'GET /gitignores'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录