git-hub 1.1.0 → 1.3.0
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.
- data/README.md +60 -12
- data/Rakefile +72 -79
- data/lib/hub/commands.rb +134 -73
- data/lib/hub/context.rb +112 -0
- data/lib/hub/version.rb +1 -1
- data/lib/hub.rb +1 -0
- data/man/hub.1 +99 -92
- data/man/hub.1.html +68 -67
- data/man/{hub.1.ron → hub.1.ronn} +52 -25
- data/test/fakebin/git +7 -0
- data/test/fakebin/open +3 -0
- data/test/helper.rb +4 -0
- data/test/hub_test.rb +237 -37
- metadata +27 -25
- data/.gitignore +0 -2
- data/.kick +0 -26
- data/CONTRIBUTORS +0 -11
- data/HISTORY.md +0 -75
data/README.md
CHANGED
@@ -36,12 +36,16 @@ Install
|
|
36
36
|
Assuming `~/bin/` is in your `$PATH`, you're ready to roll:
|
37
37
|
|
38
38
|
$ hub version
|
39
|
-
git version 1.
|
40
|
-
hub version
|
39
|
+
git version 1.7.0.4
|
40
|
+
hub version 1.1.0
|
41
41
|
|
42
42
|
### Homebrew
|
43
43
|
|
44
|
-
brew install hub
|
44
|
+
$ brew install hub
|
45
|
+
$ which hub
|
46
|
+
/usr/local/bin/hub
|
47
|
+
$ hub version
|
48
|
+
...
|
45
49
|
|
46
50
|
### RubyGems
|
47
51
|
|
@@ -49,18 +53,20 @@ Though not recommended, `hub` can also be installed as a RubyGem:
|
|
49
53
|
|
50
54
|
$ gem install git-hub
|
51
55
|
|
52
|
-
|
56
|
+
Yes, the gem name is "git-hub".
|
53
57
|
|
54
|
-
(It's not recommended because of the RubyGems startup
|
55
|
-
gist][speed] for information.)
|
58
|
+
(It's not recommended for casual use because of the RubyGems startup
|
59
|
+
time. See [this gist][speed] for information.)
|
56
60
|
|
57
61
|
### Standalone via RubyGems
|
58
62
|
|
59
|
-
Yes, the gem name is still
|
63
|
+
Yes, the gem name is still "git-hub":
|
60
64
|
|
61
65
|
$ gem install git-hub
|
62
66
|
$ hub hub standalone > ~/bin/hub && chmod 755 ~/bin/hub
|
63
|
-
|
67
|
+
|
68
|
+
This installs a standalone version which doesn't require RubyGems to
|
69
|
+
run.
|
64
70
|
|
65
71
|
### Source
|
66
72
|
|
@@ -74,7 +80,7 @@ You can also install from source:
|
|
74
80
|
Aliasing
|
75
81
|
--------
|
76
82
|
|
77
|
-
hub works best when it wraps `git`. This is not dangerous - your
|
83
|
+
`hub` works best when it wraps `git`. This is not dangerous - your
|
78
84
|
normal git commands should all work. hub merely adds some sugar.
|
79
85
|
|
80
86
|
Typing `hub alias <shell>` will display alias instructions for
|
@@ -153,18 +159,50 @@ login" below for details.
|
|
153
159
|
$ git browse
|
154
160
|
> open http://github.com/CURRENT_REPO
|
155
161
|
|
162
|
+
$ git browse -- issues
|
163
|
+
> open http://github.com/CURRENT_REPO/issues
|
164
|
+
|
156
165
|
$ git browse schacon/ticgit
|
157
166
|
> open http://github.com/schacon/ticgit
|
158
167
|
|
159
168
|
$ git browse -p schacon/ticgit
|
160
|
-
> open
|
169
|
+
> open https://github.com/schacon/ticgit
|
161
170
|
|
162
171
|
$ git browse resque
|
163
172
|
> open http://github.com/YOUR_USER/resque
|
164
173
|
|
174
|
+
$ git browse resque network
|
175
|
+
> open http://github.com/YOUR_USER/resque/network
|
176
|
+
|
165
177
|
$ git browse -p resque
|
166
178
|
> open https://github.com:YOUR_USER/resque
|
167
179
|
|
180
|
+
### git compare
|
181
|
+
|
182
|
+
$ git compare refactor
|
183
|
+
> open http://github.com/CURRENT_REPO/compare/refactor
|
184
|
+
|
185
|
+
$ git compare 1.0...1.1
|
186
|
+
> open http://github.com/CURRENT_REPO/compare/1.0...1.1
|
187
|
+
|
188
|
+
$ git compare -u fix
|
189
|
+
> (http://github.com/CURRENT_REPO/compare/fix)
|
190
|
+
|
191
|
+
$ git compare other-user patch
|
192
|
+
> open http://github.com/other-user/REPO/compare/patch
|
193
|
+
|
194
|
+
### git submodule
|
195
|
+
|
196
|
+
$ hub submodule add wycats/bundler vendor/bundler
|
197
|
+
> git submodule add git://github.com/wycats/bundler.git vendor/bundler
|
198
|
+
|
199
|
+
$ hub submodule add -p wycats/bundler vendor/bundler
|
200
|
+
> git submodule add git@github.com:wycats/bundler.git vendor/bundler
|
201
|
+
|
202
|
+
$ hub submodule add -b ryppl ryppl/pip vendor/pip
|
203
|
+
> git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip
|
204
|
+
|
205
|
+
|
168
206
|
### git help
|
169
207
|
|
170
208
|
$ git help
|
@@ -195,13 +233,13 @@ Configuration
|
|
195
233
|
-------------
|
196
234
|
|
197
235
|
If you prefer `http://` clones to `git://` clones, you can set the
|
198
|
-
`hub.http-clone` option using `git-config`.
|
236
|
+
`hub.http-clone` option to true using `git-config`.
|
199
237
|
|
200
238
|
For example:
|
201
239
|
|
202
240
|
$ git clone defunkt/repl
|
203
241
|
< git clone >
|
204
|
-
$ git config --global --
|
242
|
+
$ git config --global --bool hub.http-clone true
|
205
243
|
$ git clone defunkt/repl
|
206
244
|
< http clone >
|
207
245
|
|
@@ -234,6 +272,16 @@ Once you've made your great commits:
|
|
234
272
|
4. Create an [Issue][1] with a link to your branch
|
235
273
|
5. That's it!
|
236
274
|
|
275
|
+
### Development Gems
|
276
|
+
You will need the following gems (and their dependencies) to
|
277
|
+
contribute to `hub`:
|
278
|
+
|
279
|
+
* `rake` (`gem install rake`)
|
280
|
+
* `kicker` (`gem install kicker`)
|
281
|
+
* `turn` (`gem install turn`)
|
282
|
+
* `mg` (`gem install mg`)
|
283
|
+
* `ronn` (`gem install ronn`)
|
284
|
+
* `webhelper` (`gem install webhelper`)
|
237
285
|
|
238
286
|
Meta
|
239
287
|
----
|
data/Rakefile
CHANGED
@@ -1,37 +1,12 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
t.libs << 'lib'
|
7
|
-
t.ruby_opts << '-rubygems'
|
8
|
-
t.pattern = 'test/**/*_test.rb'
|
9
|
-
t.verbose = false
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Launch Kicker (like autotest)"
|
13
|
-
task :kicker do
|
14
|
-
puts "Kicking... (ctrl+c to cancel)"
|
15
|
-
exec "kicker -e rake test lib"
|
16
|
-
end
|
17
|
-
|
18
|
-
desc "Build a gem"
|
19
|
-
task :gem => [ :gemspec, :build ]
|
20
|
-
|
21
|
-
desc "Build standalone script"
|
22
|
-
task :standalone => :load_hub do
|
23
|
-
require 'hub/standalone'
|
24
|
-
Hub::Standalone.save('hub')
|
25
|
-
end
|
3
|
+
#
|
4
|
+
# Helpers
|
5
|
+
#
|
26
6
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Show hub manual"
|
33
|
-
task :man => "man:build" do
|
34
|
-
exec "man man/hub.1"
|
7
|
+
def command?(command)
|
8
|
+
`type -t #{command}`
|
9
|
+
$?.success?
|
35
10
|
end
|
36
11
|
|
37
12
|
task :load_hub do
|
@@ -39,54 +14,77 @@ task :load_hub do
|
|
39
14
|
require 'hub'
|
40
15
|
end
|
41
16
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
gemspec.name = "git-hub"
|
48
|
-
gemspec.summary = gemspec.description = "hub introduces git to GitHub"
|
49
|
-
gemspec.homepage = "http://github.com/defunkt/hub"
|
50
|
-
gemspec.version = Hub::Version
|
51
|
-
gemspec.authors = ["Chris Wanstrath"]
|
52
|
-
gemspec.email = "chris@ozmm.org"
|
53
|
-
gemspec.executables = ["hub"]
|
54
|
-
gemspec.post_install_message = <<-message
|
17
|
+
task :check_dirty do
|
18
|
+
if !`git status`.include?('nothing to commit')
|
19
|
+
abort "dirty index - not publishing!"
|
20
|
+
end
|
21
|
+
end
|
55
22
|
|
56
|
-
------------------------------------------------------------
|
57
23
|
|
58
|
-
|
59
|
-
|
24
|
+
#
|
25
|
+
# Tests
|
26
|
+
#
|
60
27
|
|
61
|
-
|
62
|
-
line you may want to install `hub` the old
|
63
|
-
fashioned way. Faster startup time, you see.
|
28
|
+
task :default => :test
|
64
29
|
|
65
|
-
|
66
|
-
|
67
|
-
|
30
|
+
if command? :turn
|
31
|
+
desc "Run tests"
|
32
|
+
task :test do
|
33
|
+
suffix = "-n #{ENV['TEST']}" if ENV['TEST']
|
34
|
+
sh "turn test/*.rb #{suffix}"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
Rake::TestTask.new do |t|
|
38
|
+
t.libs << 'lib'
|
39
|
+
t.ruby_opts << '-rubygems'
|
40
|
+
t.pattern = 'test/**/*_test.rb'
|
41
|
+
t.verbose = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if command? :kicker
|
46
|
+
desc "Launch Kicker (like autotest)"
|
47
|
+
task :kicker do
|
48
|
+
puts "Kicking... (ctrl+c to cancel)"
|
49
|
+
exec "kicker -e rake test lib"
|
50
|
+
end
|
51
|
+
end
|
68
52
|
|
69
|
-
Cheers,
|
70
|
-
defunkt
|
71
53
|
|
72
|
-
|
54
|
+
#
|
55
|
+
# Ron
|
56
|
+
#
|
73
57
|
|
74
|
-
|
58
|
+
if command? :ronn
|
59
|
+
desc "Show the manual"
|
60
|
+
task :man => "man:build" do
|
61
|
+
exec "man man/hub.1"
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Build the manual"
|
65
|
+
task "man:build" do
|
66
|
+
sh "ronn -br5 --organization=DEFUNKT --manual='Git Manual' man/*.ronn"
|
75
67
|
end
|
76
|
-
rescue LoadError
|
77
|
-
puts "Jeweler not available."
|
78
|
-
puts "Install it with: gem install jeweler"
|
79
68
|
end
|
80
69
|
|
81
70
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
71
|
+
#
|
72
|
+
# Gems
|
73
|
+
#
|
74
|
+
|
75
|
+
desc "Build standalone script"
|
76
|
+
task :standalone => :load_hub do
|
77
|
+
require 'hub/standalone'
|
78
|
+
Hub::Standalone.save('hub')
|
86
79
|
end
|
87
80
|
|
88
|
-
|
89
|
-
|
81
|
+
begin
|
82
|
+
require 'mg'
|
83
|
+
MG.new('git-hub.gemspec')
|
84
|
+
rescue LoadError
|
85
|
+
warn "mg not available."
|
86
|
+
warn "Install it with: gem install mg"
|
87
|
+
end
|
90
88
|
|
91
89
|
desc "Install standalone script and man pages"
|
92
90
|
task :install => :standalone do
|
@@ -99,13 +97,14 @@ task :install => :standalone do
|
|
99
97
|
FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1"
|
100
98
|
end
|
101
99
|
|
102
|
-
desc "Push a new version
|
103
|
-
task :publish =>
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
100
|
+
desc "Push a new version."
|
101
|
+
task :publish => "gem:publish" do
|
102
|
+
require 'hub/version'
|
103
|
+
sh "git tag v#{Hub::Version}"
|
104
|
+
sh "git push origin v#{Hub::Version}"
|
105
|
+
sh "git push origin master"
|
106
|
+
sh "gem push pkg/git-hub-#{Hub::Version}.gem"
|
107
|
+
sh "git clean -fd"
|
109
108
|
exec "rake pages"
|
110
109
|
end
|
111
110
|
|
@@ -122,9 +121,3 @@ task :pages => [ "man:build", :check_dirty, :standalone ] do
|
|
122
121
|
sh "git checkout master"
|
123
122
|
puts :done
|
124
123
|
end
|
125
|
-
|
126
|
-
task :check_dirty do
|
127
|
-
if !`git status`.include?('nothing to commit')
|
128
|
-
abort "dirty index - not publishing!"
|
129
|
-
end
|
130
|
-
end
|
data/lib/hub/commands.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
module Hub
|
2
|
+
# See context.rb
|
3
|
+
module Context; end
|
4
|
+
|
2
5
|
# The Commands module houses the git commands that hub
|
3
6
|
# lovingly wraps. If a method exists here, it is expected to have a
|
4
7
|
# corresponding git command which either gets run before or after
|
@@ -31,25 +34,11 @@ module Hub
|
|
31
34
|
instance_methods.each { |m| undef_method(m) unless m =~ /(^__|send|to\?$)/ }
|
32
35
|
extend self
|
33
36
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
PUBLIC = (HTTP_CLONE ? 'http' : 'git') + '://github.com/%s/%s.git'
|
40
|
-
PRIVATE = 'git@github.com:%s/%s.git'
|
41
|
-
LGHCONF = "http://github.com/guides/local-github-config"
|
42
|
-
API_REPO = 'http://github.com/api/v2/yaml/repos/show/%s/%s'
|
43
|
-
API_FORK = 'http://github.com/api/v2/yaml/repos/fork/%s/%s'
|
44
|
-
|
45
|
-
# Set the repo name based on the current origin or, as a fallback,
|
46
|
-
# the cwd.
|
47
|
-
if ORIGIN =~ %r{\bgithub\.com[:/](.+)/(.+).git$}
|
48
|
-
OWNER, REPO = $1, $2
|
49
|
-
else
|
50
|
-
REPO = File.basename(Dir.pwd)
|
51
|
-
OWNER = ''
|
52
|
-
end
|
37
|
+
# Provides `github_url` and various inspection methods
|
38
|
+
extend Context
|
39
|
+
|
40
|
+
API_REPO = 'http://github.com/api/v2/yaml/repos/show/%s/%s'
|
41
|
+
API_FORK = 'http://github.com/api/v2/yaml/repos/fork/%s/%s'
|
53
42
|
|
54
43
|
# $ hub clone rtomayko/tilt
|
55
44
|
# > git clone git://github.com/rtomayko/tilt.
|
@@ -76,15 +65,10 @@ module Hub
|
|
76
65
|
if arg =~ %r{.+?://|.+?@} || File.directory?(arg)
|
77
66
|
# Bail out early for URLs and local paths.
|
78
67
|
break
|
79
|
-
elsif arg.scan('/').size
|
68
|
+
elsif arg.scan('/').size <= 1 && !arg.include?(':')
|
80
69
|
# $ hub clone rtomayko/tilt
|
81
|
-
url = ssh ? PRIVATE : PUBLIC
|
82
|
-
args[args.index(arg)] = url % arg.split('/')
|
83
|
-
break
|
84
|
-
elsif arg !~ /:|\//
|
85
70
|
# $ hub clone tilt
|
86
|
-
|
87
|
-
args[args.index(arg)] = url % [ github_user, arg ]
|
71
|
+
args[args.index(arg)] = github_url(:repo => arg, :private => ssh)
|
88
72
|
break
|
89
73
|
end
|
90
74
|
end
|
@@ -95,10 +79,24 @@ module Hub
|
|
95
79
|
#
|
96
80
|
# $ hub submodule add -p wycats/bundler vendor/bundler
|
97
81
|
# > git submodule add git@github.com:wycats/bundler.git vendor/bundler
|
82
|
+
#
|
83
|
+
# $ hub submodule add -b ryppl ryppl/pip vendor/bundler
|
84
|
+
# > git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip
|
98
85
|
def submodule(args)
|
99
86
|
return unless index = args.index('add')
|
100
87
|
args.delete_at index
|
88
|
+
|
89
|
+
branch = args.index('-b') || args.index('--branch')
|
90
|
+
if branch
|
91
|
+
args.delete_at branch
|
92
|
+
branch_name = args.delete_at branch
|
93
|
+
end
|
94
|
+
|
101
95
|
clone(args)
|
96
|
+
|
97
|
+
if branch_name
|
98
|
+
args.insert branch, '-b', branch_name
|
99
|
+
end
|
102
100
|
args.insert index, 'add'
|
103
101
|
end
|
104
102
|
|
@@ -111,18 +109,17 @@ module Hub
|
|
111
109
|
# $ hub remote add origin
|
112
110
|
# > git remote add origin git://github.com/YOUR_LOGIN/THIS_REPO.git
|
113
111
|
def remote(args)
|
114
|
-
return if args[1] != 'add'
|
112
|
+
return if args[1] != 'add' || args.last =~ %r{.+?://|.+?@|^[./]}
|
115
113
|
|
116
114
|
ssh = args.delete('-p')
|
117
|
-
url = ssh ? PRIVATE : PUBLIC
|
118
115
|
|
119
116
|
# user/repo
|
120
117
|
args.last =~ /\b(.+?)(?:\/(.+))?$/
|
121
|
-
user, repo = $1, $2
|
118
|
+
user, repo = $1, $2
|
122
119
|
|
123
120
|
if args.words[2] == 'origin' && args.words[3].nil?
|
124
|
-
# Origin special case
|
125
|
-
user =
|
121
|
+
# Origin special case triggers default user/repo
|
122
|
+
user = repo = nil
|
126
123
|
elsif args.words[-2] == args.words[1]
|
127
124
|
# rtomayko/tilt => rtomayko
|
128
125
|
# Make sure you dance around flags.
|
@@ -135,7 +132,7 @@ module Hub
|
|
135
132
|
args.replace args[0...-1]
|
136
133
|
end
|
137
134
|
|
138
|
-
args <<
|
135
|
+
args << github_url(:user => user, :repo => repo, :private => ssh)
|
139
136
|
end
|
140
137
|
|
141
138
|
# $ hub init -g
|
@@ -145,7 +142,7 @@ module Hub
|
|
145
142
|
if args.delete('-g')
|
146
143
|
# Can't do anything if we don't have a USER set.
|
147
144
|
|
148
|
-
url =
|
145
|
+
url = github_url(:private => true)
|
149
146
|
args.after "git remote add origin #{url}"
|
150
147
|
end
|
151
148
|
end
|
@@ -157,9 +154,9 @@ module Hub
|
|
157
154
|
require 'net/http'
|
158
155
|
|
159
156
|
# can't do anything without token and original owner name
|
160
|
-
if github_user && github_token &&
|
157
|
+
if github_user && github_token && repo_owner
|
161
158
|
if own_repo_exists?
|
162
|
-
puts "#{github_user}/#{
|
159
|
+
puts "#{github_user}/#{repo_name} already exists on GitHub"
|
163
160
|
else
|
164
161
|
fork_repo
|
165
162
|
end
|
@@ -167,7 +164,7 @@ module Hub
|
|
167
164
|
if args.include?('--no-remote')
|
168
165
|
exit
|
169
166
|
else
|
170
|
-
url =
|
167
|
+
url = github_url(:private => true)
|
171
168
|
args.replace %W"remote add -f #{github_user} #{url}"
|
172
169
|
args.after { puts "new remote: #{github_user}" }
|
173
170
|
end
|
@@ -196,6 +193,9 @@ module Hub
|
|
196
193
|
# $ hub browse
|
197
194
|
# > open http://github.com/CURRENT_REPO
|
198
195
|
#
|
196
|
+
# $ hub browse -- issues
|
197
|
+
# > open http://github.com/CURRENT_REPO/issues
|
198
|
+
#
|
199
199
|
# $ hub browse pjhyett/github-services
|
200
200
|
# > open http://github.com/pjhyett/github-services
|
201
201
|
#
|
@@ -205,31 +205,75 @@ module Hub
|
|
205
205
|
# $ hub browse github-services
|
206
206
|
# > open http://github.com/YOUR_LOGIN/github-services
|
207
207
|
#
|
208
|
+
# $ hub browse github-services wiki
|
209
|
+
# > open http://wiki.github.com/YOUR_LOGIN/github-services
|
210
|
+
#
|
208
211
|
# $ hub browse -p github-fi
|
209
212
|
# > open https://github.com/YOUR_LOGIN/github-fi
|
210
213
|
def browse(args)
|
211
214
|
args.shift
|
212
|
-
|
213
|
-
|
215
|
+
browse_command(args) do
|
216
|
+
user = repo = nil
|
217
|
+
dest = args.shift
|
218
|
+
dest = nil if dest == '--'
|
214
219
|
|
215
|
-
|
216
|
-
if dest.include? '/'
|
220
|
+
if dest
|
217
221
|
# $ hub browse pjhyett/github-services
|
218
|
-
user, repo = dest.split('/')
|
219
|
-
else
|
220
222
|
# $ hub browse github-services
|
221
|
-
|
223
|
+
repo = dest
|
224
|
+
elsif repo_user
|
225
|
+
# $ hub browse
|
226
|
+
user = repo_user
|
227
|
+
else
|
228
|
+
abort "Usage: hub browse [<USER>/]<REPOSITORY>"
|
222
229
|
end
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
230
|
+
|
231
|
+
params = { :user => user, :repo => repo }
|
232
|
+
|
233
|
+
# $ hub browse -- wiki
|
234
|
+
case subpage = args.shift
|
235
|
+
when 'wiki'
|
236
|
+
params[:web] = 'wiki'
|
237
|
+
when 'commits'
|
238
|
+
branch = (!dest && tracked_branch) || 'master'
|
239
|
+
params[:web] = "/commits/#{branch}"
|
240
|
+
when 'tree', NilClass
|
241
|
+
branch = !dest && tracked_branch
|
242
|
+
params[:web] = "/tree/#{branch}" if branch && branch != 'master'
|
243
|
+
else
|
244
|
+
params[:web] = "/#{subpage}"
|
245
|
+
end
|
246
|
+
|
247
|
+
params
|
229
248
|
end
|
249
|
+
end
|
230
250
|
|
231
|
-
|
232
|
-
|
251
|
+
# $ hub compare 1.0...fix
|
252
|
+
# > open http://github.com/CURRENT_REPO/compare/1.0...fix
|
253
|
+
# $ hub compare refactor
|
254
|
+
# > open http://github.com/CURRENT_REPO/compare/refactor
|
255
|
+
# $ hub compare myfork feature
|
256
|
+
# > open http://github.com/myfork/REPO/compare/feature
|
257
|
+
# $ hub compare -p myfork topsecret
|
258
|
+
# > open https://github.com/myfork/REPO/compare/topsecret
|
259
|
+
# $ hub compare -u 1.0...2.0
|
260
|
+
# prints "http://github.com/CURRENT_REPO/compare/1.0...2.0"
|
261
|
+
def compare(args)
|
262
|
+
args.shift
|
263
|
+
browse_command(args) do
|
264
|
+
if args.empty?
|
265
|
+
branch = tracked_branch
|
266
|
+
if branch && branch != 'master'
|
267
|
+
range, user = branch, repo_user
|
268
|
+
else
|
269
|
+
abort "Usage: hub compare [USER] [<START>...]<END>"
|
270
|
+
end
|
271
|
+
else
|
272
|
+
range = args.pop
|
273
|
+
user = args.pop || repo_user
|
274
|
+
end
|
275
|
+
{ :user => user, :web => "/compare/#{range}" }
|
276
|
+
end
|
233
277
|
end
|
234
278
|
|
235
279
|
# $ hub hub standalone
|
@@ -367,28 +411,51 @@ help
|
|
367
411
|
# from the command line.
|
368
412
|
#
|
369
413
|
|
370
|
-
#
|
371
|
-
#
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
414
|
+
# Checks whether a command exists on this system in the $PATH.
|
415
|
+
#
|
416
|
+
# name - The String name of the command to check for.
|
417
|
+
#
|
418
|
+
# Returns a Boolean.
|
419
|
+
def command?(name)
|
420
|
+
`type -t #{command}`
|
421
|
+
$?.success?
|
378
422
|
end
|
379
423
|
|
380
|
-
|
381
|
-
|
382
|
-
|
424
|
+
# Detects commands to launch the user's browser, checking $BROWSER
|
425
|
+
# first then falling back to a few common launchers. Aborts with
|
426
|
+
# an error if it can't find anything appropriate.
|
427
|
+
#
|
428
|
+
# Returns a launch command.
|
429
|
+
def browser_launcher
|
430
|
+
if ENV['BROWSER']
|
431
|
+
ENV['BROWSER']
|
432
|
+
elsif RUBY_PLATFORM.include?('darwin')
|
433
|
+
"open"
|
434
|
+
elsif command?("xdg-open")
|
435
|
+
"xdg-open"
|
436
|
+
elsif command?("cygstart")
|
437
|
+
"cygstart"
|
383
438
|
else
|
384
|
-
|
439
|
+
abort "Please set $BROWSER to a web launcher to use this command."
|
385
440
|
end
|
386
441
|
end
|
387
442
|
|
443
|
+
# Handles common functionality of browser commands like `browse`
|
444
|
+
# and `compare`. Yields a block that returns params for `github_url`.
|
445
|
+
def browse_command(args)
|
446
|
+
url_only = args.delete('-u')
|
447
|
+
secure = args.delete('-p')
|
448
|
+
params = yield
|
449
|
+
|
450
|
+
args.executable = url_only ? 'echo' : browser_launcher
|
451
|
+
args.push github_url({:web => true, :private => secure}.update(params))
|
452
|
+
end
|
453
|
+
|
454
|
+
|
388
455
|
# Returns the terminal-formatted manpage, ready to be printed to
|
389
456
|
# the screen.
|
390
457
|
def hub_manpage
|
391
|
-
return "** Can't find groff(1)" unless groff
|
458
|
+
return "** Can't find groff(1)" unless command?('groff')
|
392
459
|
|
393
460
|
require 'open3'
|
394
461
|
out = nil
|
@@ -400,12 +467,6 @@ help
|
|
400
467
|
out
|
401
468
|
end
|
402
469
|
|
403
|
-
# Returns true if groff is installed and in our path, false if
|
404
|
-
# not.
|
405
|
-
def groff?
|
406
|
-
system("which groff")
|
407
|
-
end
|
408
|
-
|
409
470
|
# The groff command complete with crazy arguments we need to run
|
410
471
|
# in order to turn our raw roff (manpage markup) into something
|
411
472
|
# readable on the terminal.
|
@@ -474,7 +535,7 @@ help
|
|
474
535
|
#
|
475
536
|
# Returns a Boolean.
|
476
537
|
def own_repo_exists?
|
477
|
-
url = API_REPO % [
|
538
|
+
url = API_REPO % [github_user, repo_name]
|
478
539
|
Net::HTTPSuccess === Net::HTTP.get_response(URI(url))
|
479
540
|
end
|
480
541
|
|
@@ -482,8 +543,8 @@ help
|
|
482
543
|
#
|
483
544
|
# Returns nothing.
|
484
545
|
def fork_repo
|
485
|
-
url = API_FORK % [
|
486
|
-
Net::HTTP.post_form(URI(url), 'login' =>
|
546
|
+
url = API_FORK % [repo_owner, repo_name]
|
547
|
+
Net::HTTP.post_form(URI(url), 'login' => github_user, 'token' => github_token)
|
487
548
|
end
|
488
549
|
end
|
489
550
|
end
|