git-init 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/bin/git-init +5 -0
- data/git_init.gemspec +23 -0
- data/lib/git_init.rb +110 -0
- data/lib/git_init/version.rb +3 -0
- data/spec/git_url_spec.rb +87 -0
- data/spec/spec_helper.rb +21 -0
- metadata +115 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
.idea/
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christian Simon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# GitInit
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'git_init'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install git_init
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/git_init/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/git-init
ADDED
data/git_init.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git_init/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git-init"
|
8
|
+
spec.version = GitInit::VERSION
|
9
|
+
spec.authors = ["Christian Simon"]
|
10
|
+
spec.email = ["simon@swine.de"]
|
11
|
+
spec.summary = %q{Initialize git repositories in hierarchical strcuture in home dir.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
data/lib/git_init.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'git_init/version'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
|
5
|
+
module GitInit
|
6
|
+
class GitUrl
|
7
|
+
|
8
|
+
attr_accessor :domain, :path, :user, :type, :basename, :proto
|
9
|
+
|
10
|
+
def initialize(opts={})
|
11
|
+
|
12
|
+
# convert url if needed
|
13
|
+
if opts.is_a?(String)
|
14
|
+
opts = GitUrl.parse_url(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
# set instance vars
|
18
|
+
opts.each do |key, value|
|
19
|
+
self.send("#{key}=".to_sym, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def url
|
24
|
+
if type == :http
|
25
|
+
"#{self.proto}://#{self.domain}/#{File.join(self.path,self.basename)}"
|
26
|
+
elsif type == :ssh
|
27
|
+
if self.user.nil?
|
28
|
+
user = ""
|
29
|
+
else
|
30
|
+
user = "#{self.user}@"
|
31
|
+
end
|
32
|
+
"#{user}#{self.domain}:#{File.join(self.path,self.basename)}"
|
33
|
+
elsif type == :git
|
34
|
+
"git://#{self.domain}/#{File.join(self.path,self.basename)}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def GitUrl.parse_url(url)
|
40
|
+
|
41
|
+
ret_val = {}
|
42
|
+
|
43
|
+
# Detect type
|
44
|
+
ret_val[:type] = detect_type(url)
|
45
|
+
|
46
|
+
# Parse ssh url
|
47
|
+
if ret_val[:type] == :ssh
|
48
|
+
m = /^(([^@]+)@)?([^:]+):(.*\.git$)/.match(url)
|
49
|
+
ret_val[:user] = m[2]
|
50
|
+
ret_val[:domain] = m[3]
|
51
|
+
ret_val[:path] = File.dirname(m[4])
|
52
|
+
ret_val[:basename] = File.basename(m[4])
|
53
|
+
elsif ret_val[:type] == :http
|
54
|
+
m = /^(https?):\/\/([^\/]+)\/(.*\.git$)/.match(url)
|
55
|
+
ret_val[:proto] = m[1]
|
56
|
+
ret_val[:domain] = m[2]
|
57
|
+
ret_val[:path] = File.dirname(m[3])
|
58
|
+
ret_val[:basename] = File.basename(m[3])
|
59
|
+
elsif ret_val[:type] == :git
|
60
|
+
m = /^git:\/\/([^\/]+)\/(.*\.git$)/.match(url)
|
61
|
+
ret_val[:domain] = m[1]
|
62
|
+
ret_val[:path] = File.dirname(m[2])
|
63
|
+
ret_val[:basename] = File.basename(m[2])
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
return ret_val
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def GitUrl.detect_type(url)
|
72
|
+
|
73
|
+
# Simple git url
|
74
|
+
return :git if (/^git:\/\//.match(url))
|
75
|
+
|
76
|
+
# http(s)
|
77
|
+
return :http if (/^https?:\/\//.match(url))
|
78
|
+
|
79
|
+
# ssh
|
80
|
+
return :ssh if (/:/.match(url))
|
81
|
+
|
82
|
+
raise "Unknown type of url #{url}"
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def GitInit.run
|
91
|
+
unless ARGV[0]
|
92
|
+
$stderr.puts "Please give a git url as first parameter"
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
git=GitUrl.new (ARGV[0])
|
96
|
+
dest_path = Pathname.new(ENV['HOME']).join('git', git.domain, git.path, git.basename[0..-5])
|
97
|
+
|
98
|
+
if File.exists? dest_path
|
99
|
+
$stderr.puts "Destination directory already exists: '#{dest_path}'"
|
100
|
+
exit 2
|
101
|
+
end
|
102
|
+
|
103
|
+
FileUtils.mkdir_p dest_path.dirname
|
104
|
+
|
105
|
+
system('git', 'clone', git.url, dest_path.to_s)
|
106
|
+
puts dest_path
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
VALID_URLS = {
|
4
|
+
'https://github.com/gitlabhq/gitlabhq.git' => {
|
5
|
+
:type => :http,
|
6
|
+
:domain => 'github.com',
|
7
|
+
:path => 'gitlabhq',
|
8
|
+
:basename => 'gitlabhq.git',
|
9
|
+
:proto => 'https'
|
10
|
+
},
|
11
|
+
'http://github.com/gitlabhq/gitlabhq.git' => {
|
12
|
+
:type => :http,
|
13
|
+
:domain => 'github.com',
|
14
|
+
:path => 'gitlabhq',
|
15
|
+
:basename => 'gitlabhq.git',
|
16
|
+
:proto => 'http'
|
17
|
+
},
|
18
|
+
'git@github.com:gitlabhq/gitlabhq.git' => {
|
19
|
+
:type => :ssh,
|
20
|
+
:user => 'git',
|
21
|
+
:domain => 'github.com',
|
22
|
+
:path => 'gitlabhq',
|
23
|
+
:basename => 'gitlabhq.git',
|
24
|
+
},
|
25
|
+
'github.com:gitlabhq/gitlabhq.git' => {
|
26
|
+
:type => :ssh,
|
27
|
+
:user => nil,
|
28
|
+
:domain => 'github.com',
|
29
|
+
:path => 'gitlabhq',
|
30
|
+
:basename => 'gitlabhq.git',
|
31
|
+
},
|
32
|
+
'git://github.com/gitlabhq/gitlabhq.git' => {
|
33
|
+
:type => :git,
|
34
|
+
:domain => 'github.com',
|
35
|
+
:path => 'gitlabhq',
|
36
|
+
:basename => 'gitlabhq.git',
|
37
|
+
},
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
describe GitInit do
|
43
|
+
|
44
|
+
VALID_URLS.each do |url, values|
|
45
|
+
describe GitInit::GitUrl do
|
46
|
+
|
47
|
+
describe '#new' do
|
48
|
+
subject do
|
49
|
+
GitInit::GitUrl.method(:new)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
it 'creates object from url' do
|
54
|
+
expect{subject.(url)}.not_to raise_error()
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'generates same url as in input' do
|
58
|
+
expect(subject.(url).url).to eq(url)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "URL '#{url}'" do
|
63
|
+
describe '.parse_url' do
|
64
|
+
subject do
|
65
|
+
GitInit::GitUrl.method(:parse_url)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should parse correct urls' do
|
69
|
+
expect(subject.(url)).to eq(values)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '.detect_type' do
|
74
|
+
subject do
|
75
|
+
GitInit::GitUrl.method(:detect_type)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should parse correct urls' do
|
79
|
+
subject.(url)
|
80
|
+
expect(subject.(url)).to eq(values[:type])
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'git_init'
|
9
|
+
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-init
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Simon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- simon@swine.de
|
65
|
+
executables:
|
66
|
+
- git-init
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bin/git-init
|
77
|
+
- git_init.gemspec
|
78
|
+
- lib/git_init.rb
|
79
|
+
- lib/git_init/version.rb
|
80
|
+
- spec/git_url_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 4394827408792635842
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 4394827408792635842
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.23
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Initialize git repositories in hierarchical strcuture in home dir.
|
113
|
+
test_files:
|
114
|
+
- spec/git_url_spec.rb
|
115
|
+
- spec/spec_helper.rb
|