ghq_transfer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 833475cf0dd3f12fe168484ed356d4ff8589354e
4
+ data.tar.gz: 23fab3334ccd0d8941f74123bb6b0fd29378f85a
5
+ SHA512:
6
+ metadata.gz: b8efd400f07322ab0ba1d858d635cc8416b8049d13d11ef25aa5d3f75f691972600f64ea3d9b2d83fae6629af6f525cd43debda09a4728500a8a9948815a81da
7
+ data.tar.gz: f338cc3ed44dfa6498b1f0b91e86a348020584dc75bbcb596ef70d69643aa8a697c9f153cd6f8a35ebd7f5acbc3fccee01d4026d0fd01a275fad859e03822a26
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 Koichi ITO
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # ghq_transfer
2
+
3
+ Transfer local repositories from flatten directory style to [ghq](https://github.com/motemen/ghq) convention style.
4
+
5
+ ## Usage:
6
+
7
+ ```sh
8
+ % ghq_transfer [--dry-run] [--valth]
9
+ ```
10
+
11
+ Options:
12
+
13
+ * `--dry-run` ... Dry run mode (First of all, You'll run this)
14
+ * `--valth`` ... Apply mode
15
+
16
+ ## 1. Execute dry run mode
17
+
18
+ Example effect:
19
+
20
+ For example, your `ghq root` is `~/.ghq`.
21
+
22
+ Following the __dry run mode__.
23
+
24
+ ```sh
25
+ % ghq_transfer --dry-run
26
+ /Users/account/.ghq/rabbit -> /Users/account/.ghq/github.com/rabbit-shocker/rabbit
27
+ /Users/account/.ghq/racc -> /Users/account/.ghq/github.com/tenderlove/racc
28
+ /Users/account/.ghq/rack -> /Users/account/.ghq/github.com/rack/rack
29
+ /Users/account/.ghq/rack-attack -> /Users/account/.ghq/github.com/kickstarter/rack-attack
30
+ /Users/account/.ghq/rack-cache -> /Users/account/.ghq/github.com/rtomayko/rack-cache
31
+ /Users/account/.ghq/rack-mini-profiler -> /Users/account/.ghq/github.com/MiniProfiler/rack-mini-profiler
32
+ /Users/account/.ghq/rack-pjax -> /Users/account/.ghq/github.com/eval/rack-pjax
33
+ /Users/account/.ghq/rack-protection -> /Users/account/.ghq/github.com/rkh/rack-protection
34
+ /Users/account/.ghq/rack-test -> /Users/account/.ghq/github.com/brynary/rack-test
35
+ /Users/account/.ghq/rails -> /Users/account/.ghq/github.com/rails/rails
36
+ ```
37
+
38
+ These ghq convention layout decisions based on `git config --get remote.origin.url` of each repositories.
39
+
40
+ ## 2. Execute apply mode
41
+
42
+ Apply the ghq convention layout to your `ghq root` repositories.
43
+
44
+ ```sh
45
+ % ghq_transfer --valth
46
+ ```
47
+
48
+ :star2: __Execute apply mode after dry run mode, strongly recommended.__
49
+
50
+ ## Requirements
51
+
52
+ * [ghq](https://github.com/motemen/ghq)
53
+
54
+ ## Install
55
+
56
+ Add these lines to your application's Gemfile:
57
+
58
+ ```sh
59
+ gem 'ghq_transfer'
60
+ ```
61
+
62
+ And then execute:
63
+
64
+ ```sh
65
+ $ bundle
66
+ ```
67
+
68
+ Or install it yourself as:
69
+
70
+ ```sh
71
+ $ gem install ghq_transfer
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create new Pull Request
81
+
82
+ ## License
83
+
84
+ ghq_transfer is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/bin/ghq_transfer ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # USAGE:
4
+ #
5
+ # ghq_transfer [--debug] [--valth]
6
+ #
7
+ lib_path = File.expand_path('../../lib', __FILE__)
8
+ $:.unshift(lib_path)
9
+
10
+ require 'ghq_transfer'
11
+ require 'ghq_transfer/version'
12
+ require 'optparse'
13
+
14
+ Version = GhqTransfer::VERSION
15
+
16
+ options = {}
17
+
18
+ opt = OptionParser.new("usage: ghq_transfer [--debug] [--valth]")
19
+
20
+ opt.on('--debug', 'debug mode') {|v| options[:debug] = true }
21
+ opt.on('--dry-run', 'dry run mode') {|v| options[:dry_run] = true }
22
+ opt.on('--valth', 'apply mode') {|v| options[:valth] = true }
23
+ opt.on('-v', '--version', 'version') {|v| options[:version] = true } # overwrite
24
+
25
+ begin
26
+ opt.permute!(ARGV)
27
+
28
+ raise if options.empty?
29
+
30
+ if options[:version]
31
+ puts "ghq_transfer #{GhqTransfer::VERSION}"
32
+ exit
33
+ end
34
+
35
+ GhqTransfer::Core.new(options).run
36
+ rescue
37
+ puts opt.help
38
+
39
+ exit!
40
+ end
@@ -0,0 +1,74 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'uri'
4
+
5
+ module GhqTransfer
6
+ class Core
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def run
12
+ ghq_root = Pathname(`ghq root`.chomp)
13
+
14
+ Dir.glob(ghq_root.join('*')).each do |src|
15
+ next unless File.ftype(src) == 'directory'
16
+
17
+ puts "[DEBUG] #{src}" if @options[:debug]
18
+
19
+ Dir.chdir(src)
20
+
21
+ origin_url = `git config --get remote.origin.url`
22
+
23
+ next if origin_url.empty?
24
+
25
+ origin_url.chomp!
26
+
27
+ host, user, repo = if /^git@.+/ === origin_url
28
+ extract_paths_from_ssh(origin_url)
29
+ else
30
+ extract_paths_from_https(origin_url)
31
+ end
32
+
33
+ begin
34
+ dest_dir = ghq_root.join(host, user)
35
+ dest_path = dest_dir.join(repo)
36
+
37
+ puts "#{src} -> #{dest_path}"
38
+
39
+ if @options[:valth]
40
+ FileUtils.mkdir_p(dest_dir)
41
+
42
+ FileUtils.mv(src, dest_path)
43
+ end
44
+ rescue
45
+ puts "[SKIP] #{src}"
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def extract_paths_from_ssh(url)
53
+ /git@(.+):(.+)\/(.+)/ === url
54
+
55
+ host = $1
56
+ user = $2
57
+ repo = $3
58
+
59
+ repo.gsub!(/\.git$/, '') if repo
60
+
61
+ [host, user, repo]
62
+ end
63
+
64
+ def extract_paths_from_https(url)
65
+ uri = URI.parse(url)
66
+
67
+ host = uri.host
68
+ _, user, repo = uri.path.split('/')
69
+ repo.gsub!(/\.git$/, '')
70
+
71
+ [host, user, repo]
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module GhqTransfer
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghq_transfer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Koichi ITO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Transfer local repositories from flatten directory style to ghq convention
14
+ style.
15
+ email: koic.ito@gmail.com
16
+ executables:
17
+ - ghq_transfer
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/ghq_transfer
24
+ - lib/ghq_transfer.rb
25
+ - lib/ghq_transfer/version.rb
26
+ homepage: http://github.com/koic/ghq_transfer
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 2.1.0
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.6.7
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Transfer local repositories from flatten directory style to ghq convention
50
+ style.
51
+ test_files: []
52
+ has_rdoc: