git_cloner 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.coveralls.yml +1 -0
 - data/.gitignore +0 -1
 - data/.rubocop.yml +0 -2
 - data/.travis.yml +8 -0
 - data/Gemfile +3 -1
 - data/README.md +76 -15
 - data/Rakefile +8 -1
 - data/bin/gitcloner +5 -2
 - data/git_cloner.gemspec +29 -29
 - data/lib/copier.rb +41 -0
 - data/lib/git_cloner/version.rb +2 -1
 - data/lib/git_cloner_core.rb +133 -124
 - data/lib/git_cloner_dsl.rb +3 -2
 - data/lib/git_cloner_dsl_model.rb +1 -1
 - data/spec/copier_spec.rb +83 -0
 - data/spec/git_cloner_core_spec.rb +195 -339
 - data/spec/spec_helper.rb +9 -1
 - metadata +55 -33
 - data/rubocop-todo.yml +0 -48
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -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
         
     | 
    
        data/.coveralls.yml
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            service_name: travis-ci
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,7 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # GitCloner
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            [](https://travis-ci.org/tbpgr/git_cloner)
         
     | 
| 
      
 4 
     | 
    
         
            +
            [](https://coveralls.io/r/tbpgr/git_cloner)
         
     | 
| 
      
 5 
     | 
    
         
            +
            [](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 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       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
    
    
    
        data/bin/gitcloner
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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'
         
     | 
    
        data/git_cloner.gemspec
    CHANGED
    
    | 
         @@ -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          =  
     | 
| 
       8 
     | 
    
         
            -
              spec.version       = GitCloner::VERSION
         
     | 
| 
       9 
     | 
    
         
            -
              spec.authors       = [ 
     | 
| 
       10 
     | 
    
         
            -
              spec.email         = [ 
     | 
| 
       11 
     | 
    
         
            -
              spec.description   = %q 
     | 
| 
       12 
     | 
    
         
            -
              spec.summary       = %q 
     | 
| 
       13 
     | 
    
         
            -
              spec.homepage      =  
     | 
| 
       14 
     | 
    
         
            -
              spec.license       =  
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              spec.files         = `git ls-files`.split( 
     | 
| 
       17 
     | 
    
         
            -
              spec.executables   = spec.files.grep( 
     | 
| 
       18 
     | 
    
         
            -
              spec.test_files    = spec.files.grep( 
     | 
| 
       19 
     | 
    
         
            -
              spec.require_paths = [ 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              spec.add_runtime_dependency  
     | 
| 
       22 
     | 
    
         
            -
              spec.add_runtime_dependency  
     | 
| 
       23 
     | 
    
         
            -
              spec.add_runtime_dependency  
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       26 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       27 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       28 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       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
         
     | 
    
        data/lib/copier.rb
    ADDED
    
    | 
         @@ -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
         
     | 
    
        data/lib/git_cloner/version.rb
    CHANGED
    
    
    
        data/lib/git_cloner_core.rb
    CHANGED
    
    | 
         @@ -1,124 +1,133 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # encoding: utf-8
         
     | 
| 
       2 
     | 
    
         
            -
            require 'git_cloner_dsl'
         
     | 
| 
       3 
     | 
    
         
            -
            require  
     | 
| 
       4 
     | 
    
         
            -
            require 'fileutils'
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            # default_output  
     | 
| 
       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 
     | 
    
         
            -
                 
     | 
| 
       38 
     | 
    
         
            -
                def init
         
     | 
| 
       39 
     | 
    
         
            -
                  File.open(GIT_CLONER_FILE,  
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                 
     | 
| 
       43 
     | 
    
         
            -
                def  
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
       45 
     | 
    
         
            -
                   
     | 
| 
       46 
     | 
    
         
            -
                  default_output =  
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
       48 
     | 
    
         
            -
                   
     | 
| 
       49 
     | 
    
         
            -
                end
         
     | 
| 
       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 
     | 
    
         
            -
                 
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                 
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                 
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                 
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                   
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     |