gem_git 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/gem_git.rb +0 -0
- data/lib/gem_git/helper.rb +46 -0
- data/lib/rubygems/commands/clone_command.rb +21 -0
- data/lib/rubygems/commands/fork_command.rb +55 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/test/helper.rb +17 -0
- data/test/test_gem_git.rb +7 -0
- metadata +137 -0
data/.document
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jeremy McAnally
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= gem_git
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to gem_git
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Jeremy McAnally. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gem_git"
|
18
|
+
gem.homepage = "http://github.com/jm/gem_git"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Tools for hacking on gems}
|
21
|
+
gem.description = %Q{Tools for hacking and patching gems}
|
22
|
+
gem.email = "jeremy@arcturo.com"
|
23
|
+
gem.authors = ["Jeremy McAnally"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "gem_git #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/gem_git.rb
ADDED
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GemGit
|
2
|
+
module Helper
|
3
|
+
class NotOnGithubError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class NoGithubCredentialsError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
def git(*args)
|
10
|
+
exec("git #{args.join(' ')}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def github_user
|
14
|
+
@github_user ||= `git config --get github.user`.chomp
|
15
|
+
|
16
|
+
raise NoGithubCredentialsError.new if @github_user.empty?
|
17
|
+
@github_user
|
18
|
+
end
|
19
|
+
|
20
|
+
def github_token
|
21
|
+
@github_token ||= `git config --get github.token`.chomp
|
22
|
+
|
23
|
+
raise NoGithubCredentialsError.new if @github_token.empty?
|
24
|
+
@github_token
|
25
|
+
end
|
26
|
+
|
27
|
+
def github_info_for(gem_name)
|
28
|
+
repository_url = repository_url_for(gem_name)
|
29
|
+
parsed_url = URI.parse(repository_url)
|
30
|
+
|
31
|
+
if parsed_url.host == "github.com"
|
32
|
+
parsed_url.path.split("/").slice(1,2) # Stupid splitting
|
33
|
+
else
|
34
|
+
raise NotOnGithubError.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def repository_url_for(gem_name)
|
39
|
+
JSON.parse(Net::HTTP.get('rubygems.org', "/api/v1/gems/#{gem_name}.json"))['source_code_uri']
|
40
|
+
end
|
41
|
+
|
42
|
+
def github_clone_url(user, repos)
|
43
|
+
"git@github.com:#{user}/#{repos}.git"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Gem::Commands::CloneCommand < Gem::Command
|
2
|
+
include GemGit::Helper
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super 'clone', "Clone a gem's source from its repository."
|
6
|
+
end
|
7
|
+
|
8
|
+
def description # :nodoc:
|
9
|
+
"Clone a gem's source from its repository."
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
gem_name = get_one_optional_argument
|
14
|
+
|
15
|
+
url = repository_url_for(gem_name)
|
16
|
+
puts "Cloning #{gem_name} from #{url}..."
|
17
|
+
|
18
|
+
git "clone", url
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Gem::Commands::ForkCommand < Gem::Command
|
2
|
+
include GemGit::Helper
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super 'fork', "Makes it easy to fork a gem's source repository for patching and enhancement."
|
6
|
+
end
|
7
|
+
|
8
|
+
def description # :nodoc:
|
9
|
+
"Makes it easy to fork a gem's source repository for patching and enhancement."
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
gem_name = get_one_optional_argument
|
14
|
+
|
15
|
+
begin
|
16
|
+
username, repository = github_info_for(gem_name)
|
17
|
+
|
18
|
+
puts "Forking #{gem_name} from https://github.com/#{username}/#{repository}..."
|
19
|
+
response = Net::HTTP.post_form(URI("http://github.com/api/v2/json/repos/fork/#{username}/#{repository}"), 'login' => github_user, 'token' => github_token)
|
20
|
+
|
21
|
+
response_code = response.code.to_i
|
22
|
+
if response_code >= 400
|
23
|
+
puts "Oops, seems there was an error (code #{response_code})."
|
24
|
+
|
25
|
+
interpret_error(response_code)
|
26
|
+
else
|
27
|
+
puts "Repository forked, now cloning..."
|
28
|
+
|
29
|
+
git("clone", "git@github.com:#{github_user}/#{repository}.git")
|
30
|
+
end
|
31
|
+
rescue NotOnGithubError
|
32
|
+
puts "Sorry, this gem isn't hosted on Github. You can always use `gem clone` and then push it to Github."
|
33
|
+
rescue NoGithubCredentialsError
|
34
|
+
puts "You don't have your username and token set in the global git config (run `git config --get github.user` to see what I mean)."
|
35
|
+
puts "Please set those configuration values and try again."
|
36
|
+
end
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def interpret_error(code)
|
42
|
+
case code
|
43
|
+
when 400
|
44
|
+
puts "There was something wrong with the request it seems. Please try again or file a bug with me on Github."
|
45
|
+
when 404
|
46
|
+
puts "Looks like the repository doesn't exist or was moved. Check the URL in the RubyGems information."
|
47
|
+
when 401
|
48
|
+
puts "Sorry, looks like you don't have access to that repos or your credentials stored in the global git config are bad."
|
49
|
+
when 500, 503
|
50
|
+
puts "Github must be having some issues; try it again later?"
|
51
|
+
else
|
52
|
+
puts "Well I'm not sure what happened. Give it another shot, and maybe it'll be fixed."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
require 'gem_git'
|
15
|
+
|
16
|
+
class Test::Unit::TestCase
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem_git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy McAnally
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 23
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: jeweler
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 7
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 6
|
62
|
+
- 4
|
63
|
+
version: 1.6.4
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rcov
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
description: Tools for hacking and patching gems
|
81
|
+
email: jeremy@arcturo.com
|
82
|
+
executables: []
|
83
|
+
|
84
|
+
extensions: []
|
85
|
+
|
86
|
+
extra_rdoc_files:
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.rdoc
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- lib/gem_git.rb
|
97
|
+
- lib/rubygems_plugin.rb
|
98
|
+
- lib/gem_git/helper.rb
|
99
|
+
- lib/rubygems/commands/clone_command.rb
|
100
|
+
- lib/rubygems/commands/fork_command.rb
|
101
|
+
- test/helper.rb
|
102
|
+
- test/test_gem_git.rb
|
103
|
+
homepage: http://github.com/jm/gem_git
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
requirements: []
|
130
|
+
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.5
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Tools for hacking on gems
|
136
|
+
test_files: []
|
137
|
+
|