git_cloner 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +4 -0
- data/README.md +37 -4
- data/lib/git_cloner/version.rb +1 -1
- data/lib/git_cloner_core.rb +124 -110
- data/rubocop-todo.yml +48 -0
- data/spec/git_cloner_core_spec.rb +339 -195
- metadata +18 -16
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install git_cloner
|
18
18
|
|
19
|
-
## Usage
|
19
|
+
## CLI-Usage
|
20
20
|
|
21
21
|
### generate Gitclonerfile
|
22
22
|
|
@@ -34,12 +34,19 @@ gitcloner init
|
|
34
34
|
default_output "./"
|
35
35
|
|
36
36
|
# git repositries
|
37
|
-
#
|
38
|
-
#
|
37
|
+
# repos allow only Array(in Array, Hash[:place, :output, :copies])
|
38
|
+
# copies is option.
|
39
|
+
# copies must have Array[Hash{:from, :to}].
|
40
|
+
# you can copy files or directories.
|
41
|
+
# repos's default value => []
|
39
42
|
repos [
|
40
43
|
{
|
41
44
|
place: 'https://github.com/tbpgr/rspec_piccolo.git',
|
42
|
-
output: './tmp'
|
45
|
+
output: './tmp',
|
46
|
+
copies: [
|
47
|
+
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
48
|
+
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
49
|
+
]
|
43
50
|
}
|
44
51
|
]
|
45
52
|
~~~
|
@@ -88,7 +95,33 @@ $ tree
|
|
88
95
|
└many files...
|
89
96
|
~~~
|
90
97
|
|
98
|
+
## Direct Usage
|
99
|
+
if you want to use GitCloner directry, you can use like this sample.
|
100
|
+
|
101
|
+
~~~ruby
|
102
|
+
require 'git_cloner_core'
|
103
|
+
|
104
|
+
default_output = "./",
|
105
|
+
repos = [
|
106
|
+
{
|
107
|
+
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
108
|
+
output: "./tmp",
|
109
|
+
copies: [
|
110
|
+
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
111
|
+
{from: "./tmp/rspec_piccolo/spec", to: "./sample"},
|
112
|
+
{from: "./tmp/rspec_piccolo/spec/spec_helper.rb", to: "./helper/helper.rb"},
|
113
|
+
]
|
114
|
+
},
|
115
|
+
{
|
116
|
+
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
117
|
+
}
|
118
|
+
]
|
119
|
+
|
120
|
+
GitCloner::Core.new.clone default_output, repos
|
121
|
+
~~~
|
122
|
+
|
91
123
|
## History
|
124
|
+
* version 0.0.3 : enable direct call clone.
|
92
125
|
* version 0.0.2 : add files,directories copy.
|
93
126
|
* version 0.0.1 : first release.
|
94
127
|
|
data/lib/git_cloner/version.rb
CHANGED
data/lib/git_cloner_core.rb
CHANGED
@@ -1,110 +1,124 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'git_cloner_dsl'
|
3
|
-
require
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
module GitCloner
|
7
|
-
# GitCloner Core
|
8
|
-
class Core
|
9
|
-
GIT_CLONER_FILE =
|
10
|
-
GIT_CLONER_TEMPLATE
|
11
|
-
# encoding: utf-8
|
12
|
-
|
13
|
-
# default_output place
|
14
|
-
# default_output is required
|
15
|
-
# default_output allow only String
|
16
|
-
# default_output's default value => "./"
|
17
|
-
default_output "./"
|
18
|
-
|
19
|
-
# git repositries
|
20
|
-
#
|
21
|
-
# copies is option.
|
22
|
-
# copies must have Array[Hash{:from, :to}].
|
23
|
-
# you can copy files or directories.
|
24
|
-
#
|
25
|
-
repos [
|
26
|
-
{
|
27
|
-
place: 'https://github.com/tbpgr/rspec_piccolo.git',
|
28
|
-
output: './tmp',
|
29
|
-
copies: [
|
30
|
-
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
31
|
-
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
32
|
-
]
|
33
|
-
}
|
34
|
-
]
|
35
|
-
EOS
|
36
|
-
|
37
|
-
|
38
|
-
def init
|
39
|
-
File.open(GIT_CLONER_FILE,
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
def execute
|
44
|
-
dsl = get_dsl
|
45
|
-
base = Dir.pwd
|
46
|
-
default_output = dsl.git_cloner.default_output
|
47
|
-
tmp_repos = dsl.git_cloner.repos
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'git_cloner_dsl'
|
3
|
+
require "uri"
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module GitCloner
|
7
|
+
# GitCloner Core
|
8
|
+
class Core
|
9
|
+
GIT_CLONER_FILE = "Gitclonerfile"
|
10
|
+
GIT_CLONER_TEMPLATE =<<-EOS
|
11
|
+
# encoding: utf-8
|
12
|
+
|
13
|
+
# default_output place
|
14
|
+
# default_output is required
|
15
|
+
# default_output allow only String
|
16
|
+
# default_output's default value => "./"
|
17
|
+
default_output "./"
|
18
|
+
|
19
|
+
# git repositries
|
20
|
+
# repos allow only Array(in Array, Hash[:place, :output, :copies])
|
21
|
+
# copies is option.
|
22
|
+
# copies must have Array[Hash{:from, :to}].
|
23
|
+
# you can copy files or directories.
|
24
|
+
# repos's default value => []
|
25
|
+
repos [
|
26
|
+
{
|
27
|
+
place: 'https://github.com/tbpgr/rspec_piccolo.git',
|
28
|
+
output: './tmp',
|
29
|
+
copies: [
|
30
|
+
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
31
|
+
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
]
|
35
|
+
EOS
|
36
|
+
|
37
|
+
#== generate Gitclonerfile to current directory.
|
38
|
+
def init
|
39
|
+
File.open(GIT_CLONER_FILE, "w") {|f|f.puts GIT_CLONER_TEMPLATE}
|
40
|
+
end
|
41
|
+
|
42
|
+
#== clone git repositories
|
43
|
+
def execute
|
44
|
+
dsl = get_dsl
|
45
|
+
base = Dir.pwd
|
46
|
+
default_output = dsl.git_cloner.default_output
|
47
|
+
tmp_repos = dsl.git_cloner.repos
|
48
|
+
git_clone(default_output, tmp_repos, base)
|
49
|
+
end
|
50
|
+
|
51
|
+
def clone(default_output, repos = [])
|
52
|
+
default_output ||= './'
|
53
|
+
base = Dir.pwd
|
54
|
+
dsl = GitCloner::Dsl.new
|
55
|
+
|
56
|
+
default_output = dsl.git_cloner.default_output
|
57
|
+
tmp_repos = dsl.git_cloner.repos
|
58
|
+
git_clone(default_output, repos, base)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def git_clone(default_output, tmp_repos, base)
|
64
|
+
fail ArgumentError, 'invalid repos. repos must be Array.' unless tmp_repos.is_a? Array
|
65
|
+
tmp_repos.each do |repo|
|
66
|
+
fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a? Hash
|
67
|
+
fail ArgumentError, 'invalid key. Hash musft contain :place key' unless repo.has_key? :place
|
68
|
+
repo_name = get_repo_name repo[:place]
|
69
|
+
target = get_output(repo[:output], default_output)
|
70
|
+
FileUtils.mkdir_p(target) unless Dir.exists? target
|
71
|
+
Dir.chdir(target)
|
72
|
+
result = system("git clone #{repo[:place]} --depth=1")
|
73
|
+
remove_dot_git_directory repo_name
|
74
|
+
show_result_message(result, repo_name)
|
75
|
+
Dir.chdir base
|
76
|
+
next if repo[:copies].nil?
|
77
|
+
copy_targets repo[:copies]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_dsl
|
82
|
+
src = read_dsl
|
83
|
+
dsl = GitCloner::Dsl.new
|
84
|
+
dsl.instance_eval src
|
85
|
+
dsl
|
86
|
+
end
|
87
|
+
|
88
|
+
def read_dsl
|
89
|
+
File.open(GIT_CLONER_FILE) {|f|f.read}
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_repo_name(place)
|
93
|
+
uri = URI(place)
|
94
|
+
uri.path.gsub(/.*\//, '').gsub('.git', '')
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_output(output, default_output)
|
98
|
+
require 'test_toolbox'
|
99
|
+
output.nil? ? default_output : output
|
100
|
+
end
|
101
|
+
|
102
|
+
def remove_dot_git_directory(repo_name)
|
103
|
+
Dir.chdir("./#{repo_name}")
|
104
|
+
FileUtils.rm_rf('.git') if Dir.exists? '.git'
|
105
|
+
end
|
106
|
+
|
107
|
+
def show_result_message(result, repo_name)
|
108
|
+
if result
|
109
|
+
puts "clone #{Dir.pwd}/#{repo_name} complete"
|
110
|
+
else
|
111
|
+
puts "clone #{Dir.pwd}/#{repo_name} fail"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def copy_targets(copies)
|
116
|
+
copies.each do |cp_dir|
|
117
|
+
fail ArgumentError, 'invalid repos. copies must have from' unless cp_dir[:from]
|
118
|
+
fail ArgumentError, 'invalid repos. copies must have to' unless cp_dir[:to]
|
119
|
+
FileUtils.mkdir_p(cp_dir[:to]) unless Dir.exists? File.dirname(cp_dir[:to])
|
120
|
+
FileUtils.cp_r cp_dir[:from], cp_dir[:to]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/rubocop-todo.yml
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`.
|
2
|
+
# The point is for the user to remove these configuration records
|
3
|
+
# one by one as the offences are removed from the code base.
|
4
|
+
|
5
|
+
Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
EmptyLinesAroundBody:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Encoding:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Eval:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
HashMethods:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Lambda:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
LeadingCommentSpace:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
LineLength:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
MethodLength:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
SpaceAroundBlockBraces:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
SpaceAroundOperators:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
SpaceInsideHashLiteralBraces:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
StringLiterals:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
TrailingWhitespace:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
UselessAssignment:
|
48
|
+
Enabled: false
|
@@ -1,195 +1,339 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'git_cloner_core'
|
4
|
-
|
5
|
-
describe GitCloner::Core do
|
6
|
-
context :init do
|
7
|
-
OUTPUT_DSL_TMP_DIR = 'generate_dsl'
|
8
|
-
cases = [
|
9
|
-
{
|
10
|
-
case_no: 1,
|
11
|
-
case_title: 'valid case',
|
12
|
-
expected_file: GitCloner::Core::GIT_CLONER_FILE,
|
13
|
-
expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
|
14
|
-
},
|
15
|
-
]
|
16
|
-
|
17
|
-
cases.each do |c|
|
18
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
19
|
-
begin
|
20
|
-
case_before c
|
21
|
-
|
22
|
-
# -- given --
|
23
|
-
git_cloner_core = GitCloner::Core.new
|
24
|
-
|
25
|
-
# -- when --
|
26
|
-
git_cloner_core.init
|
27
|
-
|
28
|
-
# -- then --
|
29
|
-
actual = File.read("./#{c[:expected_file]}")
|
30
|
-
expect(actual).to eq(c[:expected_content])
|
31
|
-
ensure
|
32
|
-
case_after c
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def case_before(c)
|
37
|
-
Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
|
38
|
-
Dir.chdir(OUTPUT_DSL_TMP_DIR)
|
39
|
-
end
|
40
|
-
|
41
|
-
def case_after(c)
|
42
|
-
Dir.chdir('../')
|
43
|
-
FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context :execute do
|
49
|
-
OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
|
50
|
-
GIT_CLONER_CASE1 = <<-EOF
|
51
|
-
# encoding: utf-8
|
52
|
-
default_output "./"
|
53
|
-
repos [
|
54
|
-
{
|
55
|
-
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
56
|
-
output: "./tmp",
|
57
|
-
},
|
58
|
-
{
|
59
|
-
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
60
|
-
}
|
61
|
-
]
|
62
|
-
EOF
|
63
|
-
|
64
|
-
RESULT_CASE1 = <<-EOF
|
65
|
-
# encoding: utf-8
|
66
|
-
require 'templatable'
|
67
|
-
|
68
|
-
class SampleUse
|
69
|
-
include Templatable
|
70
|
-
template <<-EOS
|
71
|
-
line1:<%=placeholders[:param1]%>
|
72
|
-
line2:<%=placeholders[:param2]%>
|
73
|
-
EOS
|
74
|
-
|
75
|
-
def manufactured_param1
|
76
|
-
# TODO: implement your logic
|
77
|
-
end
|
78
|
-
|
79
|
-
def manufactured_param2
|
80
|
-
# TODO: implement your logic
|
81
|
-
end
|
82
|
-
end
|
83
|
-
EOF
|
84
|
-
|
85
|
-
GIT_CLONER_CASE2 = <<-EOF
|
86
|
-
# encoding: utf-8
|
87
|
-
default_output "./"
|
88
|
-
repos "invalid"
|
89
|
-
EOF
|
90
|
-
|
91
|
-
GIT_CLONER_CASE3 = <<-EOF
|
92
|
-
# encoding: utf-8
|
93
|
-
default_output "./"
|
94
|
-
repos ["invalid"]
|
95
|
-
EOF
|
96
|
-
|
97
|
-
GIT_CLONER_CASE4 = <<-EOF
|
98
|
-
# encoding: utf-8
|
99
|
-
default_output "./"
|
100
|
-
repos [
|
101
|
-
{
|
102
|
-
plase: "typo"
|
103
|
-
}
|
104
|
-
]
|
105
|
-
EOF
|
106
|
-
|
107
|
-
GIT_CLONER_CASE5 = <<-EOF
|
108
|
-
# encoding: utf-8
|
109
|
-
default_output "./"
|
110
|
-
repos [
|
111
|
-
{
|
112
|
-
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
113
|
-
output: "./tmp",
|
114
|
-
copies: [
|
115
|
-
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
116
|
-
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
117
|
-
]
|
118
|
-
},
|
119
|
-
{
|
120
|
-
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
121
|
-
}
|
122
|
-
]
|
123
|
-
EOF
|
124
|
-
|
125
|
-
cases = [
|
126
|
-
{
|
127
|
-
case_no: 1,
|
128
|
-
case_title: 'valid case',
|
129
|
-
input: GIT_CLONER_CASE1,
|
130
|
-
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
|
131
|
-
},
|
132
|
-
{
|
133
|
-
case_no: 2,
|
134
|
-
case_title: 'invalid repos case(String)',
|
135
|
-
input: GIT_CLONER_CASE2,
|
136
|
-
has_error: true,
|
137
|
-
},
|
138
|
-
{
|
139
|
-
case_no: 3,
|
140
|
-
case_title: 'invalid repos case(Array[Not Hash])',
|
141
|
-
input: GIT_CLONER_CASE3,
|
142
|
-
has_error: true,
|
143
|
-
},
|
144
|
-
{
|
145
|
-
case_no: 4,
|
146
|
-
case_title: 'invalid repos case(Array[Hash] but invalid hash key)',
|
147
|
-
input: GIT_CLONER_CASE4,
|
148
|
-
has_error: true,
|
149
|
-
},
|
150
|
-
{
|
151
|
-
case_no: 5,
|
152
|
-
case_title: 'clone git and copy directories case',
|
153
|
-
input: GIT_CLONER_CASE5,
|
154
|
-
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo'],
|
155
|
-
},
|
156
|
-
]
|
157
|
-
|
158
|
-
cases.each do |c|
|
159
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
160
|
-
begin
|
161
|
-
case_before c
|
162
|
-
|
163
|
-
# -- given --
|
164
|
-
git_cloner_core = GitCloner::Core.new
|
165
|
-
|
166
|
-
# -- when --
|
167
|
-
if c[:has_error]
|
168
|
-
lambda { git_cloner_core.execute }.should raise_error(StandardError)
|
169
|
-
next
|
170
|
-
end
|
171
|
-
git_cloner_core.execute
|
172
|
-
|
173
|
-
# -- then --
|
174
|
-
c[:expecteds].each do |expected|
|
175
|
-
actual_exists = File.exists? expected
|
176
|
-
expect(actual_exists).to be_true
|
177
|
-
end
|
178
|
-
ensure
|
179
|
-
case_after c
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def case_before(c)
|
184
|
-
Dir.mkdir(OUTPUT_GIT_CLONER_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
|
185
|
-
Dir.chdir(OUTPUT_GIT_CLONER_TMP_DIR)
|
186
|
-
File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
|
187
|
-
end
|
188
|
-
|
189
|
-
def case_after(c)
|
190
|
-
Dir.chdir('../')
|
191
|
-
FileUtils.rm_rf(OUTPUT_GIT_CLONER_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'git_cloner_core'
|
4
|
+
|
5
|
+
describe GitCloner::Core do
|
6
|
+
context :init do
|
7
|
+
OUTPUT_DSL_TMP_DIR = 'generate_dsl'
|
8
|
+
cases = [
|
9
|
+
{
|
10
|
+
case_no: 1,
|
11
|
+
case_title: 'valid case',
|
12
|
+
expected_file: GitCloner::Core::GIT_CLONER_FILE,
|
13
|
+
expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
|
14
|
+
},
|
15
|
+
]
|
16
|
+
|
17
|
+
cases.each do |c|
|
18
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
19
|
+
begin
|
20
|
+
case_before c
|
21
|
+
|
22
|
+
# -- given --
|
23
|
+
git_cloner_core = GitCloner::Core.new
|
24
|
+
|
25
|
+
# -- when --
|
26
|
+
git_cloner_core.init
|
27
|
+
|
28
|
+
# -- then --
|
29
|
+
actual = File.read("./#{c[:expected_file]}")
|
30
|
+
expect(actual).to eq(c[:expected_content])
|
31
|
+
ensure
|
32
|
+
case_after c
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def case_before(c)
|
37
|
+
Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
|
38
|
+
Dir.chdir(OUTPUT_DSL_TMP_DIR)
|
39
|
+
end
|
40
|
+
|
41
|
+
def case_after(c)
|
42
|
+
Dir.chdir('../')
|
43
|
+
FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context :execute do
|
49
|
+
OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
|
50
|
+
GIT_CLONER_CASE1 = <<-EOF
|
51
|
+
# encoding: utf-8
|
52
|
+
default_output "./"
|
53
|
+
repos [
|
54
|
+
{
|
55
|
+
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
56
|
+
output: "./tmp",
|
57
|
+
},
|
58
|
+
{
|
59
|
+
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
60
|
+
}
|
61
|
+
]
|
62
|
+
EOF
|
63
|
+
|
64
|
+
RESULT_CASE1 = <<-EOF
|
65
|
+
# encoding: utf-8
|
66
|
+
require 'templatable'
|
67
|
+
|
68
|
+
class SampleUse
|
69
|
+
include Templatable
|
70
|
+
template <<-EOS
|
71
|
+
line1:<%=placeholders[:param1]%>
|
72
|
+
line2:<%=placeholders[:param2]%>
|
73
|
+
EOS
|
74
|
+
|
75
|
+
def manufactured_param1
|
76
|
+
# TODO: implement your logic
|
77
|
+
end
|
78
|
+
|
79
|
+
def manufactured_param2
|
80
|
+
# TODO: implement your logic
|
81
|
+
end
|
82
|
+
end
|
83
|
+
EOF
|
84
|
+
|
85
|
+
GIT_CLONER_CASE2 = <<-EOF
|
86
|
+
# encoding: utf-8
|
87
|
+
default_output "./"
|
88
|
+
repos "invalid"
|
89
|
+
EOF
|
90
|
+
|
91
|
+
GIT_CLONER_CASE3 = <<-EOF
|
92
|
+
# encoding: utf-8
|
93
|
+
default_output "./"
|
94
|
+
repos ["invalid"]
|
95
|
+
EOF
|
96
|
+
|
97
|
+
GIT_CLONER_CASE4 = <<-EOF
|
98
|
+
# encoding: utf-8
|
99
|
+
default_output "./"
|
100
|
+
repos [
|
101
|
+
{
|
102
|
+
plase: "typo"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
EOF
|
106
|
+
|
107
|
+
GIT_CLONER_CASE5 = <<-EOF
|
108
|
+
# encoding: utf-8
|
109
|
+
default_output "./"
|
110
|
+
repos [
|
111
|
+
{
|
112
|
+
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
113
|
+
output: "./tmp",
|
114
|
+
copies: [
|
115
|
+
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
116
|
+
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
117
|
+
]
|
118
|
+
},
|
119
|
+
{
|
120
|
+
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
121
|
+
}
|
122
|
+
]
|
123
|
+
EOF
|
124
|
+
|
125
|
+
cases = [
|
126
|
+
{
|
127
|
+
case_no: 1,
|
128
|
+
case_title: 'valid case',
|
129
|
+
input: GIT_CLONER_CASE1,
|
130
|
+
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
|
131
|
+
},
|
132
|
+
{
|
133
|
+
case_no: 2,
|
134
|
+
case_title: 'invalid repos case(String)',
|
135
|
+
input: GIT_CLONER_CASE2,
|
136
|
+
has_error: true,
|
137
|
+
},
|
138
|
+
{
|
139
|
+
case_no: 3,
|
140
|
+
case_title: 'invalid repos case(Array[Not Hash])',
|
141
|
+
input: GIT_CLONER_CASE3,
|
142
|
+
has_error: true,
|
143
|
+
},
|
144
|
+
{
|
145
|
+
case_no: 4,
|
146
|
+
case_title: 'invalid repos case(Array[Hash] but invalid hash key)',
|
147
|
+
input: GIT_CLONER_CASE4,
|
148
|
+
has_error: true,
|
149
|
+
},
|
150
|
+
{
|
151
|
+
case_no: 5,
|
152
|
+
case_title: 'clone git and copy directories case',
|
153
|
+
input: GIT_CLONER_CASE5,
|
154
|
+
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo'],
|
155
|
+
},
|
156
|
+
]
|
157
|
+
|
158
|
+
cases.each do |c|
|
159
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
160
|
+
begin
|
161
|
+
case_before c
|
162
|
+
|
163
|
+
# -- given --
|
164
|
+
git_cloner_core = GitCloner::Core.new
|
165
|
+
|
166
|
+
# -- when --
|
167
|
+
if c[:has_error]
|
168
|
+
lambda { git_cloner_core.execute }.should raise_error(StandardError)
|
169
|
+
next
|
170
|
+
end
|
171
|
+
git_cloner_core.execute
|
172
|
+
|
173
|
+
# -- then --
|
174
|
+
c[:expecteds].each do |expected|
|
175
|
+
actual_exists = File.exists? expected
|
176
|
+
expect(actual_exists).to be_true
|
177
|
+
end
|
178
|
+
ensure
|
179
|
+
case_after c
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def case_before(c)
|
184
|
+
Dir.mkdir(OUTPUT_GIT_CLONER_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
|
185
|
+
Dir.chdir(OUTPUT_GIT_CLONER_TMP_DIR)
|
186
|
+
File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
|
187
|
+
end
|
188
|
+
|
189
|
+
def case_after(c)
|
190
|
+
Dir.chdir('../')
|
191
|
+
FileUtils.rm_rf(OUTPUT_GIT_CLONER_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_TMP_DIR
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context :init do
|
197
|
+
OUTPUT_DSL_TMP_DIR = 'generate_dsl'
|
198
|
+
cases = [
|
199
|
+
{
|
200
|
+
case_no: 1,
|
201
|
+
case_title: 'valid case',
|
202
|
+
expected_file: GitCloner::Core::GIT_CLONER_FILE,
|
203
|
+
expected_content: GitCloner::Core::GIT_CLONER_TEMPLATE,
|
204
|
+
},
|
205
|
+
]
|
206
|
+
|
207
|
+
cases.each do |c|
|
208
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
209
|
+
begin
|
210
|
+
case_before c
|
211
|
+
|
212
|
+
# -- given --
|
213
|
+
git_cloner_core = GitCloner::Core.new
|
214
|
+
|
215
|
+
# -- when --
|
216
|
+
git_cloner_core.init
|
217
|
+
|
218
|
+
# -- then --
|
219
|
+
actual = File.read("./#{c[:expected_file]}")
|
220
|
+
expect(actual).to eq(c[:expected_content])
|
221
|
+
ensure
|
222
|
+
case_after c
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def case_before(c)
|
227
|
+
Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
|
228
|
+
Dir.chdir(OUTPUT_DSL_TMP_DIR)
|
229
|
+
end
|
230
|
+
|
231
|
+
def case_after(c)
|
232
|
+
Dir.chdir('../')
|
233
|
+
FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context :clone do
|
239
|
+
OUTPUT_GIT_CLONER_CLONE_TMP_DIR = 'tmp_git_cloner_clone'
|
240
|
+
|
241
|
+
cases = [
|
242
|
+
{
|
243
|
+
case_no: 1,
|
244
|
+
case_title: 'valid case',
|
245
|
+
default_output: "./",
|
246
|
+
repos: [
|
247
|
+
{
|
248
|
+
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
249
|
+
output: "./tmp",
|
250
|
+
},
|
251
|
+
{
|
252
|
+
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
253
|
+
}
|
254
|
+
],
|
255
|
+
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
|
256
|
+
},
|
257
|
+
{
|
258
|
+
case_no: 2,
|
259
|
+
case_title: 'invalid repos case(String)',
|
260
|
+
default_output: "./",
|
261
|
+
repos: "invalid",
|
262
|
+
has_error: true,
|
263
|
+
},
|
264
|
+
{
|
265
|
+
case_no: 3,
|
266
|
+
case_title: 'invalid repos case(Array[Not Hash])',
|
267
|
+
default_output: "./",
|
268
|
+
repos: ["invalid"],
|
269
|
+
has_error: true,
|
270
|
+
},
|
271
|
+
{
|
272
|
+
case_no: 4,
|
273
|
+
default_output: "./",
|
274
|
+
repos: [
|
275
|
+
{
|
276
|
+
plase: "typo"
|
277
|
+
}
|
278
|
+
],
|
279
|
+
has_error: true,
|
280
|
+
},
|
281
|
+
{
|
282
|
+
case_no: 5,
|
283
|
+
case_title: 'clone git and copy directories case',
|
284
|
+
default_output: "./",
|
285
|
+
repos: [
|
286
|
+
{
|
287
|
+
place: "https://github.com/tbpgr/rspec_piccolo.git",
|
288
|
+
output: "./tmp",
|
289
|
+
copies: [
|
290
|
+
{from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
|
291
|
+
{from: "./tmp/rspec_piccolo/spec", to: "./sample"}
|
292
|
+
]
|
293
|
+
},
|
294
|
+
{
|
295
|
+
place: "https://github.com/tbpgr/tbpgr_utils.git",
|
296
|
+
}
|
297
|
+
],
|
298
|
+
expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils', './sample/rspec_piccolo_spec.rb', './sample/spec_helper.rb', './rspec_piccolo'],
|
299
|
+
},
|
300
|
+
]
|
301
|
+
|
302
|
+
cases.each do |c|
|
303
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
304
|
+
begin
|
305
|
+
case_before c
|
306
|
+
|
307
|
+
# -- given --
|
308
|
+
git_cloner_core = GitCloner::Core.new
|
309
|
+
|
310
|
+
# -- when --
|
311
|
+
if c[:has_error]
|
312
|
+
lambda { git_cloner_core.clone(c[:default_output], c[:repos]) }.should raise_error(StandardError)
|
313
|
+
next
|
314
|
+
end
|
315
|
+
git_cloner_core.clone(c[:default_output], c[:repos])
|
316
|
+
|
317
|
+
# -- then --
|
318
|
+
c[:expecteds].each do |expected|
|
319
|
+
actual_exists = File.exists? expected
|
320
|
+
expect(actual_exists).to be_true
|
321
|
+
end
|
322
|
+
ensure
|
323
|
+
case_after c
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def case_before(c)
|
328
|
+
Dir.mkdir(OUTPUT_GIT_CLONER_CLONE_TMP_DIR) unless Dir.exists? OUTPUT_GIT_CLONER_CLONE_TMP_DIR
|
329
|
+
Dir.chdir(OUTPUT_GIT_CLONER_CLONE_TMP_DIR)
|
330
|
+
File.open(GitCloner::Core::GIT_CLONER_FILE, 'w:UTF-8') { |f|f.print c[:input] }
|
331
|
+
end
|
332
|
+
|
333
|
+
def case_after(c)
|
334
|
+
Dir.chdir('../')
|
335
|
+
FileUtils.rm_rf(OUTPUT_GIT_CLONER_CLONE_TMP_DIR) if Dir.exists? OUTPUT_GIT_CLONER_CLONE_TMP_DIR
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_cloner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &28541964 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *28541964
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &28541664 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 4.0.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *28541664
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thor
|
38
|
-
requirement: &
|
38
|
+
requirement: &28541388 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.18.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *28541388
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &28541112 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '1.3'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *28541112
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &28540884 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *28540884
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &28540560 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.14.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *28540560
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &28540260 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: 0.8.2
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *28540260
|
91
91
|
description: GitCloner clone git repositoris from Gitclonerfile settings
|
92
92
|
email:
|
93
93
|
- tbpgr@tbpgr.jp
|
@@ -98,6 +98,7 @@ extra_rdoc_files: []
|
|
98
98
|
files:
|
99
99
|
- .gitignore
|
100
100
|
- .rspec
|
101
|
+
- .rubocop.yml
|
101
102
|
- Gemfile
|
102
103
|
- LICENSE.txt
|
103
104
|
- README.md
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- lib/git_cloner_core.rb
|
109
110
|
- lib/git_cloner_dsl.rb
|
110
111
|
- lib/git_cloner_dsl_model.rb
|
112
|
+
- rubocop-todo.yml
|
111
113
|
- spec/git_cloner_core_spec.rb
|
112
114
|
- spec/spec_helper.rb
|
113
115
|
homepage: https://github.com/tbpgr/git_cloner
|