gem-clone 0.3.1 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65f01c6935db365ac746c5c4e6a3bc5b927664f221601f003080d26d2a1fa476
4
- data.tar.gz: 67ceb76ea713a3e3adeb1035da5effbe7173c6780dd6fe5d2f3893ed5128fceb
3
+ metadata.gz: 88c04c0a3f92b224d8cf69412f3a93c6daeb829bc89749dd712874e88bd86531
4
+ data.tar.gz: f50157ba3e8559bfe70903f08c5804451eea29b015dc1b9aa9c4e895bc50aef3
5
5
  SHA512:
6
- metadata.gz: 3740f3e3e5756c62307e6b62718f9c55981ecfc65c32e9db1aac5faa563643251ff5d4ab0c3f9ddaa8ba5d3ff603edf6e9c6be3303558583e310bc1d7e5e8f25
7
- data.tar.gz: b57afb1728d4b3d08bfee562d7bea047e5f7055c246c2c3e18c8403d9e9ba84f640d803a3b2d9f172f067e18d8f06234387a4b97448e4fc8ac4c6e181ce5976d
6
+ metadata.gz: c025fe44200548cc80821344aa8e930a71ef8b4bdea7001f2fb1ef7b5833e3694774803524f71b29a13b9c66e0d84f6b1e738463cf05c872d6fb179378e8f404
7
+ data.tar.gz: 513e70c10abe50e0655dbf065672bb36564648567dc1086e6d72abc0203b91d37ee731e0ba896077762366cf137e84ad51123c7e4828da40fb24f9a99a27fc4f
data/README.md CHANGED
@@ -5,19 +5,21 @@ A RubyGems plugin that allows you to clone gem repositories using `ghq` based on
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- gem install rubygems-clone
8
+ gem install gem-clone
9
9
  ```
10
10
 
11
11
  Or build and install locally:
12
12
 
13
13
  ```bash
14
- gem build rubygems-clone.gemspec
15
- gem install rubygems-clone-0.1.0.gem
14
+ gem build gem-clone.gemspec
15
+ gem install gem-clone-0.1.0.gem
16
16
  ```
17
17
 
18
18
  ## Prerequisites
19
19
 
20
- This plugin requires `ghq` to be installed and available in your PATH.
20
+ This plugin works best with `ghq` but will automatically fall back to `git clone` if `ghq` is not available.
21
+
22
+ ### Recommended: Install ghq
21
23
 
22
24
  ```bash
23
25
  # Install ghq (example for macOS)
@@ -27,6 +29,10 @@ brew install ghq
27
29
  go install github.com/x-motemen/ghq@latest
28
30
  ```
29
31
 
32
+ ### Fallback: Git only
33
+
34
+ If `ghq` is not installed, the plugin will automatically use `git clone` instead. Make sure `git` is available in your PATH.
35
+
30
36
  ## Usage
31
37
 
32
38
  ```bash
@@ -46,8 +52,10 @@ The command will:
46
52
  2. Extract repository URL from:
47
53
  - `source_code_uri` metadata
48
54
  - `homepage_uri` (if it looks like a repository URL)
49
- - `project_uri` (if it looks like a repository URL)
50
- 3. Use `ghq get` to clone the repository (unless `--show-url` is specified)
55
+ 3. Clone the repository using:
56
+ - `ghq get` (preferred method if available)
57
+ - `git clone` (fallback if ghq is not available)
58
+ - Skip cloning if `--show-url` is specified
51
59
 
52
60
  ## Options
53
61
 
@@ -57,16 +65,27 @@ The command will:
57
65
  ## Examples
58
66
 
59
67
  ```bash
68
+ # With ghq available
60
69
  $ gem clone sinatra
61
70
  Executing: ghq get https://github.com/sinatra/sinatra
62
71
  Successfully cloned repository: https://github.com/sinatra/sinatra
63
72
 
73
+ # With verbose output
64
74
  $ gem clone rails --verbose
65
75
  Fetching gem metadata for 'rails'...
66
76
  Found repository URL: https://github.com/rails/rails
67
77
  Executing: ghq get https://github.com/rails/rails
68
78
  Successfully cloned repository: https://github.com/rails/rails
69
79
 
80
+ # Fallback to git clone when ghq is not available
81
+ $ gem clone rails --verbose
82
+ Fetching gem metadata for 'rails'...
83
+ Found repository URL: https://github.com/rails/rails
84
+ ghq not found, falling back to git clone
85
+ Executing: git clone https://github.com/rails/rails
86
+ Successfully cloned repository: https://github.com/rails/rails
87
+
88
+ # Show URL only
70
89
  $ gem clone rails --show-url
71
90
  https://github.com/rails/rails
72
91
  ```
@@ -76,8 +95,8 @@ https://github.com/rails/rails
76
95
  After checking out the repo, run tests and build the gem:
77
96
 
78
97
  ```bash
79
- gem build rubygems-clone.gemspec
80
- gem install rubygems-clone-0.1.0.gem
98
+ gem build gem-clone.gemspec
99
+ gem install gem-clone-0.1.0.gem
81
100
  ```
82
101
 
83
102
  ## License
@@ -1,8 +1,8 @@
1
1
  require 'rubygems/command'
2
- require 'rubygems/remote_fetcher'
3
2
  require 'json'
4
3
  require 'net/http'
5
4
  require 'uri'
5
+ require 'open3'
6
6
 
7
7
  class Gem::Commands::CloneCommand < Gem::Command
8
8
  def initialize
@@ -108,6 +108,29 @@ Examples:
108
108
  end
109
109
 
110
110
  def clone_repository(url)
111
+ if command_available?('ghq')
112
+ clone_with_ghq(url)
113
+ elsif command_available?('git')
114
+ clone_with_git(url)
115
+ else
116
+ alert_error "Neither 'ghq' nor 'git' is available in your PATH. Please install one of them."
117
+ terminate_interaction 1
118
+ end
119
+ end
120
+
121
+ private
122
+
123
+ def command_available?(command)
124
+ begin
125
+ check_command = RUBY_PLATFORM =~ /mswin|mingw|cygwin/ ? 'where' : 'which'
126
+ _, _, status = Open3.capture3("#{check_command} #{command}")
127
+ status.success?
128
+ rescue
129
+ false
130
+ end
131
+ end
132
+
133
+ def clone_with_ghq(url)
111
134
  command = "ghq get #{url}"
112
135
  say "Executing: #{command}" if options[:verbose]
113
136
 
@@ -116,7 +139,22 @@ Examples:
116
139
  if $?.success?
117
140
  say "Successfully cloned repository: #{url}"
118
141
  else
119
- alert_error "Failed to clone repository. Make sure 'ghq' is installed and available in your PATH."
142
+ alert_error "Failed to clone repository with ghq."
143
+ terminate_interaction 1
144
+ end
145
+ end
146
+
147
+ def clone_with_git(url)
148
+ command = "git clone #{url}"
149
+ say "ghq not found, falling back to git clone" if options[:verbose]
150
+ say "Executing: #{command}" if options[:verbose]
151
+
152
+ system(command)
153
+
154
+ if $?.success?
155
+ say "Successfully cloned repository: #{url}"
156
+ else
157
+ alert_error "Failed to clone repository with git."
120
158
  terminate_interaction 1
121
159
  end
122
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi SHIBATA