git_cloner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60d71c9a9712cf1a9c2138219fa6980bdf9b986b
4
+ data.tar.gz: bc70e7ec2625f927b3ca2bbc907d14181276ca7c
5
+ SHA512:
6
+ metadata.gz: e923a21ab30f06606788f93dd177538901d4b63c0f6abf4b5da9bfa8085c71c7d59598e4f3f6cd444cfadf4cc1e59e02c9c654d97c87ee885291d99c1c2355bf
7
+ data.tar.gz: b6271e55decb35a1f97d2db5eefbe7643ee296eedd108681315eba8f95dcc6f68143b07e160ba9abe9064885e8490fd3ef86cede117c7c85a9f900c753dfa6de
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -15,4 +15,3 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- tudu/
@@ -1,4 +1,2 @@
1
- inherit_from: rubocop-todo.yml
2
-
3
1
  LineLength:
4
2
  Enabled: false
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1
data/Gemfile CHANGED
@@ -6,4 +6,6 @@ gem "thor", "~> 0.18.1"
6
6
  gem "simplecov", "~> 0.8.2"
7
7
  gem "activesupport", "~> 4.0.1"
8
8
  gem "activemodel", "~> 4.0.2"
9
- gem "tudu", "~> 0.0.4"
9
+ group :test do
10
+ gem 'coveralls', require: false
11
+ end
data/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # GitCloner
2
2
 
3
+ [![Build Status](https://travis-ci.org/tbpgr/git_cloner.png?branch=master)](https://travis-ci.org/tbpgr/git_cloner)
4
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/git_cloner/badge.png)](https://coveralls.io/r/tbpgr/git_cloner)
5
+ [![Code Climate](https://codeclimate.com/github/tbpgr/git_cloner.png)](https://codeclimate.com/github/tbpgr/git_cloner)
6
+
3
7
  GitCloner clone git repositoris from Gitclonerfile settings.
4
8
 
9
+ ## Dependency
10
+ GitCloner depends on git. GitCloner use 'git clone' command.
11
+
5
12
  ## Installation
6
13
 
7
14
  Add this line to your application's Gemfile:
@@ -16,7 +23,13 @@ Or install it yourself as:
16
23
 
17
24
  $ gem install git_cloner
18
25
 
19
- ## CLI-Usage
26
+ ## CLI Usage
27
+
28
+ ### show help
29
+
30
+ ~~~bash
31
+ gitcloner h
32
+ ~~~
20
33
 
21
34
  ### generate Gitclonerfile
22
35
 
@@ -24,11 +37,18 @@ Or install it yourself as:
24
37
  gitcloner init
25
38
  ~~~
26
39
 
40
+ or
41
+
42
+ ~~~bash
43
+ gitcloner i
44
+ ~~~
45
+
46
+ Gitclonerfile contents is...
47
+
27
48
  ~~~ruby
28
49
  # encoding: utf-8
29
50
 
30
51
  # default_output place
31
- # default_output is required
32
52
  # default_output allow only String
33
53
  # default_output's default value => "./"
34
54
  default_output "./"
@@ -72,31 +92,36 @@ repos [
72
92
  ]
73
93
  ~~~
74
94
 
75
- ### execute clone
95
+ ### execute clone repositories
76
96
 
77
97
  ~~~bash
78
98
  gitcloner clone
79
99
  ~~~
80
100
 
101
+ or
102
+
103
+ ~~~bash
104
+ gitcloner c
105
+ ~~~
106
+
81
107
  ### confirm clone result
82
108
 
83
109
  ~~~bash
84
110
  $ tree
85
- ├─helper
86
- spec_helper.rb
87
- ├─rspec_piccolo
88
- many files...
89
- ├─sample
90
- rspec_piccolo_spec.rb
91
- spec_helper.rb
92
- ├─tmp
93
- rspec_piccolo
94
- └─tbpgr_utils
95
- └many files...
111
+ helper
112
+ spec_helper.rb
113
+ rspec_piccolo
114
+ many files...
115
+ sample
116
+ rspec_piccolo_spec.rb
117
+ spec_helper.rb
118
+ tmp
119
+ rspec_piccolo
120
+ tbpgr_utils
96
121
  ~~~
97
122
 
98
123
  ## Direct Usage
99
- if you want to use GitCloner directry, you can use like this sample.
124
+ if you want to use GitCloner directry in your ruby logic, you can use like this sample.
100
125
 
101
126
  ~~~ruby
102
127
  require 'git_cloner_core'
@@ -120,7 +145,43 @@ repos = [
120
145
  GitCloner::Core.new.clone default_output, repos
121
146
  ~~~
122
147
 
148
+ ## Sample Usage
149
+ You want to copy chef cookbooks(cookbook1, cookbook2) to cookbooks directory.
150
+
151
+ generate Gitclonerfile
152
+
153
+ ~~~
154
+ gitcloner i
155
+ ~~~
156
+
157
+ edit Gitclonerfile
158
+
159
+ ~~~ruby
160
+ # encoding: utf-8
161
+ default_output "./cookbooks"
162
+ repos [
163
+ {place: "https://github.com/some_account/cookbook1.git"},
164
+ {place: "https://github.com/some_account/cookbook2.git"},
165
+ ]
166
+ ~~~
167
+
168
+ execute clone repositories
169
+
170
+ ~~~bash
171
+ gitcloner c
172
+ ~~~
173
+
174
+ confirm results
175
+
176
+ ~~~
177
+ $ tree
178
+ ┗cookbooks
179
+ ┠cookbook1
180
+ ┗cookbook2
181
+ ~~~
182
+
123
183
  ## History
184
+ * version 0.0.4 : fix exit status.
124
185
  * version 0.0.3 : enable direct call clone.
125
186
  * version 0.0.2 : add files,directories copy.
126
187
  * version 0.0.1 : first release.
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
@@ -11,9 +11,12 @@ module GitCloner
11
11
  class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
12
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 settings'
15
15
  def clone
16
- GitCloner::Core.new.execute
16
+ GitCloner::Core.new.clone
17
+ rescue => e
18
+ warn(e.message)
19
+ exit(false)
17
20
  end
18
21
 
19
22
  desc 'init', 'generate Gitclonerfile'
@@ -1,29 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'git_cloner/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "git_cloner"
8
- spec.version = GitCloner::VERSION
9
- spec.authors = ["tbpgr"]
10
- spec.email = ["tbpgr@tbpgr.jp"]
11
- spec.description = %q{GitCloner clone git repositoris from Gitclonerfile settings}
12
- spec.summary = %q{GitCloner clone git repositoris from Gitclonerfile settings}
13
- spec.homepage = "https://github.com/tbpgr/git_cloner"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_runtime_dependency "activesupport", "~> 4.0.1"
22
- spec.add_runtime_dependency "activemodel", "~> 4.0.2"
23
- spec.add_runtime_dependency "thor", "~> 0.18.1"
24
-
25
- spec.add_development_dependency "bundler", "~> 1.3"
26
- spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec", "~> 2.14.1"
28
- spec.add_development_dependency "simplecov", "~> 0.8.2"
29
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_cloner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'git_cloner'
8
+ spec.version = GitCloner::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.description = %q(GitCloner clone git repositoris from Gitclonerfile settings)
12
+ spec.summary = %q(GitCloner clone git repositoris from Gitclonerfile settings)
13
+ spec.homepage = 'https://github.com/tbpgr/git_cloner'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '~> 4.0.1'
22
+ spec.add_runtime_dependency 'activemodel', '~> 4.0.2'
23
+ spec.add_runtime_dependency 'thor', '~> 0.18.1'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
28
+ spec.add_development_dependency 'simplecov', '~> 0.8.2'
29
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ module GitCloner
4
+ # Copier
5
+ class Copier
6
+ class << self
7
+ def copy(copies)
8
+ return if copies.nil?
9
+ copies.each { |copy_dir|copy_target(copy_dir) }
10
+ end
11
+
12
+ private
13
+
14
+ def copy_target(copy_dir)
15
+ check_copy_dir_from(copy_dir[:from])
16
+ check_copy_dir_to(copy_dir[:to])
17
+ make_copy_dir_if_not_exists(copy_dir[:to])
18
+ copy_target_files(copy_dir[:from], copy_dir[:to])
19
+ end
20
+
21
+ def check_copy_dir_from(from)
22
+ return if from
23
+ fail ArgumentError, 'invalid repos. copies must have from'
24
+ end
25
+
26
+ def check_copy_dir_to(to)
27
+ return if to
28
+ fail ArgumentError, 'invalid repos. copies must have from'
29
+ end
30
+
31
+ def make_copy_dir_if_not_exists(to)
32
+ return if Dir.exist?(File.dirname(to))
33
+ FileUtils.mkdir_p(to)
34
+ end
35
+
36
+ def copy_target_files(from, to)
37
+ FileUtils.cp_r(from, to)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,4 @@
1
+ # GitCloner
1
2
  module GitCloner
2
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
3
4
  end
@@ -1,124 +1,133 @@
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
1
+ # encoding: utf-8
2
+ require 'git_cloner_dsl'
3
+ require 'uri'
4
+ require 'fileutils'
5
+ require 'copier'
6
+
7
+ module GitCloner
8
+ # GitCloner Core
9
+ class Core
10
+ GIT_CLONER_FILE = 'Gitclonerfile'
11
+ GIT_CLONER_TEMPLATE = <<-EOS
12
+ # encoding: utf-8
13
+
14
+ # default_output place
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 clone
44
+ settings = read_settings
45
+ base_dir = Dir.pwd
46
+ default_output = settings.default_output
47
+ repos = settings.repos
48
+ clone_repositories(default_output, repos, base_dir)
49
+ end
50
+
51
+ private
52
+
53
+ def read_settings
54
+ src = read_dsl
55
+ dsl = GitCloner::Dsl.new
56
+ dsl.instance_eval src
57
+ dsl.git_cloner
58
+ end
59
+
60
+ def read_dsl
61
+ File.open(GIT_CLONER_FILE) { |f|f.read }
62
+ end
63
+
64
+ def clone_repositories(default_output, repos, base_dir)
65
+ check_repos(repos)
66
+ repos.each { |repo|clone_repository(default_output, repo, base_dir) }
67
+ end
68
+
69
+ def check_repos(repos)
70
+ return if repos.is_a? Array
71
+ fail ArgumentError, 'invalid repos. repos must be Array.'
72
+ end
73
+
74
+ def clone_repository(default_output, repo, base_dir)
75
+ check_repos_hash(repo)
76
+ check_repos_hash_key(repo)
77
+ output_dir = get_output_dir(repo[:output], default_output)
78
+ make_output_dir(output_dir)
79
+ move_to_output_dir(output_dir)
80
+ execute_git_clone(repo[:place])
81
+ back_to_base_dir(base_dir)
82
+ Copier.copy(repo[:copies])
83
+ end
84
+
85
+ def check_repos_hash(repo)
86
+ return if repo.is_a?(Hash)
87
+ fail ArgumentError, 'invalid repos. repos-Array must have Hash'
88
+ end
89
+
90
+ def check_repos_hash_key(repo)
91
+ return if repo.key?(:place)
92
+ fail ArgumentError, 'invalid key. Hash must contain :place key'
93
+ end
94
+
95
+ def get_repo_name(place)
96
+ uri = URI(place)
97
+ uri.path.gsub(/.*\//, '').gsub('.git', '')
98
+ end
99
+
100
+ def get_output_dir(output, default_output)
101
+ output.nil? ? default_output : output
102
+ end
103
+
104
+ def make_output_dir(output_dir)
105
+ FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
106
+ end
107
+
108
+ def move_to_output_dir(output_dir)
109
+ Dir.chdir(output_dir)
110
+ end
111
+
112
+ def execute_git_clone(url)
113
+ result = system("git clone #{url} --depth=1")
114
+ repo_name = get_repo_name(url)
115
+ remove_dot_git_directory repo_name
116
+ show_result_message(result, repo_name)
117
+ end
118
+
119
+ def back_to_base_dir(base_dir)
120
+ Dir.chdir(base_dir)
121
+ end
122
+
123
+ def remove_dot_git_directory(repo_name)
124
+ Dir.chdir("./#{repo_name}")
125
+ FileUtils.rm_rf('.git') if Dir.exist?('.git')
126
+ end
127
+
128
+ def show_result_message(result, repo_name)
129
+ result_msg = result ? 'complete' : 'fail'
130
+ puts("clone #{Dir.pwd}/#{repo_name} #{result_msg}")
131
+ end
132
+ end
133
+ end