hub 1.8.4 → 1.9.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.
Potentially problematic release.
This version of hub might be problematic. Click here for more details.
- data/README.md +3 -18
- data/Rakefile +6 -2
- data/lib/hub.rb +2 -0
- data/lib/hub/commands.rb +51 -155
- data/lib/hub/context.rb +45 -185
- data/lib/hub/github_api.rb +359 -0
- data/lib/hub/json.rb +36 -0
- data/lib/hub/ssh_config.rb +91 -0
- data/lib/hub/standalone.rb +30 -29
- data/lib/hub/version.rb +1 -1
- data/man/hub.1 +3 -47
- data/man/hub.1.html +4 -25
- data/man/hub.1.ronn +3 -21
- data/test/helper.rb +14 -1
- data/test/hub_test.rb +100 -430
- data/test/standalone_test.rb +8 -3
- metadata +10 -8
data/lib/hub/standalone.rb
CHANGED
@@ -2,57 +2,58 @@ module Hub
|
|
2
2
|
module Standalone
|
3
3
|
extend self
|
4
4
|
|
5
|
-
|
6
|
-
else
|
7
|
-
require 'rbconfig'
|
8
|
-
File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
|
9
|
-
end
|
5
|
+
HUB_ROOT = File.expand_path('../../..', __FILE__)
|
10
6
|
|
11
7
|
PREAMBLE = <<-preamble
|
12
|
-
#!#{RUBY_BIN}
|
13
8
|
#
|
14
|
-
# This file
|
15
|
-
# Please DO NOT EDIT or send patches for it.
|
9
|
+
# This file is generated code. DO NOT send patches for it.
|
16
10
|
#
|
17
|
-
#
|
11
|
+
# Original source files with comments are at:
|
18
12
|
# https://github.com/defunkt/hub
|
19
|
-
# and submit patches against the individual files
|
20
|
-
# that build hub.
|
21
13
|
#
|
22
14
|
|
23
15
|
preamble
|
24
16
|
|
25
|
-
POSTAMBLE = "Hub::Runner.execute(*ARGV)\n"
|
26
|
-
__DIR__ = File.dirname(__FILE__)
|
27
|
-
MANPAGE = "__END__\n#{File.read(__DIR__ + '/../../man/hub.1')}"
|
28
|
-
|
29
17
|
def save(filename, path = '.')
|
30
18
|
target = File.join(File.expand_path(path), filename)
|
31
19
|
File.open(target, 'w') do |f|
|
32
|
-
f
|
20
|
+
build f
|
33
21
|
f.chmod 0755
|
34
22
|
end
|
35
23
|
end
|
36
24
|
|
37
|
-
def build
|
38
|
-
|
25
|
+
def build io
|
26
|
+
io.puts "#!#{ruby_executable}"
|
27
|
+
io << PREAMBLE
|
39
28
|
|
40
|
-
|
41
|
-
|
29
|
+
each_source_file do |filename|
|
30
|
+
File.open(filename, 'r') do |source|
|
31
|
+
source.each_line {|line| io << line if line !~ /^\s*#/ }
|
32
|
+
end
|
33
|
+
io.puts ''
|
34
|
+
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
io.puts "Hub::Runner.execute(*ARGV)"
|
37
|
+
io.puts "\n__END__"
|
38
|
+
io << File.read(File.join(HUB_ROOT, 'man/hub.1'))
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
def each_source_file
|
42
|
+
File.open(File.join(HUB_ROOT, 'lib/hub.rb'), 'r') do |main|
|
43
|
+
main.each_line do |req|
|
44
|
+
if req =~ /^require\s+["'](.+)["']/
|
45
|
+
yield File.join(HUB_ROOT, 'lib', "#{$1}.rb")
|
46
|
+
end
|
50
47
|
end
|
51
48
|
end
|
49
|
+
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def ruby_executable
|
52
|
+
if File.executable? '/usr/bin/ruby' then '/usr/bin/ruby'
|
53
|
+
else
|
54
|
+
require 'rbconfig'
|
55
|
+
File.join RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']
|
56
|
+
end
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
data/lib/hub/version.rb
CHANGED
data/man/hub.1
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
.\" generated with Ronn/v0.7.3
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.
|
4
|
-
.TH "HUB" "1" "
|
4
|
+
.TH "HUB" "1" "April 2012" "DEFUNKT" "Git Manual"
|
5
5
|
.
|
6
6
|
.SH "NAME"
|
7
7
|
\fBhub\fR \- git + hub = github
|
@@ -132,7 +132,7 @@ Open a GitHub compare view page in the system\'s default web browser\. \fISTART\
|
|
132
132
|
.
|
133
133
|
.TP
|
134
134
|
\fBgit fork\fR [\fB\-\-no\-remote\fR]
|
135
|
-
Forks the original project (referenced by "origin" remote) on GitHub and adds a new remote for it under your username\.
|
135
|
+
Forks the original project (referenced by "origin" remote) on GitHub and adds a new remote for it under your username\.
|
136
136
|
.
|
137
137
|
.TP
|
138
138
|
\fBgit pull\-request\fR [\fB\-f\fR] [\fITITLE\fR|\fB\-i\fR \fIISSUE\fR|\fIISSUE\-URL\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR]
|
@@ -145,37 +145,7 @@ If \fITITLE\fR is omitted, a text editor will open in which title and body of th
|
|
145
145
|
If instead of normal \fITITLE\fR an issue number is given with \fB\-i\fR, the pull request will be attached to an existing GitHub issue\. Alternatively, instead of title you can paste a full URL to an issue on GitHub\.
|
146
146
|
.
|
147
147
|
.SH "CONFIGURATION"
|
148
|
-
|
149
|
-
.
|
150
|
-
.IP "" 4
|
151
|
-
.
|
152
|
-
.nf
|
153
|
-
|
154
|
-
$ git config \-\-global github\.user
|
155
|
-
.
|
156
|
-
.fi
|
157
|
-
.
|
158
|
-
.IP "" 0
|
159
|
-
.
|
160
|
-
.P
|
161
|
-
Or, set the GitHub username and token with:
|
162
|
-
.
|
163
|
-
.IP "" 4
|
164
|
-
.
|
165
|
-
.nf
|
166
|
-
|
167
|
-
$ git config \-\-global github\.user <username>
|
168
|
-
$ git config \-\-global github\.token <token>
|
169
|
-
.
|
170
|
-
.fi
|
171
|
-
.
|
172
|
-
.IP "" 0
|
173
|
-
.
|
174
|
-
.P
|
175
|
-
You can override these values with \fIGITHUB_USER\fR and \fIGITHUB_TOKEN\fR environment variables\.
|
176
|
-
.
|
177
|
-
.P
|
178
|
-
See \fIhttp://help\.github\.com/set\-your\-user\-name\-email\-and\-github\-token/\fR for more information\.
|
148
|
+
Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in "~/\.config/hub"\.
|
179
149
|
.
|
180
150
|
.P
|
181
151
|
If you prefer the HTTPS protocol for GitHub repositories, you can set "hub\.protocol" to "https"\. This will affect \fBclone\fR, \fBfork\fR, \fBremote add\fR and other operations that expand references to GitHub repositories as full URLs that otherwise use git and ssh protocols\.
|
@@ -204,20 +174,6 @@ $ git config \-\-global \-\-add hub\.host my\.git\.org
|
|
204
174
|
.IP "" 0
|
205
175
|
.
|
206
176
|
.P
|
207
|
-
API username and token need also be configured for each Enterprise host:
|
208
|
-
.
|
209
|
-
.IP "" 4
|
210
|
-
.
|
211
|
-
.nf
|
212
|
-
|
213
|
-
$ git config \-\-global github\."my\.git\.org"\.user <username>
|
214
|
-
$ git config \-\-global github\."my\.git\.org"\.token <token>
|
215
|
-
.
|
216
|
-
.fi
|
217
|
-
.
|
218
|
-
.IP "" 0
|
219
|
-
.
|
220
|
-
.P
|
221
177
|
The default host for commands like \fBinit\fR and \fBclone\fR is still github\.com, but this can be affected with the \fIGITHUB_HOST\fR environment variable:
|
222
178
|
.
|
223
179
|
.IP "" 4
|
data/man/hub.1.html
CHANGED
@@ -173,8 +173,7 @@ the range of history to compare. If a range with two dots (<code>a..b</code>) is
|
|
173
173
|
it will be transformed into one with three dots. If <var>START</var> is omitted,
|
174
174
|
GitHub will compare against the base branch (the default is "master").</p></dd>
|
175
175
|
<dt><code>git fork</code> [<code>--no-remote</code>]</dt><dd><p>Forks the original project (referenced by "origin" remote) on GitHub and
|
176
|
-
adds a new remote for it under your username
|
177
|
-
be set (see CONFIGURATION).</p></dd>
|
176
|
+
adds a new remote for it under your username.</p></dd>
|
178
177
|
<dt><code>git pull-request</code> [<code>-f</code>] [<var>TITLE</var>|<code>-i</code> <var>ISSUE</var>|<var>ISSUE-URL</var>] [<code>-b</code> <var>BASE</var>] [<code>-h</code> <var>HEAD</var>]</dt><dd><p>Opens a pull request on GitHub for the project that the "origin" remote
|
179
178
|
points to. The default head of the pull request is the current branch.
|
180
179
|
Both base and head of the pull request can be explicitly given in one of
|
@@ -194,22 +193,8 @@ of title you can paste a full URL to an issue on GitHub.</p></dd>
|
|
194
193
|
|
195
194
|
<h2 id="CONFIGURATION">CONFIGURATION</h2>
|
196
195
|
|
197
|
-
<p>
|
198
|
-
|
199
|
-
<pre><code>$ git config --global github.user
|
200
|
-
</code></pre>
|
201
|
-
|
202
|
-
<p>Or, set the GitHub username and token with:</p>
|
203
|
-
|
204
|
-
<pre><code>$ git config --global github.user <username>
|
205
|
-
$ git config --global github.token <token>
|
206
|
-
</code></pre>
|
207
|
-
|
208
|
-
<p>You can override these values with <var>GITHUB_USER</var> and <var>GITHUB_TOKEN</var>
|
209
|
-
environment variables.</p>
|
210
|
-
|
211
|
-
<p>See <a href="http://help.github.com/set-your-user-name-email-and-github-token/" data-bare-link="true">http://help.github.com/set-your-user-name-email-and-github-token/</a> for more
|
212
|
-
information.</p>
|
196
|
+
<p>Hub will prompt for GitHub username & password the first time it needs to access
|
197
|
+
the API and exchange it for an OAuth token, which it saves in "~/.config/hub".</p>
|
213
198
|
|
214
199
|
<p>If you prefer the HTTPS protocol for GitHub repositories, you can set
|
215
200
|
"hub.protocol" to "https". This will affect <code>clone</code>, <code>fork</code>, <code>remote add</code>
|
@@ -228,12 +213,6 @@ configure hub to treat such remotes same as github.com:</p>
|
|
228
213
|
<pre><code>$ git config --global --add hub.host my.git.org
|
229
214
|
</code></pre>
|
230
215
|
|
231
|
-
<p>API username and token need also be configured for each Enterprise host:</p>
|
232
|
-
|
233
|
-
<pre><code>$ git config --global github."my.git.org".user <username>
|
234
|
-
$ git config --global github."my.git.org".token <token>
|
235
|
-
</code></pre>
|
236
|
-
|
237
216
|
<p>The default host for commands like <code>init</code> and <code>clone</code> is still
|
238
217
|
github.com, but this can be affected with the <var>GITHUB_HOST</var> environment
|
239
218
|
variable:</p>
|
@@ -448,7 +427,7 @@ $ git help hub
|
|
448
427
|
|
449
428
|
<ol class='man-decor man-foot man foot'>
|
450
429
|
<li class='tl'>DEFUNKT</li>
|
451
|
-
<li class='tc'>
|
430
|
+
<li class='tc'>April 2012</li>
|
452
431
|
<li class='tr'>hub(1)</li>
|
453
432
|
</ol>
|
454
433
|
|
data/man/hub.1.ronn
CHANGED
@@ -128,8 +128,7 @@ hub also adds some custom commands that are otherwise not present in git:
|
|
128
128
|
|
129
129
|
* `git fork` [`--no-remote`]:
|
130
130
|
Forks the original project (referenced by "origin" remote) on GitHub and
|
131
|
-
adds a new remote for it under your username.
|
132
|
-
be set (see CONFIGURATION).
|
131
|
+
adds a new remote for it under your username.
|
133
132
|
|
134
133
|
* `git pull-request` [`-f`] [<TITLE>|`-i` <ISSUE>|<ISSUE-URL>] [`-b` <BASE>] [`-h` <HEAD>]:
|
135
134
|
Opens a pull request on GitHub for the project that the "origin" remote
|
@@ -149,20 +148,8 @@ hub also adds some custom commands that are otherwise not present in git:
|
|
149
148
|
|
150
149
|
## CONFIGURATION
|
151
150
|
|
152
|
-
|
153
|
-
|
154
|
-
$ git config --global github.user
|
155
|
-
|
156
|
-
Or, set the GitHub username and token with:
|
157
|
-
|
158
|
-
$ git config --global github.user <username>
|
159
|
-
$ git config --global github.token <token>
|
160
|
-
|
161
|
-
You can override these values with <GITHUB_USER> and <GITHUB_TOKEN>
|
162
|
-
environment variables.
|
163
|
-
|
164
|
-
See <http://help.github.com/set-your-user-name-email-and-github-token/> for more
|
165
|
-
information.
|
151
|
+
Hub will prompt for GitHub username & password the first time it needs to access
|
152
|
+
the API and exchange it for an OAuth token, which it saves in "~/.config/hub".
|
166
153
|
|
167
154
|
If you prefer the HTTPS protocol for GitHub repositories, you can set
|
168
155
|
"hub.protocol" to "https". This will affect `clone`, `fork`, `remote add`
|
@@ -179,11 +166,6 @@ configure hub to treat such remotes same as github.com:
|
|
179
166
|
|
180
167
|
$ git config --global --add hub.host my.git.org
|
181
168
|
|
182
|
-
API username and token need also be configured for each Enterprise host:
|
183
|
-
|
184
|
-
$ git config --global github."my.git.org".user <username>
|
185
|
-
$ git config --global github."my.git.org".token <token>
|
186
|
-
|
187
169
|
The default host for commands like `init` and `clone` is still
|
188
170
|
github.com, but this can be affected with the <GITHUB_HOST> environment
|
189
171
|
variable:
|
data/test/helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'hub'
|
3
|
-
require 'hub/standalone'
|
4
3
|
|
5
4
|
# We're checking for `open` in our tests
|
6
5
|
ENV['BROWSER'] = 'open'
|
@@ -9,6 +8,9 @@ ENV['BROWSER'] = 'open'
|
|
9
8
|
fakebin_dir = File.expand_path('../fakebin', __FILE__)
|
10
9
|
ENV['PATH'] = "#{fakebin_dir}:#{ENV['PATH']}"
|
11
10
|
|
11
|
+
# Use an isolated config file in testing
|
12
|
+
ENV['HUB_CONFIG'] = File.join(ENV['TMPDIR'] || '/tmp', 'hub-test-config')
|
13
|
+
|
12
14
|
class Test::Unit::TestCase
|
13
15
|
# Shortcut for creating a `Hub` instance. Pass it what you would
|
14
16
|
# normally pass `hub` on the command line, e.g.
|
@@ -98,4 +100,15 @@ class Test::Unit::TestCase
|
|
98
100
|
assert expected == output,
|
99
101
|
"expected:\n#{expected}\ngot:\n#{output}"
|
100
102
|
end
|
103
|
+
|
104
|
+
def edit_hub_config
|
105
|
+
config = ENV['HUB_CONFIG']
|
106
|
+
if File.exist? config
|
107
|
+
data = YAML.load File.read(config)
|
108
|
+
else
|
109
|
+
data = {}
|
110
|
+
end
|
111
|
+
yield data
|
112
|
+
File.open(config, 'w') { |cfg| cfg << YAML.dump(data) }
|
113
|
+
end
|
101
114
|
end
|
data/test/hub_test.rb
CHANGED
@@ -3,6 +3,7 @@ require 'webmock/test_unit'
|
|
3
3
|
require 'rbconfig'
|
4
4
|
require 'yaml'
|
5
5
|
require 'forwardable'
|
6
|
+
require 'fileutils'
|
6
7
|
|
7
8
|
WebMock::BodyPattern.class_eval do
|
8
9
|
undef normalize_hash
|
@@ -21,7 +22,7 @@ class HubTest < Test::Unit::TestCase
|
|
21
22
|
|
22
23
|
COMMANDS = []
|
23
24
|
|
24
|
-
Hub::Context.class_eval do
|
25
|
+
Hub::Context::System.class_eval do
|
25
26
|
remove_method :which
|
26
27
|
define_method :which do |name|
|
27
28
|
COMMANDS.include?(name) ? "/usr/bin/#{name}" : nil
|
@@ -36,7 +37,22 @@ class HubTest < Test::Unit::TestCase
|
|
36
37
|
super
|
37
38
|
COMMANDS.replace %w[open groff]
|
38
39
|
Hub::Context::PWD.replace '/path/to/hub'
|
39
|
-
Hub::
|
40
|
+
Hub::SshConfig::CONFIG_FILES.replace []
|
41
|
+
|
42
|
+
@prompt_stubs = prompt_stubs = []
|
43
|
+
@password_prompt_stubs = password_prompt_stubs = []
|
44
|
+
|
45
|
+
Hub::GitHubAPI::Configuration.class_eval do
|
46
|
+
undef prompt
|
47
|
+
undef prompt_password
|
48
|
+
|
49
|
+
define_method :prompt do |what|
|
50
|
+
prompt_stubs.shift.call(what)
|
51
|
+
end
|
52
|
+
define_method :prompt_password do |host, user|
|
53
|
+
password_prompt_stubs.shift.call(host, user)
|
54
|
+
end
|
55
|
+
end
|
40
56
|
|
41
57
|
@git_reader = Hub::Context::GitReader.new 'git' do |cache, cmd|
|
42
58
|
unless cmd.index('config --get alias.') == 0
|
@@ -46,12 +62,17 @@ class HubTest < Test::Unit::TestCase
|
|
46
62
|
|
47
63
|
Hub::Commands.instance_variable_set :@git_reader, @git_reader
|
48
64
|
Hub::Commands.instance_variable_set :@local_repo, nil
|
65
|
+
Hub::Commands.instance_variable_set :@api_client, nil
|
66
|
+
|
67
|
+
FileUtils.rm_rf ENV['HUB_CONFIG']
|
68
|
+
|
69
|
+
edit_hub_config do |data|
|
70
|
+
data['github.com'] = [{'user' => 'tpw', 'oauth_token' => 'OTOKEN'}]
|
71
|
+
end
|
49
72
|
|
50
73
|
@git_reader.stub! \
|
51
74
|
'remote' => "mislav\norigin",
|
52
75
|
'symbolic-ref -q HEAD' => 'refs/heads/master',
|
53
|
-
'config --get github.user' => 'tpw',
|
54
|
-
'config --get github.token' => 'abc123',
|
55
76
|
'config --get-all remote.origin.url' => 'git://github.com/defunkt/hub.git',
|
56
77
|
'config --get-all remote.mislav.url' => 'git://github.com/mislav/hub.git',
|
57
78
|
'rev-parse --symbolic-full-name master@{upstream}' => 'refs/remotes/origin/master',
|
@@ -61,278 +82,6 @@ class HubTest < Test::Unit::TestCase
|
|
61
82
|
'rev-parse -q --git-dir' => '.git'
|
62
83
|
end
|
63
84
|
|
64
|
-
def test_private_clone
|
65
|
-
stub_no_git_repo
|
66
|
-
input = "clone -p rtomayko/ronn"
|
67
|
-
command = "git clone git@github.com:rtomayko/ronn.git"
|
68
|
-
assert_command input, command
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_private_clone_noop
|
72
|
-
stub_no_git_repo
|
73
|
-
input = "--noop clone -p rtomayko/ronn"
|
74
|
-
command = "git clone git@github.com:rtomayko/ronn.git\n"
|
75
|
-
assert_output command, hub(input)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_https_clone
|
79
|
-
stub_no_git_repo
|
80
|
-
stub_https_is_preferred
|
81
|
-
input = "clone rtomayko/ronn"
|
82
|
-
command = "git clone https://github.com/rtomayko/ronn.git"
|
83
|
-
assert_command input, command
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_public_clone
|
87
|
-
stub_no_git_repo
|
88
|
-
input = "clone rtomayko/ronn"
|
89
|
-
command = "git clone git://github.com/rtomayko/ronn.git"
|
90
|
-
assert_command input, command
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_your_private_clone
|
94
|
-
stub_no_git_repo
|
95
|
-
input = "clone -p resque"
|
96
|
-
command = "git clone git@github.com:tpw/resque.git"
|
97
|
-
assert_command input, command
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_your_clone_is_always_private
|
101
|
-
stub_no_git_repo
|
102
|
-
input = "clone resque"
|
103
|
-
command = "git clone git@github.com:tpw/resque.git"
|
104
|
-
assert_command input, command
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_clone_repo_with_period
|
108
|
-
stub_no_git_repo
|
109
|
-
input = "clone hookio/hook.js"
|
110
|
-
command = "git clone git://github.com/hookio/hook.js.git"
|
111
|
-
assert_command input, command
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_clone_with_arguments
|
115
|
-
stub_no_git_repo
|
116
|
-
input = "clone --bare -o master resque"
|
117
|
-
command = "git clone --bare -o master git@github.com:tpw/resque.git"
|
118
|
-
assert_command input, command
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_clone_with_arguments_and_destination
|
122
|
-
stub_no_git_repo
|
123
|
-
assert_forwarded "clone --template=one/two git://github.com/tpw/resque.git --origin master resquetastic"
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_your_private_clone_fails_without_config
|
127
|
-
stub_no_git_repo
|
128
|
-
out = hub("clone -p mustache") do
|
129
|
-
stub_github_user(nil)
|
130
|
-
end
|
131
|
-
|
132
|
-
assert_equal "** No GitHub user set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_your_public_clone_fails_without_config
|
136
|
-
stub_no_git_repo
|
137
|
-
out = hub("clone mustache") do
|
138
|
-
stub_github_user(nil)
|
139
|
-
end
|
140
|
-
|
141
|
-
assert_equal "** No GitHub user set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_private_clone_left_alone
|
145
|
-
stub_no_git_repo
|
146
|
-
assert_forwarded "clone git@github.com:rtomayko/ronn.git"
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_public_clone_left_alone
|
150
|
-
stub_no_git_repo
|
151
|
-
assert_forwarded "clone git://github.com/rtomayko/ronn.git"
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_normal_public_clone_with_path
|
155
|
-
stub_no_git_repo
|
156
|
-
assert_forwarded "clone git://github.com/rtomayko/ronn.git ronn-dev"
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_normal_clone_from_path
|
160
|
-
stub_no_git_repo
|
161
|
-
assert_forwarded "clone ./test"
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_unchanged_clone_from_existing_directory
|
165
|
-
stub_no_git_repo
|
166
|
-
assert_forwarded "clone test"
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_local_clone_with_destination
|
170
|
-
stub_no_git_repo
|
171
|
-
assert_forwarded "clone -l . ../copy"
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_clone_with_host_alias
|
175
|
-
stub_no_git_repo
|
176
|
-
assert_forwarded "clone server:git/repo.git"
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_enterprise_clone
|
180
|
-
stub_no_git_repo
|
181
|
-
stub_github_user('myfiname', 'git.my.org')
|
182
|
-
with_host_env('git.my.org') do
|
183
|
-
assert_command "clone myrepo", "git clone git@git.my.org:myfiname/myrepo.git"
|
184
|
-
assert_command "clone another/repo", "git clone git@git.my.org:another/repo.git"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_alias_expand
|
189
|
-
stub_alias 'c', 'clone --bare'
|
190
|
-
input = "c rtomayko/ronn"
|
191
|
-
command = "git clone --bare git://github.com/rtomayko/ronn.git"
|
192
|
-
assert_command input, command
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_alias_expand_advanced
|
196
|
-
stub_alias 'c', 'clone --template="white space"'
|
197
|
-
input = "c rtomayko/ronn"
|
198
|
-
command = "git clone '--template=white space' git://github.com/rtomayko/ronn.git"
|
199
|
-
assert_command input, command
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_alias_doesnt_expand_for_unknown_commands
|
203
|
-
stub_alias 'c', 'compute --fast'
|
204
|
-
assert_forwarded "c rtomayko/ronn"
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_remote_origin
|
208
|
-
input = "remote add origin"
|
209
|
-
command = "git remote add origin git://github.com/tpw/hub.git"
|
210
|
-
assert_command input, command
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_remote_add_with_name
|
214
|
-
input = "remote add another hookio/hub.js"
|
215
|
-
command = "git remote add another git://github.com/hookio/hub.js.git"
|
216
|
-
assert_command input, command
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_private_remote_origin
|
220
|
-
input = "remote add -p origin"
|
221
|
-
command = "git remote add origin git@github.com:tpw/hub.git"
|
222
|
-
assert_command input, command
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_public_remote_url_untouched
|
226
|
-
assert_forwarded "remote add origin http://github.com/defunkt/resque.git"
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_private_remote_url_untouched
|
230
|
-
assert_forwarded "remote add origin git@github.com:defunkt/resque.git"
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_remote_from_rel_path
|
234
|
-
assert_forwarded "remote add origin ./path"
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_remote_from_abs_path
|
238
|
-
assert_forwarded "remote add origin /path"
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_remote_with_host_alias
|
242
|
-
assert_forwarded "remote add origin server:/git/repo.git"
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_remote_add_enterprise
|
246
|
-
stub_hub_host('git.my.org')
|
247
|
-
stub_repo_url('git@git.my.org:defunkt/hub.git')
|
248
|
-
assert_command "remote add another", "git remote add another git@git.my.org:another/hub.git"
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_public_submodule
|
252
|
-
input = "submodule add wycats/bundler vendor/bundler"
|
253
|
-
command = "git submodule add git://github.com/wycats/bundler.git vendor/bundler"
|
254
|
-
assert_command input, command
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_private_submodule
|
258
|
-
input = "submodule add -p grit vendor/grit"
|
259
|
-
command = "git submodule add git@github.com:tpw/grit.git vendor/grit"
|
260
|
-
assert_command input, command
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_submodule_branch
|
264
|
-
input = "submodule add -b ryppl ryppl/pip vendor/pip"
|
265
|
-
command = "git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip"
|
266
|
-
assert_command input, command
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_submodule_with_args
|
270
|
-
input = "submodule -q add --bare -- grit grit"
|
271
|
-
command = "git submodule -q add --bare -- git://github.com/tpw/grit.git grit"
|
272
|
-
assert_command input, command
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_private_remote
|
276
|
-
input = "remote add -p rtomayko"
|
277
|
-
command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
|
278
|
-
assert_command input, command
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_https_protocol_remote
|
282
|
-
stub_https_is_preferred
|
283
|
-
input = "remote add rtomayko"
|
284
|
-
command = "git remote add rtomayko https://github.com/rtomayko/hub.git"
|
285
|
-
assert_command input, command
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_public_remote
|
289
|
-
input = "remote add rtomayko"
|
290
|
-
command = "git remote add rtomayko git://github.com/rtomayko/hub.git"
|
291
|
-
assert_command input, command
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_public_remote_f
|
295
|
-
input = "remote add -f rtomayko"
|
296
|
-
command = "git remote add -f rtomayko git://github.com/rtomayko/hub.git"
|
297
|
-
assert_command input, command
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_named_public_remote
|
301
|
-
input = "remote add origin rtomayko"
|
302
|
-
command = "git remote add origin git://github.com/rtomayko/hub.git"
|
303
|
-
assert_command input, command
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_named_public_remote_f
|
307
|
-
input = "remote add -f origin rtomayko"
|
308
|
-
command = "git remote add -f origin git://github.com/rtomayko/hub.git"
|
309
|
-
assert_command input, command
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_private_remote_with_repo
|
313
|
-
input = "remote add -p jashkenas/coffee-script"
|
314
|
-
command = "git remote add jashkenas git@github.com:jashkenas/coffee-script.git"
|
315
|
-
assert_command input, command
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_public_remote_with_repo
|
319
|
-
input = "remote add jashkenas/coffee-script"
|
320
|
-
command = "git remote add jashkenas git://github.com/jashkenas/coffee-script.git"
|
321
|
-
assert_command input, command
|
322
|
-
end
|
323
|
-
|
324
|
-
def test_public_remote_f_with_repo
|
325
|
-
input = "remote add -f jashkenas/coffee-script"
|
326
|
-
command = "git remote add -f jashkenas git://github.com/jashkenas/coffee-script.git"
|
327
|
-
assert_command input, command
|
328
|
-
end
|
329
|
-
|
330
|
-
def test_named_private_remote_with_repo
|
331
|
-
input = "remote add -p origin jashkenas/coffee-script"
|
332
|
-
command = "git remote add origin git@github.com:jashkenas/coffee-script.git"
|
333
|
-
assert_command input, command
|
334
|
-
end
|
335
|
-
|
336
85
|
def test_fetch_existing_remote
|
337
86
|
assert_forwarded "fetch mislav"
|
338
87
|
end
|
@@ -356,19 +105,6 @@ class HubTest < Test::Unit::TestCase
|
|
356
105
|
"fetch xoebus"
|
357
106
|
end
|
358
107
|
|
359
|
-
def test_fetch_no_auth
|
360
|
-
stub_github_user nil
|
361
|
-
stub_github_token nil
|
362
|
-
stub_remotes_group('xoebus', nil)
|
363
|
-
# stub_existing_fork('xoebus')
|
364
|
-
stub_request(:get, "https://github.com/api/v2/yaml/repos/show/xoebus/hub").
|
365
|
-
to_return(:status => 200)
|
366
|
-
|
367
|
-
assert_commands "git remote add xoebus git://github.com/xoebus/hub.git",
|
368
|
-
"git fetch xoebus",
|
369
|
-
"fetch xoebus"
|
370
|
-
end
|
371
|
-
|
372
108
|
def test_fetch_new_remote_with_options
|
373
109
|
stub_remotes_group('xoebus', nil)
|
374
110
|
stub_existing_fork('xoebus')
|
@@ -550,18 +286,13 @@ class HubTest < Test::Unit::TestCase
|
|
550
286
|
def test_init_enterprise
|
551
287
|
stub_no_remotes
|
552
288
|
stub_no_git_repo
|
553
|
-
|
554
|
-
|
555
|
-
assert_commands "git init", "git remote add origin git@git.my.org:myfiname/hub.git", "init -g"
|
289
|
+
edit_hub_config do |data|
|
290
|
+
data['git.my.org'] = [{'user'=>'myfiname'}]
|
556
291
|
end
|
557
|
-
end
|
558
292
|
|
559
|
-
|
560
|
-
|
561
|
-
stub_github_user(nil)
|
293
|
+
with_host_env('git.my.org') do
|
294
|
+
assert_commands "git init", "git remote add origin git@git.my.org:myfiname/hub.git", "init -g"
|
562
295
|
end
|
563
|
-
|
564
|
-
assert_equal "** No GitHub user set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
|
565
296
|
end
|
566
297
|
|
567
298
|
def test_push_untouched
|
@@ -589,8 +320,8 @@ class HubTest < Test::Unit::TestCase
|
|
589
320
|
def test_create
|
590
321
|
stub_no_remotes
|
591
322
|
stub_nonexisting_fork('tpw')
|
592
|
-
stub_request(:post, "https
|
593
|
-
with(:body => { 'name' => 'hub' })
|
323
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
324
|
+
with(:body => { 'name' => 'hub', 'private' => false })
|
594
325
|
|
595
326
|
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
|
596
327
|
expected << "created repository: tpw/hub\n"
|
@@ -600,8 +331,8 @@ class HubTest < Test::Unit::TestCase
|
|
600
331
|
def test_create_custom_name
|
601
332
|
stub_no_remotes
|
602
333
|
stub_nonexisting_fork('tpw', 'hubbub')
|
603
|
-
stub_request(:post, "https
|
604
|
-
with(:body => { 'name' => 'hubbub' })
|
334
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
335
|
+
with(:body => { 'name' => 'hubbub', 'private' => false })
|
605
336
|
|
606
337
|
expected = "remote add -f origin git@github.com:tpw/hubbub.git\n"
|
607
338
|
expected << "created repository: tpw/hubbub\n"
|
@@ -611,72 +342,29 @@ class HubTest < Test::Unit::TestCase
|
|
611
342
|
def test_create_in_organization
|
612
343
|
stub_no_remotes
|
613
344
|
stub_nonexisting_fork('acme', 'hubbub')
|
614
|
-
stub_request(:post, "https
|
615
|
-
with(:body => { 'name' => '
|
345
|
+
stub_request(:post, "https://api.github.com/orgs/acme/repos").
|
346
|
+
with(:body => { 'name' => 'hubbub', 'private' => false })
|
616
347
|
|
617
348
|
expected = "remote add -f origin git@github.com:acme/hubbub.git\n"
|
618
349
|
expected << "created repository: acme/hubbub\n"
|
619
350
|
assert_equal expected, hub("create acme/hubbub") { ENV['GIT'] = 'echo' }
|
620
351
|
end
|
621
352
|
|
622
|
-
def test_create_no_openssl
|
623
|
-
stub_no_remotes
|
624
|
-
# stub_nonexisting_fork('tpw')
|
625
|
-
stub_request(:get, "http://#{auth}github.com/api/v2/yaml/repos/show/tpw/hub").
|
626
|
-
to_return(:status => 404)
|
627
|
-
|
628
|
-
stub_request(:post, "http://#{auth}github.com/api/v2/json/repos/create").
|
629
|
-
with(:body => { 'name' => 'hub' })
|
630
|
-
|
631
|
-
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
|
632
|
-
expected << "created repository: tpw/hub\n"
|
633
|
-
|
634
|
-
assert_equal expected, hub("create") {
|
635
|
-
ENV['GIT'] = 'echo'
|
636
|
-
require 'net/https'
|
637
|
-
Object.send :remove_const, :OpenSSL
|
638
|
-
}
|
639
|
-
end
|
640
|
-
|
641
353
|
def test_create_failed
|
642
354
|
stub_no_remotes
|
643
355
|
stub_nonexisting_fork('tpw')
|
644
|
-
stub_request(:post, "https
|
356
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
645
357
|
to_return(:status => [401, "Your token is fail"])
|
646
358
|
|
647
359
|
expected = "Error creating repository: Your token is fail (HTTP 401)\n"
|
648
|
-
expected << "Check your token configuration (`git config github.token`)\n"
|
649
360
|
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
|
650
361
|
end
|
651
362
|
|
652
|
-
def test_create_with_env_authentication
|
653
|
-
stub_no_remotes
|
654
|
-
old_user = ENV['GITHUB_USER']
|
655
|
-
old_token = ENV['GITHUB_TOKEN']
|
656
|
-
ENV['GITHUB_USER'] = 'mojombo'
|
657
|
-
ENV['GITHUB_TOKEN'] = '123abc'
|
658
|
-
|
659
|
-
# stub_nonexisting_fork('mojombo')
|
660
|
-
stub_request(:get, "https://#{auth('mojombo', '123abc')}github.com/api/v2/yaml/repos/show/mojombo/hub").
|
661
|
-
to_return(:status => 404)
|
662
|
-
|
663
|
-
stub_request(:post, "https://#{auth('mojombo', '123abc')}github.com/api/v2/json/repos/create").
|
664
|
-
with(:body => { 'name' => 'hub' })
|
665
|
-
|
666
|
-
expected = "remote add -f origin git@github.com:mojombo/hub.git\n"
|
667
|
-
expected << "created repository: mojombo/hub\n"
|
668
|
-
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
|
669
|
-
|
670
|
-
ensure
|
671
|
-
ENV['GITHUB_USER'] = old_user
|
672
|
-
ENV['GITHUB_TOKEN'] = old_token
|
673
|
-
end
|
674
|
-
|
675
363
|
def test_create_private_repository
|
676
364
|
stub_no_remotes
|
677
365
|
stub_nonexisting_fork('tpw')
|
678
|
-
stub_request(:post, "https
|
679
|
-
with(:body => { 'name' => 'hub', '
|
366
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
367
|
+
with(:body => { 'name' => 'hub', 'private' => true })
|
680
368
|
|
681
369
|
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
|
682
370
|
expected << "created repository: tpw/hub\n"
|
@@ -686,10 +374,10 @@ class HubTest < Test::Unit::TestCase
|
|
686
374
|
def test_create_private_repository_fails
|
687
375
|
stub_no_remotes
|
688
376
|
stub_nonexisting_fork('tpw')
|
689
|
-
stub_request(:post, "https
|
377
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
690
378
|
to_return(:status => [422, "Unprocessable Entity"],
|
691
379
|
:headers => {"Content-type" => "application/json"},
|
692
|
-
:body => %({"
|
380
|
+
:body => %({"message":"repository creation failed: You are over your quota."}))
|
693
381
|
|
694
382
|
expected = "Error creating repository: Unprocessable Entity (HTTP 422)\n"
|
695
383
|
expected << "repository creation failed: You are over your quota.\n"
|
@@ -699,8 +387,9 @@ class HubTest < Test::Unit::TestCase
|
|
699
387
|
def test_create_with_description_and_homepage
|
700
388
|
stub_no_remotes
|
701
389
|
stub_nonexisting_fork('tpw')
|
702
|
-
stub_request(:post, "https
|
703
|
-
'name' => 'hub', '
|
390
|
+
stub_request(:post, "https://api.github.com/user/repos").with(:body => {
|
391
|
+
'name' => 'hub', 'private' => false,
|
392
|
+
'description' => 'toyproject', 'homepage' => 'http://example.com'
|
704
393
|
})
|
705
394
|
|
706
395
|
expected = "remote add -f origin git@github.com:tpw/hub.git\n"
|
@@ -734,14 +423,6 @@ class HubTest < Test::Unit::TestCase
|
|
734
423
|
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
|
735
424
|
end
|
736
425
|
|
737
|
-
def test_create_no_user
|
738
|
-
stub_no_remotes
|
739
|
-
out = hub("create") do
|
740
|
-
stub_github_token(nil)
|
741
|
-
end
|
742
|
-
assert_equal "** No GitHub token set. See http://help.github.com/set-your-user-name-email-and-github-token/\n", out
|
743
|
-
end
|
744
|
-
|
745
426
|
def test_create_outside_git_repo
|
746
427
|
stub_no_git_repo
|
747
428
|
assert_equal "'create' must be run from inside a git repository\n", hub("create")
|
@@ -749,8 +430,8 @@ class HubTest < Test::Unit::TestCase
|
|
749
430
|
|
750
431
|
def test_create_origin_already_exists
|
751
432
|
stub_nonexisting_fork('tpw')
|
752
|
-
stub_request(:post, "https
|
753
|
-
with(:body => { 'name' => 'hub' })
|
433
|
+
stub_request(:post, "https://api.github.com/user/repos").
|
434
|
+
with(:body => { 'name' => 'hub', 'private' => false })
|
754
435
|
|
755
436
|
expected = "remote -v\ncreated repository: tpw/hub\n"
|
756
437
|
assert_equal expected, hub("create") { ENV['GIT'] = 'echo' }
|
@@ -758,7 +439,7 @@ class HubTest < Test::Unit::TestCase
|
|
758
439
|
|
759
440
|
def test_fork
|
760
441
|
stub_nonexisting_fork('tpw')
|
761
|
-
stub_request(:post, "https
|
442
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/forks").
|
762
443
|
with { |req| req.headers['Content-Length'] == 0 }
|
763
444
|
|
764
445
|
expected = "remote add -f tpw git@github.com:tpw/hub.git\n"
|
@@ -769,7 +450,7 @@ class HubTest < Test::Unit::TestCase
|
|
769
450
|
def test_fork_https_protocol
|
770
451
|
stub_https_is_preferred
|
771
452
|
stub_nonexisting_fork('tpw')
|
772
|
-
stub_request(:post, "https
|
453
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/forks")
|
773
454
|
|
774
455
|
expected = "remote add -f tpw https://github.com/tpw/hub.git\n"
|
775
456
|
expected << "new remote: tpw\n"
|
@@ -785,12 +466,14 @@ class HubTest < Test::Unit::TestCase
|
|
785
466
|
def test_fork_enterprise
|
786
467
|
stub_hub_host('git.my.org')
|
787
468
|
stub_repo_url('git@git.my.org:defunkt/hub.git')
|
788
|
-
|
789
|
-
|
469
|
+
edit_hub_config do |data|
|
470
|
+
data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN'}]
|
471
|
+
end
|
790
472
|
|
791
|
-
stub_request(:get, "https
|
473
|
+
stub_request(:get, "https://git.my.org/repos/myfiname/hub").
|
792
474
|
to_return(:status => 404)
|
793
|
-
stub_request(:post, "https
|
475
|
+
stub_request(:post, "https://git.my.org/repos/defunkt/hub/forks").
|
476
|
+
with(:headers => {"Authorization" => "token FITOKEN"})
|
794
477
|
|
795
478
|
expected = "remote add -f myfiname git@git.my.org:myfiname/hub.git\n"
|
796
479
|
expected << "new remote: myfiname\n"
|
@@ -799,7 +482,7 @@ class HubTest < Test::Unit::TestCase
|
|
799
482
|
|
800
483
|
def test_fork_failed
|
801
484
|
stub_nonexisting_fork('tpw')
|
802
|
-
stub_request(:post, "https
|
485
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/forks").
|
803
486
|
to_return(:status => [500, "Your fork is fail"])
|
804
487
|
|
805
488
|
expected = "Error creating fork: Your fork is fail (HTTP 500)\n"
|
@@ -808,7 +491,7 @@ class HubTest < Test::Unit::TestCase
|
|
808
491
|
|
809
492
|
def test_fork_no_remote
|
810
493
|
stub_nonexisting_fork('tpw')
|
811
|
-
stub_request(:post, "https
|
494
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/forks")
|
812
495
|
|
813
496
|
assert_equal "", hub("fork --no-remote") { ENV['GIT'] = 'echo' }
|
814
497
|
end
|
@@ -839,9 +522,9 @@ class HubTest < Test::Unit::TestCase
|
|
839
522
|
stub_branch('refs/heads/feature')
|
840
523
|
stub_tracking_nothing('feature')
|
841
524
|
|
842
|
-
stub_request(:post, "https
|
843
|
-
with(:body => { '
|
844
|
-
req.headers['Content-Length'] ==
|
525
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
526
|
+
with(:body => { 'base' => "master", 'head' => "tpw:feature", 'title' => "hereyougo" }) { |req|
|
527
|
+
req.headers['Content-Length'] == 63
|
845
528
|
}.to_return(:body => mock_pullreq_response(1))
|
846
529
|
|
847
530
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -852,8 +535,8 @@ class HubTest < Test::Unit::TestCase
|
|
852
535
|
stub_branch('refs/heads/feature')
|
853
536
|
stub_tracking('feature', 'mislav', 'yay-feature')
|
854
537
|
|
855
|
-
stub_request(:post, "https
|
856
|
-
with(:body => {
|
538
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
539
|
+
with(:body => {'base' => "master", 'head' => "mislav:yay-feature", 'title' => "hereyougo" }).
|
857
540
|
to_return(:body => mock_pullreq_response(1))
|
858
541
|
|
859
542
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -864,8 +547,8 @@ class HubTest < Test::Unit::TestCase
|
|
864
547
|
stub_branch('refs/heads/feature')
|
865
548
|
stub_tracking('feature', 'refs/heads/master')
|
866
549
|
|
867
|
-
stub_request(:post, "https
|
868
|
-
with(:body => {
|
550
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
551
|
+
with(:body => {'base' => "master", 'head' => "tpw:feature", 'title' => "hereyougo" }).
|
869
552
|
to_return(:body => mock_pullreq_response(1))
|
870
553
|
|
871
554
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -884,14 +567,15 @@ class HubTest < Test::Unit::TestCase
|
|
884
567
|
def test_pullrequest_enterprise_no_tracking
|
885
568
|
stub_hub_host('git.my.org')
|
886
569
|
stub_repo_url('git@git.my.org:defunkt/hub.git')
|
887
|
-
stub_github_user('myfiname', 'git.my.org')
|
888
|
-
stub_github_token('789xyz', 'git.my.org')
|
889
570
|
stub_branch('refs/heads/feature')
|
890
571
|
stub_tracking_nothing('feature')
|
891
572
|
stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil
|
573
|
+
edit_hub_config do |data|
|
574
|
+
data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN'}]
|
575
|
+
end
|
892
576
|
|
893
|
-
stub_request(:post, "https
|
894
|
-
with(:body => {
|
577
|
+
stub_request(:post, "https://git.my.org/repos/defunkt/hub/pulls").
|
578
|
+
with(:body => {'base' => "master", 'head' => "myfiname:feature", 'title' => "hereyougo" }).
|
895
579
|
to_return(:body => mock_pullreq_response(1, 'defunkt/hub', 'git.my.org'))
|
896
580
|
|
897
581
|
expected = "https://git.my.org/defunkt/hub/pull/1\n"
|
@@ -899,8 +583,8 @@ class HubTest < Test::Unit::TestCase
|
|
899
583
|
end
|
900
584
|
|
901
585
|
def test_pullrequest_explicit_head
|
902
|
-
stub_request(:post, "https
|
903
|
-
with(:body => {
|
586
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
587
|
+
with(:body => {'base' => "master", 'head' => "tpw:yay-feature", 'title' => "hereyougo" }).
|
904
588
|
to_return(:body => mock_pullreq_response(1))
|
905
589
|
|
906
590
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -908,8 +592,8 @@ class HubTest < Test::Unit::TestCase
|
|
908
592
|
end
|
909
593
|
|
910
594
|
def test_pullrequest_explicit_head_with_owner
|
911
|
-
stub_request(:post, "https
|
912
|
-
with(:body => {
|
595
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
596
|
+
with(:body => {'base' => "master", 'head' => "mojombo:feature", 'title' => "hereyougo" }).
|
913
597
|
to_return(:body => mock_pullreq_response(1))
|
914
598
|
|
915
599
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -917,8 +601,8 @@ class HubTest < Test::Unit::TestCase
|
|
917
601
|
end
|
918
602
|
|
919
603
|
def test_pullrequest_explicit_base
|
920
|
-
stub_request(:post, "https
|
921
|
-
with(:body => {
|
604
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
605
|
+
with(:body => {'base' => "feature", 'head' => "defunkt:master", 'title' => "hereyougo" }).
|
922
606
|
to_return(:body => mock_pullreq_response(1))
|
923
607
|
|
924
608
|
expected = "https://github.com/defunkt/hub/pull/1\n"
|
@@ -926,20 +610,20 @@ class HubTest < Test::Unit::TestCase
|
|
926
610
|
end
|
927
611
|
|
928
612
|
def test_pullrequest_explicit_base_with_owner
|
929
|
-
stub_request(:post, "https
|
930
|
-
with(:body => {
|
931
|
-
to_return(:body => mock_pullreq_response(1))
|
613
|
+
stub_request(:post, "https://api.github.com/repos/mojombo/hub/pulls").
|
614
|
+
with(:body => {'base' => "feature", 'head' => "defunkt:master", 'title' => "hereyougo" }).
|
615
|
+
to_return(:body => mock_pullreq_response(1, 'mojombo/hub'))
|
932
616
|
|
933
|
-
expected = "https://github.com/
|
617
|
+
expected = "https://github.com/mojombo/hub/pull/1\n"
|
934
618
|
assert_output expected, "pull-request hereyougo -b mojombo:feature -f"
|
935
619
|
end
|
936
620
|
|
937
621
|
def test_pullrequest_explicit_base_with_repo
|
938
|
-
stub_request(:post, "https
|
939
|
-
with(:body => {
|
940
|
-
to_return(:body => mock_pullreq_response(1))
|
622
|
+
stub_request(:post, "https://api.github.com/repos/mojombo/hubbub/pulls").
|
623
|
+
with(:body => {'base' => "feature", 'head' => "defunkt:master", 'title' => "hereyougo" }).
|
624
|
+
to_return(:body => mock_pullreq_response(1, 'mojombo/hubbub'))
|
941
625
|
|
942
|
-
expected = "https://github.com/
|
626
|
+
expected = "https://github.com/mojombo/hubbub/pull/1\n"
|
943
627
|
assert_output expected, "pull-request hereyougo -b mojombo/hubbub:feature -f"
|
944
628
|
end
|
945
629
|
|
@@ -948,8 +632,8 @@ class HubTest < Test::Unit::TestCase
|
|
948
632
|
stub_tracking('myfix', 'mislav', 'awesomefix')
|
949
633
|
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/awesomefix...", nil
|
950
634
|
|
951
|
-
stub_request(:post, "https
|
952
|
-
with(:body => {
|
635
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
636
|
+
with(:body => {'base' => "master", 'head' => "mislav:awesomefix", 'issue' => '92' }).
|
953
637
|
to_return(:body => mock_pullreq_response(92))
|
954
638
|
|
955
639
|
expected = "https://github.com/defunkt/hub/pull/92\n"
|
@@ -961,8 +645,8 @@ class HubTest < Test::Unit::TestCase
|
|
961
645
|
stub_tracking('myfix', 'mislav', 'awesomefix')
|
962
646
|
stub_command_output "rev-list --cherry-pick --right-only --no-merges mislav/awesomefix...", nil
|
963
647
|
|
964
|
-
stub_request(:post, "https
|
965
|
-
with(:body => {
|
648
|
+
stub_request(:post, "https://api.github.com/repos/mojombo/hub/pulls").
|
649
|
+
with(:body => {'base' => "master", 'head' => "mislav:awesomefix", 'issue' => '92' }).
|
966
650
|
to_return(:body => mock_pullreq_response(92, 'mojombo/hub'))
|
967
651
|
|
968
652
|
expected = "https://github.com/mojombo/hub/pull/92\n"
|
@@ -970,10 +654,10 @@ class HubTest < Test::Unit::TestCase
|
|
970
654
|
end
|
971
655
|
|
972
656
|
def test_pullrequest_fails
|
973
|
-
stub_request(:post, "https
|
657
|
+
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
|
974
658
|
to_return(:status => [422, "Unprocessable Entity"],
|
975
659
|
:headers => {"Content-type" => "application/json"},
|
976
|
-
:body => %({"
|
660
|
+
:body => %({"message":["oh no!\\nit failed."]}))
|
977
661
|
|
978
662
|
expected = "Error creating pull request: Unprocessable Entity (HTTP 422)\n"
|
979
663
|
expected << "oh no!\nit failed.\n"
|
@@ -985,7 +669,7 @@ class HubTest < Test::Unit::TestCase
|
|
985
669
|
end
|
986
670
|
|
987
671
|
def test_checkout_pullrequest
|
988
|
-
stub_request(:get, "https
|
672
|
+
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73").
|
989
673
|
to_return(:body => mock_pull_response('blueyed:feature'))
|
990
674
|
|
991
675
|
assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git',
|
@@ -994,7 +678,7 @@ class HubTest < Test::Unit::TestCase
|
|
994
678
|
end
|
995
679
|
|
996
680
|
def test_checkout_private_pullrequest
|
997
|
-
stub_request(:get, "https
|
681
|
+
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73").
|
998
682
|
to_return(:body => mock_pull_response('blueyed:feature', :private))
|
999
683
|
|
1000
684
|
assert_commands 'git remote add -f -t feature blueyed git@github.com:blueyed/hub.git',
|
@@ -1003,7 +687,7 @@ class HubTest < Test::Unit::TestCase
|
|
1003
687
|
end
|
1004
688
|
|
1005
689
|
def test_checkout_pullrequest_custom_branch
|
1006
|
-
stub_request(:get, "https
|
690
|
+
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73").
|
1007
691
|
to_return(:body => mock_pull_response('blueyed:feature'))
|
1008
692
|
|
1009
693
|
assert_commands 'git remote add -f -t feature blueyed git://github.com/blueyed/hub.git',
|
@@ -1014,7 +698,7 @@ class HubTest < Test::Unit::TestCase
|
|
1014
698
|
def test_checkout_pullrequest_existing_remote
|
1015
699
|
stub_command_output 'remote', "origin\nblueyed"
|
1016
700
|
|
1017
|
-
stub_request(:get, "https
|
701
|
+
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/73").
|
1018
702
|
to_return(:body => mock_pull_response('blueyed:feature'))
|
1019
703
|
|
1020
704
|
assert_commands 'git remote set-branches --add blueyed feature',
|
@@ -1059,9 +743,7 @@ class HubTest < Test::Unit::TestCase
|
|
1059
743
|
def test_help_hub
|
1060
744
|
help_manpage = hub("help hub")
|
1061
745
|
assert_includes "git + hub = github", help_manpage
|
1062
|
-
assert_includes
|
1063
|
-
Use git-config(1) to display the currently configured GitHub username:
|
1064
|
-
config
|
746
|
+
assert_includes "Hub will prompt for GitHub username & password", help_manpage
|
1065
747
|
end
|
1066
748
|
|
1067
749
|
def test_help_flag_on_command
|
@@ -1086,8 +768,7 @@ config
|
|
1086
768
|
end
|
1087
769
|
|
1088
770
|
def test_hub_standalone
|
1089
|
-
|
1090
|
-
assert_equal Hub::Standalone.build, help_standalone
|
771
|
+
assert_includes 'This file is generated code', hub("hub standalone")
|
1091
772
|
end
|
1092
773
|
|
1093
774
|
def test_hub_compare
|
@@ -1324,16 +1005,6 @@ config
|
|
1324
1005
|
|
1325
1006
|
private
|
1326
1007
|
|
1327
|
-
def stub_github_user(name, host = '')
|
1328
|
-
host = %(."#{host}") unless host.empty?
|
1329
|
-
stub_config_value "github#{host}.user", name
|
1330
|
-
end
|
1331
|
-
|
1332
|
-
def stub_github_token(token, host = '')
|
1333
|
-
host = %(."#{host}") unless host.empty?
|
1334
|
-
stub_config_value "github#{host}.token", token
|
1335
|
-
end
|
1336
|
-
|
1337
1008
|
def stub_repo_url(value, remote_name = 'origin')
|
1338
1009
|
stub_config_value "remote.#{remote_name}.url", value, '--get-all'
|
1339
1010
|
end
|
@@ -1376,7 +1047,7 @@ config
|
|
1376
1047
|
end
|
1377
1048
|
|
1378
1049
|
def stub_fork(user, repo, status)
|
1379
|
-
stub_request(:get, "https
|
1050
|
+
stub_request(:get, "https://api.github.com/repos/#{user}/#{repo}").
|
1380
1051
|
to_return(:status => status)
|
1381
1052
|
end
|
1382
1053
|
|
@@ -1427,16 +1098,15 @@ config
|
|
1427
1098
|
end
|
1428
1099
|
end
|
1429
1100
|
|
1430
|
-
def auth(user = git_config('github.user'), password = git_config('github.token'))
|
1431
|
-
"#{user}%2Ftoken:#{password}@"
|
1432
|
-
end
|
1433
|
-
|
1434
1101
|
def mock_pullreq_response(id, name_with_owner = 'defunkt/hub', host = 'github.com')
|
1435
|
-
|
1102
|
+
Hub::JSON.generate :html_url => "https://#{host}/#{name_with_owner}/pull/#{id}"
|
1436
1103
|
end
|
1437
1104
|
|
1438
1105
|
def mock_pull_response(label, priv = false)
|
1439
|
-
|
1106
|
+
Hub::JSON.generate :head => {
|
1107
|
+
:label => label,
|
1108
|
+
:repo => {:private => !!priv}
|
1109
|
+
}
|
1440
1110
|
end
|
1441
1111
|
|
1442
1112
|
def improved_help_text
|
@@ -1445,7 +1115,7 @@ config
|
|
1445
1115
|
|
1446
1116
|
def with_ssh_config
|
1447
1117
|
config_file = File.expand_path '../ssh_config', __FILE__
|
1448
|
-
Hub::
|
1118
|
+
Hub::SshConfig::CONFIG_FILES.replace [config_file]
|
1449
1119
|
yield
|
1450
1120
|
end
|
1451
1121
|
|