gem-clone 0.4.0 → 0.4.2
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 +4 -4
- data/README.md +185 -55
- data/lib/rubygems/commands/clone_command.rb +30 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f10b5ead51ab522bd8575ce4d75a262dbfc1c92e190207d1101631bb76a24366
|
|
4
|
+
data.tar.gz: db822b7b07fbcb6ec522c667cc90829d70c6fcd93b18bedd8591971d7cadc2b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c897ef52329cfbbaae20e125d630a142d849cade5d2cfcf52c901aa91a118f63bd27fa9661f8fc8a849978281cab629fefdc7a6b436f18500030a93dc8818fe
|
|
7
|
+
data.tar.gz: 864e09fd30b7a65ae23b4162bc226c9806d69e3820562600e900a0f1627be5573a9c7f6c8a1903641941e0b3521b3be97cf55e55cbaff730b5a3d9142ece4a70
|
data/README.md
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# gem-clone
|
|
2
2
|
|
|
3
|
-
A RubyGems plugin that allows you to clone gem repositories using `ghq
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
gem install rubygems-clone
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Or build and install locally:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
gem build rubygems-clone.gemspec
|
|
15
|
-
gem install rubygems-clone-0.1.0.gem
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Prerequisites
|
|
19
|
-
|
|
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
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
# Install ghq (example for macOS)
|
|
26
|
-
brew install ghq
|
|
27
|
-
|
|
28
|
-
# Or install via Go
|
|
29
|
-
go install github.com/x-motemen/ghq@latest
|
|
30
|
-
```
|
|
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.
|
|
3
|
+
A RubyGems plugin that allows you to clone gem repositories by fetching source code URLs from gem metadata and using `git goget`, `ghq`, or `git clone`.
|
|
35
4
|
|
|
36
5
|
## Usage
|
|
37
6
|
|
|
7
|
+
### Basic Usage
|
|
8
|
+
|
|
38
9
|
```bash
|
|
39
10
|
# Clone a gem repository
|
|
40
11
|
gem clone sinatra
|
|
@@ -46,39 +17,28 @@ gem clone rails --verbose
|
|
|
46
17
|
gem clone rails --show-url
|
|
47
18
|
```
|
|
48
19
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
1. Fetch gem metadata from RubyGems.org API
|
|
52
|
-
2. Extract repository URL from:
|
|
53
|
-
- `source_code_uri` metadata
|
|
54
|
-
- `homepage_uri` (if it looks like a repository URL)
|
|
55
|
-
- `project_uri` (if it looks like a repository URL)
|
|
56
|
-
3. Clone the repository using:
|
|
57
|
-
- `ghq get` (preferred method if available)
|
|
58
|
-
- `git clone` (fallback if ghq is not available)
|
|
59
|
-
- Skip cloning if `--show-url` is specified
|
|
60
|
-
|
|
61
|
-
## Options
|
|
20
|
+
### Options
|
|
62
21
|
|
|
63
22
|
- `-v, --verbose`: Show verbose output during execution
|
|
64
23
|
- `-u, --show-url`: Display the repository URL without executing the clone operation
|
|
65
24
|
|
|
66
|
-
|
|
25
|
+
### Examples
|
|
67
26
|
|
|
68
27
|
```bash
|
|
69
|
-
# With
|
|
28
|
+
# With git goget available (preferred)
|
|
70
29
|
$ gem clone sinatra
|
|
71
|
-
Executing:
|
|
30
|
+
Executing: git goget https://github.com/sinatra/sinatra
|
|
72
31
|
Successfully cloned repository: https://github.com/sinatra/sinatra
|
|
73
32
|
|
|
74
|
-
#
|
|
33
|
+
# Fallback to ghq when git goget is not available
|
|
75
34
|
$ gem clone rails --verbose
|
|
76
35
|
Fetching gem metadata for 'rails'...
|
|
77
36
|
Found repository URL: https://github.com/rails/rails
|
|
37
|
+
git goget not found, falling back to ghq
|
|
78
38
|
Executing: ghq get https://github.com/rails/rails
|
|
79
39
|
Successfully cloned repository: https://github.com/rails/rails
|
|
80
40
|
|
|
81
|
-
# Fallback to git clone when ghq is
|
|
41
|
+
# Fallback to git clone when neither git goget nor ghq is available
|
|
82
42
|
$ gem clone rails --verbose
|
|
83
43
|
Fetching gem metadata for 'rails'...
|
|
84
44
|
Found repository URL: https://github.com/rails/rails
|
|
@@ -91,15 +51,185 @@ $ gem clone rails --show-url
|
|
|
91
51
|
https://github.com/rails/rails
|
|
92
52
|
```
|
|
93
53
|
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
### From RubyGems
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
gem install gem-clone
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### From Source
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/hsbt/gem-clone.git
|
|
66
|
+
cd gem-clone
|
|
67
|
+
gem build gem-clone.gemspec
|
|
68
|
+
gem install gem-clone-*.gem
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Prerequisites
|
|
72
|
+
|
|
73
|
+
This plugin works best with `git goget` but will automatically fall back to `ghq` or `git clone` if `git goget` is not available.
|
|
74
|
+
|
|
75
|
+
#### Recommended: Install git goget
|
|
76
|
+
|
|
77
|
+
[git goget](https://github.com/hsbt/git-goget) is a bash script for cloning Git repositories with additional features.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Install git goget from GitHub
|
|
81
|
+
git clone https://github.com/hsbt/git-goget.git
|
|
82
|
+
cd git-goget
|
|
83
|
+
chmod +x git-goget
|
|
84
|
+
# Copy to a directory in your PATH
|
|
85
|
+
cp git-goget /usr/local/bin/
|
|
86
|
+
|
|
87
|
+
# Or download directly
|
|
88
|
+
curl -o git-goget https://raw.githubusercontent.com/hsbt/git-goget/main/git-goget
|
|
89
|
+
chmod +x git-goget
|
|
90
|
+
cp git-goget /usr/local/bin/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Alternative: Install ghq
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Install ghq (example for macOS)
|
|
97
|
+
brew install ghq
|
|
98
|
+
|
|
99
|
+
# Or install via Go
|
|
100
|
+
go install github.com/x-motemen/ghq@latest
|
|
101
|
+
|
|
102
|
+
# Or download binary from GitHub releases
|
|
103
|
+
# https://github.com/x-motemen/ghq/releases
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Fallback: Git only
|
|
107
|
+
|
|
108
|
+
If neither `git goget` nor `ghq` is installed, the plugin will automatically use `git clone` instead. Make sure `git` is available in your PATH.
|
|
109
|
+
|
|
110
|
+
## Technical Details
|
|
111
|
+
|
|
112
|
+
### How it works
|
|
113
|
+
|
|
114
|
+
The plugin performs the following steps:
|
|
115
|
+
|
|
116
|
+
1. **Fetch gem metadata** from RubyGems.org API (`/api/v1/gems/{gem_name}.json`)
|
|
117
|
+
2. **Extract repository URL** from gem metadata in this priority order:
|
|
118
|
+
- `source_code_uri` metadata field
|
|
119
|
+
- `homepage_uri` (if it looks like a repository URL)
|
|
120
|
+
3. **Normalize URL** by removing version-specific paths (e.g., `/tree/v1.0.0`, `/blob/main/README.md`)
|
|
121
|
+
4. **Clone repository** using:
|
|
122
|
+
- `git goget <url>` (preferred method if available)
|
|
123
|
+
- `ghq get <url>` (fallback if git goget is not available)
|
|
124
|
+
- `git clone <url>` (fallback if neither git goget nor ghq is available)
|
|
125
|
+
- Display URL only if `--show-url` option is specified
|
|
126
|
+
|
|
127
|
+
### URL Normalization
|
|
128
|
+
|
|
129
|
+
The plugin automatically normalizes repository URLs by removing common Git hosting service paths:
|
|
130
|
+
|
|
131
|
+
- `/tree/*` → removed (GitHub, GitLab branches/tags)
|
|
132
|
+
- `/blob/*` → removed (GitHub, GitLab file views)
|
|
133
|
+
- `/commits/*` → removed (commit history pages)
|
|
134
|
+
- `/releases/*` → removed (release pages)
|
|
135
|
+
- `/issues/*` → removed (issue pages)
|
|
136
|
+
- `/pull/*` → removed (pull request pages)
|
|
137
|
+
- `/tags/*` → removed (tag pages)
|
|
138
|
+
- `/branches/*` → removed (branch pages)
|
|
139
|
+
|
|
140
|
+
**Example:**
|
|
141
|
+
- `https://github.com/rails/rails/tree/v8.0.2` → `https://github.com/rails/rails`
|
|
142
|
+
|
|
143
|
+
### Cross-platform Support
|
|
144
|
+
|
|
145
|
+
The plugin includes cross-platform command detection:
|
|
146
|
+
|
|
147
|
+
- **Unix/Linux/macOS**: Uses `which` command
|
|
148
|
+
- **Windows**: Uses `where` command
|
|
149
|
+
- **Error handling**: Gracefully handles missing commands
|
|
150
|
+
|
|
151
|
+
### Supported Repository Hosts
|
|
152
|
+
|
|
153
|
+
The plugin recognizes repository URLs from:
|
|
154
|
+
|
|
155
|
+
- GitHub (github.com)
|
|
156
|
+
- GitLab (gitlab.com)
|
|
157
|
+
- Bitbucket (bitbucket.org)
|
|
158
|
+
- Codeberg (codeberg.org)
|
|
159
|
+
- SourceHut (sourcehut.org)
|
|
160
|
+
|
|
161
|
+
### Requirements
|
|
162
|
+
|
|
163
|
+
- Ruby >= 2.7.0
|
|
164
|
+
- RubyGems
|
|
165
|
+
- `git goget` (recommended), `ghq` (alternative), or `git` (fallback)
|
|
166
|
+
|
|
94
167
|
## Development
|
|
95
168
|
|
|
96
|
-
|
|
169
|
+
### Setting up the development environment
|
|
97
170
|
|
|
98
171
|
```bash
|
|
99
|
-
|
|
100
|
-
|
|
172
|
+
# Clone the repository
|
|
173
|
+
git clone https://github.com/hsbt/gem-clone.git
|
|
174
|
+
cd gem-clone
|
|
175
|
+
|
|
176
|
+
# Install dependencies
|
|
177
|
+
bundle install
|
|
178
|
+
|
|
179
|
+
# Run tests
|
|
180
|
+
bundle exec rake test
|
|
181
|
+
|
|
182
|
+
# Build the gem
|
|
183
|
+
gem build gem-clone.gemspec
|
|
101
184
|
```
|
|
102
185
|
|
|
186
|
+
### Running Tests
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Run all tests
|
|
190
|
+
bundle exec rake test
|
|
191
|
+
|
|
192
|
+
# Run specific test file
|
|
193
|
+
ruby -Ilib:test test/clone_command_test.rb
|
|
194
|
+
|
|
195
|
+
# Run with verbose output
|
|
196
|
+
ruby -Ilib:test test/clone_command_test.rb --verbose
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Contributing
|
|
200
|
+
|
|
201
|
+
1. Fork the repository
|
|
202
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
203
|
+
3. Make your changes and add tests
|
|
204
|
+
4. Run the test suite (`bundle exec rake test`)
|
|
205
|
+
5. Commit your changes (`git commit -am 'Add amazing feature'`)
|
|
206
|
+
6. Push to the branch (`git push origin feature/amazing-feature`)
|
|
207
|
+
7. Open a Pull Request
|
|
208
|
+
|
|
103
209
|
## License
|
|
104
210
|
|
|
105
|
-
|
|
211
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
MIT License
|
|
215
|
+
|
|
216
|
+
Copyright (c) 2024 Hiroshi SHIBATA
|
|
217
|
+
|
|
218
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
219
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
220
|
+
in the Software without restriction, including without limitation the rights
|
|
221
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
222
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
223
|
+
furnished to do so, subject to the following conditions:
|
|
224
|
+
|
|
225
|
+
The above copyright notice and this permission notice shall be included in all
|
|
226
|
+
copies or substantial portions of the Software.
|
|
227
|
+
|
|
228
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
229
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
230
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
231
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
232
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
233
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
234
|
+
SOFTWARE.
|
|
235
|
+
```
|
|
@@ -2,10 +2,11 @@ require 'rubygems/command'
|
|
|
2
2
|
require 'json'
|
|
3
3
|
require 'net/http'
|
|
4
4
|
require 'uri'
|
|
5
|
+
require 'open3'
|
|
5
6
|
|
|
6
7
|
class Gem::Commands::CloneCommand < Gem::Command
|
|
7
8
|
def initialize
|
|
8
|
-
super 'clone', 'Clone a gem repository using ghq'
|
|
9
|
+
super 'clone', 'Clone a gem repository using git goget, ghq, or git'
|
|
9
10
|
|
|
10
11
|
add_option('-v', '--verbose', 'Show verbose output') do |value, options|
|
|
11
12
|
options[:verbose] = true
|
|
@@ -23,8 +24,8 @@ class Gem::Commands::CloneCommand < Gem::Command
|
|
|
23
24
|
def description # :nodoc:
|
|
24
25
|
<<-EOF
|
|
25
26
|
The clone command fetches gem metadata from RubyGems.org and clones
|
|
26
|
-
the gem's source repository using
|
|
27
|
-
source_code_uri from the gem's metadata.
|
|
27
|
+
the gem's source repository using git goget (preferred), ghq, or git
|
|
28
|
+
based on the homepage or source_code_uri from the gem's metadata.
|
|
28
29
|
|
|
29
30
|
Examples:
|
|
30
31
|
gem clone sinatra
|
|
@@ -107,12 +108,14 @@ Examples:
|
|
|
107
108
|
end
|
|
108
109
|
|
|
109
110
|
def clone_repository(url)
|
|
110
|
-
if command_available?('
|
|
111
|
+
if command_available?('git-goget')
|
|
112
|
+
clone_with_git_goget(url)
|
|
113
|
+
elsif command_available?('ghq')
|
|
111
114
|
clone_with_ghq(url)
|
|
112
115
|
elsif command_available?('git')
|
|
113
116
|
clone_with_git(url)
|
|
114
117
|
else
|
|
115
|
-
alert_error "
|
|
118
|
+
alert_error "None of 'git goget', 'ghq', or 'git' is available in your PATH. Please install one of them."
|
|
116
119
|
terminate_interaction 1
|
|
117
120
|
end
|
|
118
121
|
end
|
|
@@ -120,11 +123,32 @@ Examples:
|
|
|
120
123
|
private
|
|
121
124
|
|
|
122
125
|
def command_available?(command)
|
|
123
|
-
|
|
126
|
+
begin
|
|
127
|
+
check_command = RUBY_PLATFORM =~ /mswin|mingw|cygwin/ ? 'where' : 'which'
|
|
128
|
+
_, _, status = Open3.capture3("#{check_command} #{command}")
|
|
129
|
+
status.success?
|
|
130
|
+
rescue
|
|
131
|
+
false
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def clone_with_git_goget(url)
|
|
136
|
+
command = "git goget #{url}"
|
|
137
|
+
say "Executing: #{command}" if options[:verbose]
|
|
138
|
+
|
|
139
|
+
system(command)
|
|
140
|
+
|
|
141
|
+
if $?.success?
|
|
142
|
+
say "Successfully cloned repository: #{url}"
|
|
143
|
+
else
|
|
144
|
+
alert_error "Failed to clone repository with git goget."
|
|
145
|
+
terminate_interaction 1
|
|
146
|
+
end
|
|
124
147
|
end
|
|
125
148
|
|
|
126
149
|
def clone_with_ghq(url)
|
|
127
150
|
command = "ghq get #{url}"
|
|
151
|
+
say "git goget not found, falling back to ghq" if options[:verbose]
|
|
128
152
|
say "Executing: #{command}" if options[:verbose]
|
|
129
153
|
|
|
130
154
|
system(command)
|