git_cloner 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,6 +53,11 @@ repos [
53
53
  {
54
54
  place: "https://github.com/tbpgr/rspec_piccolo.git",
55
55
  output: "./tmp",
56
+ copies: [
57
+ {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
58
+ {from: "./tmp/rspec_piccolo/spec", to: "./sample"},
59
+ {from: "./tmp/rspec_piccolo/spec/spec_helper.rb", to: "./helper/helper.rb"},
60
+ ]
56
61
  },
57
62
  {
58
63
  place: "https://github.com/tbpgr/tbpgr_utils.git",
@@ -70,11 +75,23 @@ gitcloner clone
70
75
 
71
76
  ~~~bash
72
77
  $ tree
78
+ ├─helper
79
+ | └spec_helper.rb
80
+ ├─rspec_piccolo
81
+ | └many files...
82
+ ├─sample
83
+ | ├rspec_piccolo_spec.rb
84
+ | └spec_helper.rb
73
85
  ├─tmp
74
- rspec_piccolo
86
+ rspec_piccolo
75
87
  └─tbpgr_utils
88
+ └many files...
76
89
  ~~~
77
90
 
91
+ ## History
92
+ * version 0.0.2 : add files,directories copy.
93
+ * version 0.0.1 : first release.
94
+
78
95
  ## Contributing
79
96
 
80
97
  1. Fork it
data/bin/gitcloner CHANGED
@@ -1,27 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require "git_cloner_core"
5
- require "git_cloner/version"
6
- require "thor"
4
+ require 'git_cloner_core'
5
+ require 'git_cloner/version'
6
+ require 'thor'
7
7
 
8
8
  module GitCloner
9
9
  # GitCloner CLI
10
10
  class CLI < Thor
11
- class_option :help, :type => :boolean, :aliases => '-h', :desc => 'help message.'
12
- class_option :version, :type => :boolean, :desc => 'version'
11
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
12
+ class_option :version, type: :boolean, desc: 'version'
13
13
 
14
- desc "clone", "clone git repositories from Gitclonerfile"
14
+ desc 'clone', 'clone git repositories from Gitclonerfile'
15
15
  def clone
16
16
  GitCloner::Core.new.execute
17
17
  end
18
18
 
19
- desc "init", "generate Gitclonerfile"
19
+ desc 'init', 'generate Gitclonerfile'
20
20
  def init
21
21
  GitCloner::Core.new.init
22
22
  end
23
23
 
24
- desc "version", "version"
24
+ desc 'version', 'version'
25
25
  def version
26
26
  p GitCloner::VERSION
27
27
  end
@@ -1,3 +1,3 @@
1
- module GitCloner
2
- VERSION = "0.0.1"
3
- end
1
+ module GitCloner
2
+ VERSION = '0.0.2'
3
+ end
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
2
  require 'git_cloner_dsl'
3
- require "uri"
3
+ require 'uri'
4
+ require 'fileutils'
4
5
 
5
6
  module GitCloner
6
7
  # GitCloner Core
7
8
  class Core
8
- GIT_CLONER_FILE = "Gitclonerfile"
9
- GIT_CLONER_TEMPLATE =<<-EOS
9
+ GIT_CLONER_FILE = 'Gitclonerfile'
10
+ GIT_CLONER_TEMPLATE = <<-EOS
10
11
  # encoding: utf-8
11
12
 
12
13
  # default_output place
@@ -16,22 +17,29 @@ module GitCloner
16
17
  default_output "./"
17
18
 
18
19
  # git repositries
19
- # repo allow only Array(in Array, Hash[:place, :output])
20
+ # repo 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.
20
24
  # repo's default value => []
21
25
  repos [
22
26
  {
23
27
  place: 'https://github.com/tbpgr/rspec_piccolo.git',
24
- output: './tmp'
28
+ output: './tmp',
29
+ copies: [
30
+ {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"},
31
+ {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
32
+ ]
25
33
  }
26
34
  ]
27
35
  EOS
28
36
 
29
- #== generate Gitclonerfile to current directory.
37
+ # == generate Gitclonerfile to current directory.
30
38
  def init
31
- File.open(GIT_CLONER_FILE, "w") {|f|f.puts GIT_CLONER_TEMPLATE}
39
+ File.open(GIT_CLONER_FILE, 'w') { |f|f.puts GIT_CLONER_TEMPLATE }
32
40
  end
33
41
 
34
- #== clone git repositories
42
+ # == clone git repositories
35
43
  def execute
36
44
  dsl = get_dsl
37
45
  base = Dir.pwd
@@ -40,15 +48,17 @@ repos [
40
48
  fail ArgumentError, 'invalid repos. repos must be Array.' unless tmp_repos.is_a? Array
41
49
  tmp_repos.each do |repo|
42
50
  fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a? Hash
43
- fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.has_key? :place
51
+ fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.key? :place
44
52
  repo_name = get_repo_name repo[:place]
45
- target_dir = get_output(repo[:output], default_output)
46
- FileUtils.mkdir_p(target_dir) unless Dir.exists? target_dir
47
- Dir.chdir(target_dir)
53
+ target = get_output(repo[:output], default_output)
54
+ FileUtils.mkdir_p(target) unless Dir.exists? target
55
+ Dir.chdir(target)
48
56
  result = system("git clone #{repo[:place]} --depth=1")
49
57
  remove_dot_git_directory repo_name
50
58
  show_result_message(result, repo_name)
51
59
  Dir.chdir base
60
+ next if repo[:copies].nil?
61
+ copy_targets repo[:copies]
52
62
  end
53
63
  end
54
64
 
@@ -62,7 +72,7 @@ repos [
62
72
  end
63
73
 
64
74
  def read_dsl
65
- File.open(GIT_CLONER_FILE) {|f|f.read}
75
+ File.open(GIT_CLONER_FILE) { |f|f.read }
66
76
  end
67
77
 
68
78
  def get_repo_name(place)
@@ -83,7 +93,17 @@ repos [
83
93
  if result
84
94
  puts "clone #{Dir.pwd}/#{repo_name} complete"
85
95
  else
86
- pust "clone #{Dir.pwd}/#{repo_name} fail"
96
+ puts "clone #{Dir.pwd}/#{repo_name} fail"
97
+ end
98
+ end
99
+
100
+ def copy_targets(copies)
101
+ copies.each do |cp_dir|
102
+ fail ArgumentError, 'invalid repos. copies must have from' unless cp_dir[:from]
103
+ fail ArgumentError, 'invalid repos. copies must have to' unless cp_dir[:to]
104
+ to_dir = File.dirname(cp_dir[:to])
105
+ FileUtils.mkdir_p(to_dir) unless Dir.exists? to_dir
106
+ FileUtils.cp_r cp_dir[:from], cp_dir[:to]
87
107
  end
88
108
  end
89
109
  end
@@ -7,7 +7,7 @@ module GitCloner
7
7
 
8
8
  # default_output place
9
9
  attr_accessor :default_output
10
- validates :default_output, :presence => true
10
+ validates :default_output, presence: true
11
11
 
12
12
  # git repositries
13
13
  attr_accessor :repos
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
- require "spec_helper"
3
- require "git_cloner_core"
2
+ require 'spec_helper'
3
+ require 'git_cloner_core'
4
4
 
5
5
  describe GitCloner::Core do
6
6
  context :init do
@@ -47,7 +47,7 @@ describe GitCloner::Core do
47
47
 
48
48
  context :execute do
49
49
  OUTPUT_GIT_CLONER_TMP_DIR = 'tmp_git_cloner'
50
- GIT_CLONER_CASE1 =<<-EOF
50
+ GIT_CLONER_CASE1 = <<-EOF
51
51
  # encoding: utf-8
52
52
  default_output "./"
53
53
  repos [
@@ -61,7 +61,7 @@ repos [
61
61
  ]
62
62
  EOF
63
63
 
64
- RESULT_CASE1 =<<-EOF
64
+ RESULT_CASE1 = <<-EOF
65
65
  # encoding: utf-8
66
66
  require 'templatable'
67
67
 
@@ -82,19 +82,19 @@ line2:<%=placeholders[:param2]%>
82
82
  end
83
83
  EOF
84
84
 
85
- GIT_CLONER_CASE2 =<<-EOF
85
+ GIT_CLONER_CASE2 = <<-EOF
86
86
  # encoding: utf-8
87
87
  default_output "./"
88
88
  repos "invalid"
89
89
  EOF
90
90
 
91
- GIT_CLONER_CASE3 =<<-EOF
91
+ GIT_CLONER_CASE3 = <<-EOF
92
92
  # encoding: utf-8
93
93
  default_output "./"
94
94
  repos ["invalid"]
95
95
  EOF
96
96
 
97
- GIT_CLONER_CASE4 =<<-EOF
97
+ GIT_CLONER_CASE4 = <<-EOF
98
98
  # encoding: utf-8
99
99
  default_output "./"
100
100
  repos [
@@ -104,31 +104,55 @@ repos [
104
104
  ]
105
105
  EOF
106
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
+
107
125
  cases = [
108
126
  {
109
127
  case_no: 1,
110
- case_title: "valid case",
128
+ case_title: 'valid case',
111
129
  input: GIT_CLONER_CASE1,
112
130
  expecteds: ['./tmp/rspec_piccolo', './tbpgr_utils'],
113
131
  },
114
132
  {
115
133
  case_no: 2,
116
- case_title: "invalid repos case(String)",
134
+ case_title: 'invalid repos case(String)',
117
135
  input: GIT_CLONER_CASE2,
118
136
  has_error: true,
119
137
  },
120
138
  {
121
139
  case_no: 3,
122
- case_title: "invalid repos case(Array[Not Hash])",
140
+ case_title: 'invalid repos case(Array[Not Hash])',
123
141
  input: GIT_CLONER_CASE3,
124
142
  has_error: true,
125
143
  },
126
144
  {
127
145
  case_no: 4,
128
- case_title: "invalid repos case(Array[Hash] but invalid hash key)",
146
+ case_title: 'invalid repos case(Array[Hash] but invalid hash key)',
129
147
  input: GIT_CLONER_CASE4,
130
148
  has_error: true,
131
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
+ },
132
156
  ]
133
157
 
134
158
  cases.each do |c|
@@ -141,7 +165,7 @@ repos [
141
165
 
142
166
  # -- when --
143
167
  if c[:has_error]
144
- lambda {git_cloner_core.execute}.should raise_error(StandardError)
168
+ lambda { git_cloner_core.execute }.should raise_error(StandardError)
145
169
  next
146
170
  end
147
171
  git_cloner_core.execute
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require "simplecov"
2
+ require 'simplecov'
3
3
  SimpleCov.start
4
4
  RSpec.configure do |config|
5
5
  config.treat_symbols_as_metadata_keys_with_true_values = true
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.1
4
+ version: 0.0.2
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-10 00:00:00.000000000 Z
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &30810744 !ruby/object:Gem::Requirement
16
+ requirement: &22962024 !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: *30810744
24
+ version_requirements: *22962024
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &30810444 !ruby/object:Gem::Requirement
27
+ requirement: &22961664 !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: *30810444
35
+ version_requirements: *22961664
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &30810168 !ruby/object:Gem::Requirement
38
+ requirement: &22961160 !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: *30810168
46
+ version_requirements: *22961160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &30809892 !ruby/object:Gem::Requirement
49
+ requirement: &22960500 !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: *30809892
57
+ version_requirements: *22960500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &30809664 !ruby/object:Gem::Requirement
60
+ requirement: &22959912 !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: *30809664
68
+ version_requirements: *22959912
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &30809340 !ruby/object:Gem::Requirement
71
+ requirement: &22959396 !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: *30809340
79
+ version_requirements: *22959396
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &30809040 !ruby/object:Gem::Requirement
82
+ requirement: &22975512 !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: *30809040
90
+ version_requirements: *22975512
91
91
  description: GitCloner clone git repositoris from Gitclonerfile settings
92
92
  email:
93
93
  - tbpgr@tbpgr.jp