git-hub 1.3.0 → 1.3.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.
data/README.md CHANGED
@@ -131,6 +131,31 @@ superpowers:
131
131
  $ git remote add origin
132
132
  > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
133
133
 
134
+ ### git fetch
135
+
136
+ $ git fetch mislav
137
+ > git remote add mislav git://github.com/mislav/REPO.git
138
+ > git fetch mislav
139
+
140
+ $ git fetch mislav,xoebus
141
+ > git remote add mislav ...
142
+ > git remote add xoebus ...
143
+ > git fetch --multiple mislav xoebus
144
+
145
+ ### git cherry-pick
146
+
147
+ $ git cherry-pick http://github.com/mislav/REPO/commit/SHA
148
+ > git remote add -f mislav git://github.com/mislav/REPO.git
149
+ > git cherry-pick SHA
150
+
151
+ $ git cherry-pick mislav@SHA
152
+ > git remote add -f mislav git://github.com/mislav/CURRENT_REPO.git
153
+ > git cherry-pick SHA
154
+
155
+ $ git cherry-pick mislav@SHA
156
+ > git fetch mislav
157
+ > git cherry-pick SHA
158
+
134
159
  ### git fork
135
160
 
136
161
  $ git fork
data/Rakefile CHANGED
@@ -100,7 +100,7 @@ end
100
100
  desc "Push a new version."
101
101
  task :publish => "gem:publish" do
102
102
  require 'hub/version'
103
- sh "git tag v#{Hub::Version}"
103
+ system "git tag v#{Hub::Version}"
104
104
  sh "git push origin v#{Hub::Version}"
105
105
  sh "git push origin master"
106
106
  sh "gem push pkg/git-hub-#{Hub::Version}.gem"
data/lib/hub/args.rb CHANGED
@@ -52,7 +52,7 @@ module Hub
52
52
  # args = Args.new([ 'remote', 'add', '-f', 'tekkub' ])
53
53
  # args.words == [ 'remote', 'add', 'tekkub' ]
54
54
  def words
55
- reject { |arg| arg =~ /^-/ }
55
+ reject { |arg| arg.index('-') == 0 }
56
56
  end
57
57
 
58
58
  # All the flags (as opposed to words) contained in this argument
data/lib/hub/commands.rb CHANGED
@@ -135,6 +135,90 @@ module Hub
135
135
  args << github_url(:user => user, :repo => repo, :private => ssh)
136
136
  end
137
137
 
138
+ # $ hub fetch mislav
139
+ # > git remote add mislav git://github.com/mislav/REPO.git
140
+ # > git fetch mislav
141
+ #
142
+ # $ hub fetch --multiple mislav xoebus
143
+ # > git remote add mislav ...
144
+ # > git remote add xoebus ...
145
+ # > git fetch --multiple mislav xoebus
146
+ def fetch(args)
147
+ # $ hub fetch --multiple <name1>, <name2>, ...
148
+ if args.include?('--multiple')
149
+ names = args.words[1..-1]
150
+ # $ hub fetch <name>
151
+ elsif name = args.words[1]
152
+ # $ hub fetch <name1>,<name2>,...
153
+ if name =~ /^\w+(,\w+)+$/
154
+ index = args.index(name)
155
+ args.delete(name)
156
+ names = name.split(',')
157
+ args.insert(index, *names)
158
+ args.insert(index, '--multiple')
159
+ else
160
+ names = [name]
161
+ end
162
+ else
163
+ names = []
164
+ end
165
+
166
+ names.reject! { |name|
167
+ name =~ /\W/ or remotes.include?(name) or
168
+ remotes_group(name) or not repo_exists?(name)
169
+ }
170
+
171
+ if names.any?
172
+ commands = names.map { |name| "git remote add #{name} #{github_url(:user => name)}" }
173
+ commands << args.to_exec.join(' ')
174
+ args.replace commands.shift.split(' ')
175
+ args.shift # don't want "git"
176
+ args.after commands.join('; ')
177
+ end
178
+ end
179
+
180
+ # $ git cherry-pick http://github.com/mislav/hub/commit/a319d88#comments
181
+ # > git remote add -f mislav git://github.com/mislav/hub.git
182
+ # > git cherry-pick a319d88
183
+ #
184
+ # $ git cherry-pick mislav@a319d88
185
+ # > git remote add -f mislav git://github.com/mislav/hub.git
186
+ # > git cherry-pick a319d88
187
+ #
188
+ # $ git cherry-pick mislav@SHA
189
+ # > git fetch mislav
190
+ # > git cherry-pick SHA
191
+ def cherry_pick(args)
192
+ unless args.include?('-m') or args.include?('--mainline')
193
+ case ref = args.words.last
194
+ when %r{^(https?:)//github.com/(.+?)/(.+?)/commit/([a-f1-9]{7,40})}
195
+ scheme, user, repo, sha = $1, $2, $3, $4
196
+ args[args.index(ref)] = sha
197
+ when /^(\w+)@([a-f1-9]{7,40})$/
198
+ scheme, user, repo, sha = nil, $1, nil, $2
199
+ args[args.index(ref)] = sha
200
+ else
201
+ user = nil
202
+ end
203
+
204
+ if user
205
+ # cherry-pick comes after the fetch
206
+ args.after args.to_exec.join(' ')
207
+
208
+ if user == repo_owner
209
+ # fetch from origin if the repo belongs to the user
210
+ args.replace ['fetch', default_remote]
211
+ elsif remotes.include?(user)
212
+ args.replace ['fetch', user]
213
+ else
214
+ secure = scheme == 'https:'
215
+ remote_url = github_url(:user => user, :repo => repo, :private => secure)
216
+ args.replace ['remote', 'add', '-f', user, remote_url]
217
+ end
218
+ end
219
+ end
220
+ end
221
+
138
222
  # $ hub init -g
139
223
  # > git init
140
224
  # > git remote add origin git@github.com:USER/REPO.git
@@ -151,11 +235,9 @@ module Hub
151
235
  # ... hardcore forking action ...
152
236
  # > git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
153
237
  def fork(args)
154
- require 'net/http'
155
-
156
238
  # can't do anything without token and original owner name
157
239
  if github_user && github_token && repo_owner
158
- if own_repo_exists?
240
+ if repo_exists?(github_user)
159
241
  puts "#{github_user}/#{repo_name} already exists on GitHub"
160
242
  else
161
243
  fork_repo
@@ -530,12 +612,10 @@ help
530
612
  end
531
613
  end
532
614
 
533
- # Determines whether the current user (you) has a fork of the
534
- # current repo on GitHub.
535
- #
536
- # Returns a Boolean.
537
- def own_repo_exists?
538
- url = API_REPO % [github_user, repo_name]
615
+ # Determines whether a user has a fork of the current repo on GitHub.
616
+ def repo_exists?(user)
617
+ require 'net/http'
618
+ url = API_REPO % [user, repo_name]
539
619
  Net::HTTPSuccess === Net::HTTP.get_response(URI(url))
540
620
  end
541
621
 
data/lib/hub/context.rb CHANGED
@@ -60,12 +60,22 @@ module Hub
60
60
  normalize_branch(branch) if branch
61
61
  end
62
62
 
63
+ def remotes
64
+ list = GIT_CONFIG['remote'].split("\n")
65
+ main = list.delete('origin') and list.unshift(main)
66
+ list
67
+ end
68
+
69
+ def remotes_group(name)
70
+ GIT_CONFIG["config remotes.#{name}"]
71
+ end
72
+
63
73
  def current_remote
64
74
  (current_branch && remote_for(current_branch)) || default_remote
65
75
  end
66
76
 
67
77
  def default_remote
68
- 'origin'
78
+ remotes.first
69
79
  end
70
80
 
71
81
  def normalize_branch(branch)
data/lib/hub/runner.rb CHANGED
@@ -13,9 +13,9 @@ module Hub
13
13
  # Hack to emulate git-style
14
14
  @args.unshift 'help' if @args.grep(/^[^-]|version/).empty?
15
15
 
16
- if Commands.respond_to?(@args[0])
17
- Commands.send(@args[0], @args)
18
- end
16
+ # git commands can have dashes
17
+ cmd = @args[0].sub(/(\w)-/, '\1_')
18
+ Commands.send(cmd, @args) if Commands.respond_to?(cmd)
19
19
  end
20
20
 
21
21
  # Shortcut
data/lib/hub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hub
2
- Version = VERSION = '1.3.0'
2
+ Version = VERSION = '1.3.1'
3
3
  end
data/man/hub.1 CHANGED
@@ -22,6 +22,12 @@
22
22
  \fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[/\fIREPOSITORY\fR]
23
23
  .
24
24
  .br
25
+ \fBgit fetch\fR \fIUSER\-1\fR,[\fIUSER\-2\fR,...]
26
+ .
27
+ .br
28
+ \fBgit cherry\-pick\fR \fIGITHUB\-REF\fR
29
+ .
30
+ .br
25
31
  \fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,...,\fIREMOTE\-N\fR \fIREF\fR
26
32
  .
27
33
  .br
@@ -68,6 +74,18 @@ current working directory is used. With \fB\-p\fR, use private remote
68
74
  then uses your GitHub login.
69
75
  .
70
76
  .TP
77
+ \fBgit fetch\fR \fIUSER\-1\fR,[\fIUSER\-2\fR,...]
78
+ Adds missing remote(s) with \fBgit remote add\fR prior to fetching. New
79
+ remotes are only added if they correspond to valid forks on GitHub.
80
+ .
81
+ .TP
82
+ \fBgit cherry\-pick\fR \fIGITHUB\-REF\fR
83
+ Cherry\-pick a commit from a fork using either full URL to the commit
84
+ or GitHub\-flavored Markdown notation, which is \fBuser@sha\fR. If the remote
85
+ doesn't yet exist, it will be added. A \fBgit fetch <user>\fR is issued
86
+ prior to the cherry\-pick attempt.
87
+ .
88
+ .TP
71
89
  \fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,...,\fIREMOTE\-N\fR \fIREF\fR
72
90
  Push \fIREF\fR to each of \fIREMOTE\-1\fR through \fIREMOTE\-N\fR by executing
73
91
  multiple \fBgit push\fR commands.
@@ -183,6 +201,39 @@ $ git remote add origin
183
201
  .
184
202
  .fi
185
203
  .
204
+ .SS "git fetch"
205
+ .
206
+ .nf
207
+
208
+ $ git fetch mislav
209
+ > git remote add mislav git://github.com/mislav/REPO.git
210
+ > git fetch mislav
211
+
212
+ $ git fetch mislav,xoebus
213
+ > git remote add mislav ...
214
+ > git remote add xoebus ...
215
+ > git fetch \-\-multiple mislav xoebus
216
+ .
217
+ .fi
218
+ .
219
+ .SS "git cherry\-pick"
220
+ .
221
+ .nf
222
+
223
+ $ git cherry\-pick http://github.com/mislav/REPO/commit/SHA
224
+ > git remote add \-f mislav git://github.com/mislav/REPO.git
225
+ > git cherry\-pick SHA
226
+
227
+ $ git cherry\-pick mislav@SHA
228
+ > git remote add \-f mislav git://github.com/mislav/CURRENT_REPO.git
229
+ > git cherry\-pick SHA
230
+
231
+ $ git cherry\-pick mislav@SHA
232
+ > git fetch mislav
233
+ > git cherry\-pick SHA
234
+ .
235
+ .fi
236
+ .
186
237
  .SS "git fork"
187
238
  .
188
239
  .nf
data/man/hub.1.html CHANGED
@@ -73,6 +73,8 @@
73
73
  <p><code>git init -g</code> <var>OPTIONS</var><br />
74
74
  <code>git clone</code> [<code>-p</code>] <var>OPTIONS</var> [<var>USER</var>/]<var>REPOSITORY</var> <var>DIRECTORY</var><br />
75
75
  <code>git remote add</code> [<code>-p</code>] <var>OPTIONS</var> <var>USER</var>[/<var>REPOSITORY</var>]<br />
76
+ <code>git fetch</code> <var>USER-1</var>,[<var>USER-2</var>,...]<br />
77
+ <code>git cherry-pick</code> <var>GITHUB-REF</var><br />
76
78
  <code>git push</code> <var>REMOTE-1</var>,<var>REMOTE-2</var>,...,<var>REMOTE-N</var> <var>REF</var><br />
77
79
  <code>git browse</code> [<code>-p</code>] [<code>-u</code>] [[<var>USER</var><code>/</code>]<var>REPOSITORY</var>] [SUBPAGE]<br />
78
80
  <code>git compare</code> [<code>-p</code>] [<code>-u</code>] [<var>USER</var>] [<var>START</var>...]<var>END</var><br />
@@ -101,6 +103,12 @@ git-remote(1). When /<var>REPOSITORY</var> is omitted, the basename of the
101
103
  current working directory is used. With <code>-p</code>, use private remote
102
104
  "git@github.com:<var>USER</var>/<var>REPOSITORY</var>.git". If <var>USER</var> is "origin"
103
105
  then uses your GitHub login.</p></dd>
106
+ <dt><code>git fetch</code> <var>USER-1</var>,[<var>USER-2</var>,...]</dt><dd><p>Adds missing remote(s) with <code>git remote add</code> prior to fetching. New
107
+ remotes are only added if they correspond to valid forks on GitHub.</p></dd>
108
+ <dt><code>git cherry-pick</code> <var>GITHUB-REF</var></dt><dd><p>Cherry-pick a commit from a fork using either full URL to the commit
109
+ or GitHub-flavored Markdown notation, which is <code>user@sha</code>. If the remote
110
+ doesn't yet exist, it will be added. A <code>git fetch &lt;user></code> is issued
111
+ prior to the cherry-pick attempt.</p></dd>
104
112
  <dt><code>git push</code> <var>REMOTE-1</var>,<var>REMOTE-2</var>,...,<var>REMOTE-N</var> <var>REF</var></dt><dd><p>Push <var>REF</var> to each of <var>REMOTE-1</var> through <var>REMOTE-N</var> by executing
105
113
  multiple <code>git push</code> commands.</p></dd>
106
114
  <dt><code>git browse</code> [<code>-p</code>] [<code>-u</code>] [[<var>USER</var><code>/</code>]<var>REPOSITORY</var>] [SUBPAGE]</dt><dd><p>Open repository's GitHub page in the system's default web browser
@@ -175,6 +183,33 @@ $ git remote add origin
175
183
  &gt; git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
176
184
  </code></pre>
177
185
 
186
+ <h3>git fetch</h3>
187
+
188
+ <pre><code>$ git fetch mislav
189
+ &gt; git remote add mislav git://github.com/mislav/REPO.git
190
+ &gt; git fetch mislav
191
+
192
+ $ git fetch mislav,xoebus
193
+ &gt; git remote add mislav ...
194
+ &gt; git remote add xoebus ...
195
+ &gt; git fetch --multiple mislav xoebus
196
+ </code></pre>
197
+
198
+ <h3>git cherry-pick</h3>
199
+
200
+ <pre><code>$ git cherry-pick http://github.com/mislav/REPO/commit/SHA
201
+ &gt; git remote add -f mislav git://github.com/mislav/REPO.git
202
+ &gt; git cherry-pick SHA
203
+
204
+ $ git cherry-pick mislav@SHA
205
+ &gt; git remote add -f mislav git://github.com/mislav/CURRENT_REPO.git
206
+ &gt; git cherry-pick SHA
207
+
208
+ $ git cherry-pick mislav@SHA
209
+ &gt; git fetch mislav
210
+ &gt; git cherry-pick SHA
211
+ </code></pre>
212
+
178
213
  <h3>git fork</h3>
179
214
 
180
215
  <pre><code>$ git fork
data/man/hub.1.ronn CHANGED
@@ -9,6 +9,8 @@ hub(1) -- git + hub = github
9
9
  `git init -g` <OPTIONS>
10
10
  `git clone` [`-p`] <OPTIONS> [<USER>/]<REPOSITORY> <DIRECTORY>
11
11
  `git remote add` [`-p`] <OPTIONS> <USER>[/<REPOSITORY>]
12
+ `git fetch` <USER-1>,[<USER-2>,...]
13
+ `git cherry-pick` <GITHUB-REF>
12
14
  `git push` <REMOTE-1>,<REMOTE-2>,...,<REMOTE-N> <REF>
13
15
  `git browse` [`-p`] [`-u`] [[<USER>`/`]<REPOSITORY>] [SUBPAGE]
14
16
  `git compare` [`-p`] [`-u`] [<USER>] [<START>...]<END>
@@ -44,6 +46,16 @@ alias command displays information on configuring your environment:
44
46
  "git@github.com:<USER>/<REPOSITORY>.git". If <USER> is "origin"
45
47
  then uses your GitHub login.
46
48
 
49
+ * `git fetch` <USER-1>,[<USER-2>,...]:
50
+ Adds missing remote(s) with `git remote add` prior to fetching. New
51
+ remotes are only added if they correspond to valid forks on GitHub.
52
+
53
+ * `git cherry-pick` <GITHUB-REF>:
54
+ Cherry-pick a commit from a fork using either full URL to the commit
55
+ or GitHub-flavored Markdown notation, which is `user@sha`. If the remote
56
+ doesn't yet exist, it will be added. A `git fetch <user>` is issued
57
+ prior to the cherry-pick attempt.
58
+
47
59
  * `git push` <REMOTE-1>,<REMOTE-2>,...,<REMOTE-N> <REF>:
48
60
  Push <REF> to each of <REMOTE-1> through <REMOTE-N> by executing
49
61
  multiple `git push` commands.
@@ -122,6 +134,31 @@ cloning:
122
134
  $ git remote add origin
123
135
  > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
124
136
 
137
+ ### git fetch
138
+
139
+ $ git fetch mislav
140
+ > git remote add mislav git://github.com/mislav/REPO.git
141
+ > git fetch mislav
142
+
143
+ $ git fetch mislav,xoebus
144
+ > git remote add mislav ...
145
+ > git remote add xoebus ...
146
+ > git fetch --multiple mislav xoebus
147
+
148
+ ### git cherry-pick
149
+
150
+ $ git cherry-pick http://github.com/mislav/REPO/commit/SHA
151
+ > git remote add -f mislav git://github.com/mislav/REPO.git
152
+ > git cherry-pick SHA
153
+
154
+ $ git cherry-pick mislav@SHA
155
+ > git remote add -f mislav git://github.com/mislav/CURRENT_REPO.git
156
+ > git cherry-pick SHA
157
+
158
+ $ git cherry-pick mislav@SHA
159
+ > git fetch mislav
160
+ > git cherry-pick SHA
161
+
125
162
  ### git fork
126
163
 
127
164
  $ git fork
data/test/helper.rb CHANGED
@@ -88,11 +88,13 @@ class Test::Unit::TestCase
88
88
 
89
89
  # Asserts that `haystack` includes `needle`.
90
90
  def assert_includes(needle, haystack)
91
- assert haystack.include?(needle)
91
+ assert haystack.include?(needle),
92
+ "expected #{needle.inspect} in #{haystack.inspect}"
92
93
  end
93
94
 
94
95
  # Asserts that `haystack` does not include `needle`.
95
96
  def assert_not_includes(needle, haystack)
96
- assert !haystack.include?(needle)
97
+ assert !haystack.include?(needle),
98
+ "didn't expect #{needle.inspect} in #{haystack.inspect}"
97
99
  end
98
100
  end
data/test/hub_test.rb CHANGED
@@ -20,6 +20,7 @@ class HubTest < Test::Unit::TestCase
20
20
  @git = Hub::Context::GIT_CONFIG.replace(Hash.new { |h, k|
21
21
  raise ArgumentError, "`git #{k}` not stubbed"
22
22
  }).update(
23
+ 'remote' => "mislav\norigin",
23
24
  'symbolic-ref -q HEAD' => 'refs/heads/master',
24
25
  'config github.user' => 'tpw',
25
26
  'config github.token' => 'abc123',
@@ -217,6 +218,134 @@ class HubTest < Test::Unit::TestCase
217
218
  assert_command input, command
218
219
  end
219
220
 
221
+ def test_fetch_existing_remote
222
+ assert_command "fetch mislav", "git fetch mislav"
223
+ end
224
+
225
+ def test_fetch_new_remote
226
+ stub_remotes_group('xoebus', nil)
227
+ stub_existing_fork('xoebus')
228
+
229
+ h = Hub("fetch xoebus")
230
+ assert_equal "git remote add xoebus git://github.com/xoebus/hub.git", h.command
231
+ assert_equal "git fetch xoebus", h.after
232
+ end
233
+
234
+ def test_fetch_new_remote_with_options
235
+ stub_remotes_group('xoebus', nil)
236
+ stub_existing_fork('xoebus')
237
+
238
+ h = Hub("fetch --depth=1 --prune xoebus")
239
+ assert_equal "git remote add xoebus git://github.com/xoebus/hub.git", h.command
240
+ assert_equal "git fetch --depth=1 --prune xoebus", h.after
241
+ end
242
+
243
+ def test_fetch_multiple_new_remotes
244
+ stub_remotes_group('xoebus', nil)
245
+ stub_remotes_group('rtomayko', nil)
246
+ stub_existing_fork('xoebus')
247
+ stub_existing_fork('rtomayko')
248
+
249
+ h = Hub("fetch --multiple xoebus rtomayko")
250
+
251
+ assert_equal "git remote add xoebus git://github.com/xoebus/hub.git", h.command
252
+ expected = ["git remote add rtomayko git://github.com/rtomayko/hub.git"] <<
253
+ "git fetch --multiple xoebus rtomayko"
254
+ assert_equal expected.join('; '), h.after
255
+ end
256
+
257
+ def test_fetch_multiple_comma_separated_remotes
258
+ stub_remotes_group('xoebus', nil)
259
+ stub_remotes_group('rtomayko', nil)
260
+ stub_existing_fork('xoebus')
261
+ stub_existing_fork('rtomayko')
262
+
263
+ h = Hub("fetch xoebus,rtomayko")
264
+
265
+ assert_equal "git remote add xoebus git://github.com/xoebus/hub.git", h.command
266
+ expected = ["git remote add rtomayko git://github.com/rtomayko/hub.git"] <<
267
+ "git fetch --multiple xoebus rtomayko"
268
+ assert_equal expected.join('; '), h.after
269
+ end
270
+
271
+ def test_fetch_multiple_new_remotes_with_filtering
272
+ stub_remotes_group('xoebus', nil)
273
+ stub_remotes_group('mygrp', 'one two')
274
+ stub_remotes_group('typo', nil)
275
+ stub_existing_fork('xoebus')
276
+ stub_nonexisting_fork('typo')
277
+
278
+ # mislav: existing remote; skipped
279
+ # xoebus: new remote, fork exists; added
280
+ # mygrp: a remotes group; skipped
281
+ # URL: can't be a username; skipped
282
+ # typo: fork doesn't exist; skipped
283
+ h = Hub("fetch --multiple mislav xoebus mygrp git://example.com typo")
284
+
285
+ assert_equal "git remote add xoebus git://github.com/xoebus/hub.git", h.command
286
+ expected = "git fetch --multiple mislav xoebus mygrp git://example.com typo"
287
+ assert_equal expected, h.after
288
+ end
289
+
290
+ def test_cherry_pick
291
+ h = Hub("cherry-pick a319d88")
292
+ assert_equal "git cherry-pick a319d88", h.command
293
+ assert !h.args.after?
294
+ end
295
+
296
+ def test_cherry_pick_url
297
+ url = 'http://github.com/mislav/hub/commit/a319d88#comments'
298
+ h = Hub("cherry-pick #{url}")
299
+ assert_equal "git fetch mislav", h.command
300
+ assert_equal "git cherry-pick a319d88", h.after
301
+ end
302
+
303
+ def test_cherry_pick_url_with_remote_add
304
+ url = 'http://github.com/xoebus/hub/commit/a319d88'
305
+ h = Hub("cherry-pick #{url}")
306
+ assert_equal "git remote add -f xoebus git://github.com/xoebus/hub.git", h.command
307
+ assert_equal "git cherry-pick a319d88", h.after
308
+ end
309
+
310
+ def test_cherry_pick_private_url_with_remote_add
311
+ url = 'https://github.com/xoebus/hub/commit/a319d88'
312
+ h = Hub("cherry-pick #{url}")
313
+ assert_equal "git remote add -f xoebus git@github.com:xoebus/hub.git", h.command
314
+ assert_equal "git cherry-pick a319d88", h.after
315
+ end
316
+
317
+ def test_cherry_pick_origin_url
318
+ url = 'https://github.com/defunkt/hub/commit/a319d88'
319
+ h = Hub("cherry-pick #{url}")
320
+ assert_equal "git fetch origin", h.command
321
+ assert_equal "git cherry-pick a319d88", h.after
322
+ end
323
+
324
+ def test_cherry_pick_github_user_notation
325
+ h = Hub("cherry-pick mislav@a319d88")
326
+ assert_equal "git fetch mislav", h.command
327
+ assert_equal "git cherry-pick a319d88", h.after
328
+ end
329
+
330
+ def test_cherry_pick_github_user_repo_notation
331
+ # not supported
332
+ h = Hub("cherry-pick mislav/hubbub@a319d88")
333
+ assert_equal "git cherry-pick mislav/hubbub@a319d88", h.command
334
+ assert !h.args.after?
335
+ end
336
+
337
+ def test_cherry_pick_github_notation_too_short
338
+ h = Hub("cherry-pick mislav@a319")
339
+ assert_equal "git cherry-pick mislav@a319", h.command
340
+ assert !h.args.after?
341
+ end
342
+
343
+ def test_cherry_pick_github_notation_with_remote_add
344
+ h = Hub("cherry-pick xoebus@a319d88")
345
+ assert_equal "git remote add -f xoebus git://github.com/xoebus/hub.git", h.command
346
+ assert_equal "git cherry-pick a319d88", h.after
347
+ end
348
+
220
349
  def test_init
221
350
  h = Hub("init -g")
222
351
  assert_equal "git init", h.command
@@ -244,8 +373,7 @@ class HubTest < Test::Unit::TestCase
244
373
  end
245
374
 
246
375
  def test_fork
247
- stub_request(:get, "github.com/api/v2/yaml/repos/show/tpw/hub").
248
- to_return(:status => 404)
376
+ stub_nonexisting_fork('tpw')
249
377
  stub_request(:post, "github.com/api/v2/yaml/repos/fork/defunkt/hub").with { |req|
250
378
  params = Hash[*req.body.split(/[&=]/)]
251
379
  params == { 'login'=>'tpw', 'token'=>'abc123' }
@@ -257,16 +385,14 @@ class HubTest < Test::Unit::TestCase
257
385
  end
258
386
 
259
387
  def test_fork_no_remote
260
- stub_request(:get, "github.com/api/v2/yaml/repos/show/tpw/hub").
261
- to_return(:status => 404)
388
+ stub_nonexisting_fork('tpw')
262
389
  stub_request(:post, "github.com/api/v2/yaml/repos/fork/defunkt/hub")
263
390
 
264
391
  assert_equal "", hub("fork --no-remote") { ENV['GIT'] = 'echo' }
265
392
  end
266
393
 
267
394
  def test_fork_already_exists
268
- stub_request(:get, "github.com/api/v2/yaml/repos/show/tpw/hub").
269
- to_return(:status => 200)
395
+ stub_existing_fork('tpw')
270
396
 
271
397
  expected = "tpw/hub already exists on GitHub\n"
272
398
  expected << "remote add -f tpw git@github.com:tpw/hub.git\n"
@@ -479,6 +605,23 @@ config
479
605
  @git['config branch.master.merge'] = nil
480
606
  end
481
607
 
608
+ def stub_remotes_group(name, value)
609
+ @git["config remotes.#{name}"] = value
610
+ end
611
+
612
+ def stub_existing_fork(user)
613
+ stub_fork(user, 200)
614
+ end
615
+
616
+ def stub_nonexisting_fork(user)
617
+ stub_fork(user, 404)
618
+ end
619
+
620
+ def stub_fork(user, status)
621
+ stub_request(:get, "github.com/api/v2/yaml/repos/show/#{user}/hub").
622
+ to_return(:status => status)
623
+ end
624
+
482
625
  def stub_available_commands(*names)
483
626
  COMMANDS.replace names
484
627
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 0
9
- version: 1.3.0
8
+ - 1
9
+ version: 1.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Wanstrath