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 +4 -4
- data/README.md +27 -8
- data/lib/rubygems/commands/clone_command.rb +40 -2
- 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: 88c04c0a3f92b224d8cf69412f3a93c6daeb829bc89749dd712874e88bd86531
|
4
|
+
data.tar.gz: f50157ba3e8559bfe70903f08c5804451eea29b015dc1b9aa9c4e895bc50aef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
8
|
+
gem install gem-clone
|
9
9
|
```
|
10
10
|
|
11
11
|
Or build and install locally:
|
12
12
|
|
13
13
|
```bash
|
14
|
-
gem build
|
15
|
-
gem install
|
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
|
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
|
-
|
50
|
-
|
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
|
80
|
-
gem install
|
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
|
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
|