git-hub 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTORS CHANGED
@@ -1,5 +1,7 @@
1
1
  * Chris Wanstrath
2
2
  * Stephen Celis
3
+ * Rob Ares
4
+ * Mislav Marohnić
3
5
  * Ryan Tomayko
4
6
  * Caio Chassot
5
7
  * Joshua Peek
data/HISTORY.md CHANGED
@@ -1,6 +1,9 @@
1
- ## 1.0.0 (2010-??-??)
1
+ ## 1.0.0 (2010-03-03)
2
2
 
3
- *
3
+ * `hub browse` with no arguments uses the current repo.
4
+ * `hub submodule add user/repo directory
5
+ * `hub remote add rtomayko/tilt`
6
+ * `remote add -p origin rtomayko/tilt`
4
7
 
5
8
  ## 0.3.2 (2010-02-17)
6
9
 
data/README.md CHANGED
@@ -146,6 +146,9 @@ superpowers:
146
146
 
147
147
  ### git browse
148
148
 
149
+ $ git browse
150
+ > open http://github.com/CURRENT_REPO
151
+
149
152
  $ git browse schacon/ticgit
150
153
  > open http://github.com/schacon/ticgit
151
154
 
data/lib/hub/args.rb CHANGED
@@ -6,6 +6,14 @@ module Hub
6
6
  # The ARGV array is converted into an Args instance by the Hub
7
7
  # instance when instantiated.
8
8
  class Args < Array
9
+ attr_accessor :executable
10
+
11
+ def initialize(*args)
12
+ super
13
+ @executable = ENV["GIT"] || "git"
14
+ @after = nil
15
+ end
16
+
9
17
  # With no arguments, returns the `after` callback.
10
18
  #
11
19
  # With a single argument, sets the `after` callback.
@@ -31,5 +39,11 @@ module Hub
31
39
  def after?
32
40
  !!@after
33
41
  end
42
+
43
+ # Array of `executable` followed by all args suitable as arguments
44
+ # for `exec` or `system` calls.
45
+ def to_exec
46
+ [executable].concat self
47
+ end
34
48
  end
35
49
  end
data/lib/hub/commands.rb CHANGED
@@ -42,9 +42,10 @@ module Hub
42
42
  # Set the repo name based on the current origin or, as a fallback,
43
43
  # the cwd.
44
44
  if ORIGIN =~ %r{\bgithub\.com[:/](.+)/(.+).git$}
45
- REPO = $2
45
+ OWNER, REPO = $1, $2
46
46
  else
47
47
  REPO = File.basename(Dir.pwd)
48
+ OWNER = ''
48
49
  end
49
50
 
50
51
  # $ hub clone rtomayko/tilt
@@ -86,6 +87,18 @@ module Hub
86
87
  end
87
88
  end
88
89
 
90
+ # $ hub submodule add wycats/bundler vendor/bundler
91
+ # > git submodule add git://github.com/wycats/bundler.git vendor/bundler
92
+ #
93
+ # $ hub submodule add -p wycats/bundler vendor/bundler
94
+ # > git submodule add git@github.com:wycats/bundler.git vendor/bundler
95
+ def submodule(args)
96
+ return unless index = args.index('add')
97
+ args.delete_at index
98
+ clone(args)
99
+ args.insert index, 'add'
100
+ end
101
+
89
102
  # $ hub remote add pjhyett
90
103
  # > git remote add pjhyett git://github.com/pjhyett/THIS_REPO.git
91
104
  #
@@ -97,15 +110,39 @@ module Hub
97
110
  def remote(args)
98
111
  return unless args[1] == 'add'
99
112
 
100
- # Assume GitHub usernames don't ever contain : or /, while URLs
101
- # do.
102
- if args[-1] !~ /:|\//
103
- ssh = args.delete('-p')
104
- user = args.last
105
- url = ssh ? PRIVATE : PUBLIC
113
+ ssh = args.delete('-p')
114
+ url = ssh ? PRIVATE : PUBLIC
115
+
116
+ if args.last =~ /\b(\w+)\/(\w+)/
117
+ # user/repo
118
+ user, repo = $1, $2
119
+
120
+ if args[-2] == args[1]
121
+ # rtomayko/tilt => rtomayko
122
+ args[-1] = user
123
+ else
124
+ # They're specifying the remote name manually (e.g.
125
+ # git remote add blah rtomayko/tilt), so just drop the last
126
+ # argument.
127
+ args.replace args[0...-1]
128
+ end
106
129
 
107
- # Origin special case.
108
- user = github_user if args[2] == 'origin'
130
+ args << url % [ user, repo ]
131
+ elsif args.last !~ /:|\//
132
+ if args[2] == 'origin' && args[3].nil?
133
+ # Origin special case.
134
+ user = github_user
135
+ else
136
+ # Assume no : or / means GitHub user.
137
+ user = args.last
138
+ end
139
+
140
+ if args[-2] != args[1]
141
+ # They're specifying the remote name manually (e.g.
142
+ # git remote add blah rtomayko), so just drop the last
143
+ # argument.
144
+ args.replace args[0...-1]
145
+ end
109
146
 
110
147
  args << url % [ user, REPO ]
111
148
  end
@@ -142,6 +179,9 @@ module Hub
142
179
  args.after after
143
180
  end
144
181
 
182
+ # $ hub browse
183
+ # > open http://github.com/CURRENT_REPO
184
+ #
145
185
  # $ hub browse pjhyett/github-services
146
186
  # > open http://github.com/pjhyett/github-services
147
187
  #
@@ -154,19 +194,28 @@ module Hub
154
194
  # $ hub browse -p github-fi
155
195
  # > open https://github.com/YOUR_LOGIN/github-fi
156
196
  def browse(args)
197
+ args.shift
157
198
  protocol = args.delete('-p') ? 'https' : 'http'
158
-
159
- if args.last.include? '/'
160
- # $ hub browse pjhyett/github-services
161
- user, repo = args.last.split('/')
199
+ dest = args.pop
200
+
201
+ if dest
202
+ if dest.include? '/'
203
+ # $ hub browse pjhyett/github-services
204
+ user, repo = dest.split('/')
205
+ else
206
+ # $ hub browse github-services
207
+ user, repo = github_user, dest
208
+ end
209
+ elsif !OWNER.empty?
210
+ # $ hub browse
211
+ user, repo = OWNER, REPO
162
212
  else
163
- # $ hub browse github-services
164
- user = github_user
165
- repo = args.last
213
+ warn "Usage: hub browse [<USER>/]<REPOSITORY>"
214
+ exit(1)
166
215
  end
167
216
 
168
- browser = ENV['BROWSER'] || "open"
169
- exec "#{browser} #{protocol}://github.com/#{user}/#{repo}"
217
+ args.executable = ENV['BROWSER'] || 'open'
218
+ args.push "#{protocol}://github.com/#{user}/#{repo}"
170
219
  end
171
220
 
172
221
  # $ hub hub standalone
@@ -174,7 +223,7 @@ module Hub
174
223
  # installation sequence:
175
224
  #
176
225
  # $ gem install git-hub
177
- # $ hub standalone > ~/bin/standalone
226
+ # $ hub hub standalone > ~/bin/hub && chmod 755 ~/bin/hub
178
227
  # $ gem uninstall git-hub
179
228
  def hub(args)
180
229
  return help(args) unless args[1] == 'standalone'
data/lib/hub/runner.rb CHANGED
@@ -6,6 +6,7 @@ module Hub
6
6
  # augment a git command, is kept in the `Hub::Commands` module.
7
7
  class Runner
8
8
  attr_reader :args
9
+
9
10
  def initialize(*args)
10
11
  @args = Args.new(args)
11
12
 
@@ -34,7 +35,7 @@ module Hub
34
35
  # A string representation of the git command we would run if
35
36
  # #execute were called.
36
37
  def command
37
- "git #{args.join(' ')}"
38
+ args.to_exec.join(' ')
38
39
  end
39
40
 
40
41
  # Runs the target git command with an optional callback. Replaces
@@ -43,7 +44,7 @@ module Hub
43
44
  if args.after?
44
45
  execute_with_after_callback
45
46
  else
46
- exec "git", *args
47
+ exec(*args.to_exec)
47
48
  end
48
49
  end
49
50
 
@@ -53,7 +54,7 @@ module Hub
53
54
  # callback.
54
55
  def execute_with_after_callback
55
56
  after = args.after
56
- if system("git", *args)
57
+ if system(*args.to_exec)
57
58
  after.respond_to?(:call) ? after.call : exec(after)
58
59
  exit
59
60
  else
data/lib/hub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hub
2
- Version = '0.3.2'
2
+ Version = '1.0.0'
3
3
  end
data/man/hub.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ron/v0.3
2
2
  .\" http://github.com/rtomayko/ron/
3
3
  .
4
- .TH "HUB" "1" "February 2010" "DEFUNKT" "Git Manual"
4
+ .TH "HUB" "1" "March 2010" "DEFUNKT" "Git Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBhub\fR \-\- git + hub = github
@@ -27,6 +27,7 @@
27
27
  \fBgit browse\fR [\fB\-p\fR] [\fIUSER\fR/]\fIREPOSITORY\fR
28
28
  .
29
29
  .br
30
+ \fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
30
31
  .
31
32
  .SH "DESCRIPTION"
32
33
  \fBhub\fR enhances various \fBgit\fR commands with GitHub remote expansion. The
@@ -65,10 +66,17 @@ Push \fIREF\fR to each of \fIREMOTE\-1\fR through \fIREMOTE\-N\fR by executing
65
66
  multiple \fBgit push\fR commands.
66
67
  .
67
68
  .TP
68
- \fBgit browse\fR [\fB\-p\fR] [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR
69
+ \fBgit browse\fR [\fB\-p\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR]
69
70
  Open repository's GitHub page in the system's default web browser
70
71
  using \fBopen(1)\fR or the \fBBROWSER\fR env variable. Use \fB\-p\fR to open a
71
- page with https.
72
+ page with https. If the repository isn't specified, \fBbrowse\fR opens
73
+ the page of the repository found in the current directory.
74
+ .
75
+ .TP
76
+ \fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
77
+ Submodule repository "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" into \fIDIRECTORY\fR as with git\-submodule(1). When \fIUSER\fR/ is omitted, assumes
78
+ your GitHub login. With \fB\-p\fR, use private remote
79
+ "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git".
72
80
  .
73
81
  .TP
74
82
  \fBgit help\fR
data/man/hub.1.html CHANGED
@@ -74,7 +74,7 @@
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
76
  <code>git browse</code> [<code>-p</code>] [<var>USER</var>/]<var>REPOSITORY</var> <br>
77
- </p>
77
+ <code>git submodule add</code> [<code>-p</code>] <var>OPTIONS</var> [<var>USER</var>/]<var>REPOSITORY</var> <var>DIRECTORY</var></p>
78
78
 
79
79
  <h2>DESCRIPTION</h2>
80
80
 
@@ -122,11 +122,18 @@ then uses your GitHub login.</p></dd>
122
122
  <dd><p>Push <var>REF</var> to each of <var>REMOTE-1</var> through <var>REMOTE-N</var> by executing
123
123
  multiple <code>git push</code> commands.</p></dd>
124
124
  <dt>
125
- <code>git browse</code> [<code>-p</code>] [<var>USER</var><code>/</code>]<var>REPOSITORY</var>
126
- </dt>
125
+ <code>git browse</code> [<code>-p</code>] [[<var>USER</var><code>/</code>]<var>REPOSITORY</var>]</dt>
127
126
  <dd><p>Open repository's GitHub page in the system's default web browser
128
127
  using <code>open(1)</code> or the <code>BROWSER</code> env variable. Use <code>-p</code> to open a
129
- page with https.</p></dd>
128
+ page with https. If the repository isn't specified, <code>browse</code> opens
129
+ the page of the repository found in the current directory.</p></dd>
130
+ <dt>
131
+ <code>git submodule add</code> [<code>-p</code>] <var>OPTIONS</var> [<var>USER</var>/]<var>REPOSITORY</var> <var>DIRECTORY</var>
132
+ </dt>
133
+ <dd><p>Submodule repository "git://github.com/<var>USER</var>/<var>REPOSITORY</var>.git" into
134
+ <var>DIRECTORY</var> as with git-submodule(1). When <var>USER</var>/ is omitted, assumes
135
+ your GitHub login. With <code>-p</code>, use private remote
136
+ "git@github.com:<var>USER</var>/<var>REPOSITORY</var>.git".</p></dd>
130
137
  <dt><code>git help</code></dt>
131
138
  <dd><p>Display enhanced git-help(1).</p></dd>
132
139
  </dl>
@@ -236,7 +243,7 @@ $ git help hub
236
243
 
237
244
  <ol class='foot man'>
238
245
  <li class='tl'>DEFUNKT</li>
239
- <li class='tc'>February 2010</li>
246
+ <li class='tc'>March 2010</li>
240
247
  <li class='tr'>hub(1)</li>
241
248
  </ol>
242
249
 
data/man/hub.1.ron CHANGED
@@ -10,6 +10,7 @@ hub(1) -- git + hub = github
10
10
  `git clone` [`-p`] <OPTIONS> [<USER>/]<REPOSITORY> <DIRECTORY>
11
11
  `git remote add` [`-p`] <OPTIONS> <USER>[/<REPOSITORY>]
12
12
  `git browse` [`-p`] [<USER>/]<REPOSITORY>
13
+ `git submodule add` [`-p`] <OPTIONS> [<USER>/]<REPOSITORY> <DIRECTORY>
13
14
 
14
15
  ## DESCRIPTION
15
16
 
@@ -46,10 +47,17 @@ After configuring the alias, the following commands have superpowers:
46
47
  Push <REF> to each of <REMOTE-1> through <REMOTE-N> by executing
47
48
  multiple `git push` commands.
48
49
 
49
- * `git browse` [`-p`] [<USER>`/`]<REPOSITORY>:
50
+ * `git browse` [`-p`] [[<USER>`/`]<REPOSITORY>]:
50
51
  Open repository's GitHub page in the system's default web browser
51
52
  using `open(1)` or the `BROWSER` env variable. Use `-p` to open a
52
- page with https.
53
+ page with https. If the repository isn't specified, `browse` opens
54
+ the page of the repository found in the current directory.
55
+
56
+ * `git submodule add` [`-p`] <OPTIONS> [<USER>/]<REPOSITORY> <DIRECTORY>:
57
+ Submodule repository "git://github.com/<USER>/<REPOSITORY>.git" into
58
+ <DIRECTORY> as with git-submodule(1). When <USER>/ is omitted, assumes
59
+ your GitHub login. With `-p`, use private remote
60
+ "git@github.com:<USER>/<REPOSITORY>.git".
53
61
 
54
62
  * `git help`:
55
63
  Display enhanced git-help(1).
data/test/hub_test.rb CHANGED
@@ -3,7 +3,9 @@ require 'helper'
3
3
 
4
4
  class HubTest < Test::Unit::TestCase
5
5
  def setup
6
+ Hub::Commands::REPO.replace("hub")
6
7
  Hub::Commands::USER.replace("tpw")
8
+ Hub::Commands::OWNER.replace("defunkt")
7
9
  end
8
10
 
9
11
  def test_private_clone
@@ -88,6 +90,21 @@ class HubTest < Test::Unit::TestCase
88
90
  assert_command input, command
89
91
  end
90
92
 
93
+ def test_public_submodule
94
+ input = "submodule add wycats/bundler vendor/bundler"
95
+ command = "git submodule add git://github.com/wycats.bundler.git"
96
+ end
97
+
98
+ def test_private_submodule
99
+ input = "submodule add -p grit vendor/grit"
100
+ command = "git submodule add git@github.com:tpw/grit.git"
101
+ end
102
+
103
+ def test_submodule_with_args
104
+ input = "submodule -q add --bare -- grit grit"
105
+ command = "git submodule -q add --bare -- git://github.com/tpw/grit.git grit"
106
+ end
107
+
91
108
  def test_private_remote
92
109
  input = "remote add -p rtomayko"
93
110
  command = "git remote add rtomayko git@github.com:rtomayko/hub.git"
@@ -100,6 +117,30 @@ class HubTest < Test::Unit::TestCase
100
117
  assert_command input, command
101
118
  end
102
119
 
120
+ def test_named_public_remote
121
+ input = "remote add origin rtomayko"
122
+ command = "git remote add origin git://github.com/rtomayko/hub.git"
123
+ assert_command input, command
124
+ end
125
+
126
+ def test_private_remote_with_repo
127
+ input = "remote add -p rtomayko/tilt"
128
+ command = "git remote add rtomayko git@github.com:rtomayko/tilt.git"
129
+ assert_command input, command
130
+ end
131
+
132
+ def test_public_remote_with_repo
133
+ input = "remote add rtomayko/tilt"
134
+ command = "git remote add rtomayko git://github.com/rtomayko/tilt.git"
135
+ assert_command input, command
136
+ end
137
+
138
+ def test_named_private_remote_with_repo
139
+ input = "remote add -p origin rtomayko/tilt"
140
+ command = "git remote add origin git@github.com:rtomayko/tilt.git"
141
+ assert_command input, command
142
+ end
143
+
103
144
  def test_init
104
145
  h = Hub("init -g")
105
146
  assert_equal "git init", h.command
@@ -153,6 +194,7 @@ config
153
194
  def test_help_hub_no_groff
154
195
  help_manpage = hub("help hub") do
155
196
  Hub::Commands.class_eval do
197
+ remove_method :groff?
156
198
  def groff?; false end
157
199
  end
158
200
  end
@@ -165,26 +207,32 @@ config
165
207
  end
166
208
 
167
209
  def test_hub_open
168
- input = "browse mojombo/bert"
169
- command = "http://github.com/mojombo/bert\n"
170
- assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
210
+ assert_command "browse mojombo/bert", "open http://github.com/mojombo/bert"
171
211
  end
172
212
 
173
213
  def test_hub_open_private
174
- input = "browse -p bmizerany/sinatra"
175
- command = "https://github.com/bmizerany/sinatra\n"
176
- assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
214
+ assert_command "browse -p bmizerany/sinatra", "open https://github.com/bmizerany/sinatra"
177
215
  end
178
216
 
179
217
  def test_hub_open_self
180
- input = "browse resque"
181
- command = "http://github.com/tpw/resque\n"
182
- assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
218
+ assert_command "browse resque", "open http://github.com/tpw/resque"
183
219
  end
184
220
 
185
221
  def test_hub_open_self_private
186
- input = "browse -p github"
187
- command = "https://github.com/tpw/github\n"
188
- assert_equal command, hub(input) { ENV['BROWSER'] = 'echo' }
222
+ assert_command "browse -p github", "open https://github.com/tpw/github"
223
+ end
224
+
225
+ def test_hub_open_current
226
+ assert_command "browse", "open http://github.com/defunkt/hub"
227
+ end
228
+
229
+ def test_hub_open_current_private
230
+ assert_command "browse -p", "open https://github.com/defunkt/hub"
231
+ end
232
+
233
+ def test_hub_open_no_repo
234
+ Hub::Commands::OWNER.replace("")
235
+ input = "browse"
236
+ assert_equal "Usage: hub browse [<USER>/]<REPOSITORY>\n", hub(input)
189
237
  end
190
238
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-17 00:00:00 -08:00
12
+ date: 2010-03-03 00:00:00 -08:00
13
13
  default_executable: hub
14
14
  dependencies: []
15
15