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.
@@ -0,0 +1,112 @@
1
+ module Hub
2
+ # Provides methods for inspecting the environment, such as GitHub user/token
3
+ # settings, repository info, and similar.
4
+ module Context
5
+ # Caches output when shelling out to git
6
+ GIT_CONFIG = Hash.new do |cache, cmd|
7
+ result = %x{git #{cmd}}.chomp
8
+ cache[cmd] = $?.success? && !result.empty? ? result : nil
9
+ end
10
+
11
+ # Parses URLs for git remotes and stores info
12
+ REMOTES = Hash.new do |cache, remote|
13
+ url = GIT_CONFIG["config remote.#{remote}.url"]
14
+
15
+ if url && url.to_s =~ %r{\bgithub\.com[:/](.+)/(.+).git$}
16
+ cache[remote] = { :user => $1, :repo => $2 }
17
+ else
18
+ cache[remote] = { }
19
+ end
20
+ end
21
+
22
+ LGHCONF = "http://github.com/guides/local-github-config"
23
+
24
+ def repo_owner
25
+ REMOTES[default_remote][:user]
26
+ end
27
+
28
+ def repo_user
29
+ REMOTES[current_remote][:user]
30
+ end
31
+
32
+ def repo_name
33
+ REMOTES[default_remote][:repo] || File.basename(Dir.pwd)
34
+ end
35
+
36
+ # Either returns the GitHub user as set by git-config(1) or aborts
37
+ # with an error message.
38
+ def github_user(fatal = true)
39
+ if user = GIT_CONFIG['config github.user']
40
+ user
41
+ elsif fatal
42
+ abort("** No GitHub user set. See #{LGHCONF}")
43
+ end
44
+ end
45
+
46
+ def github_token(fatal = true)
47
+ if token = GIT_CONFIG['config github.token']
48
+ token
49
+ elsif fatal
50
+ abort("** No GitHub token set. See #{LGHCONF}")
51
+ end
52
+ end
53
+
54
+ def current_branch
55
+ GIT_CONFIG['symbolic-ref -q HEAD']
56
+ end
57
+
58
+ def tracked_branch
59
+ branch = current_branch && tracked_for(current_branch)
60
+ normalize_branch(branch) if branch
61
+ end
62
+
63
+ def current_remote
64
+ (current_branch && remote_for(current_branch)) || default_remote
65
+ end
66
+
67
+ def default_remote
68
+ 'origin'
69
+ end
70
+
71
+ def normalize_branch(branch)
72
+ branch.sub('refs/heads/', '')
73
+ end
74
+
75
+ def remote_for(branch)
76
+ GIT_CONFIG['config branch.%s.remote' % normalize_branch(branch)]
77
+ end
78
+
79
+ def tracked_for(branch)
80
+ GIT_CONFIG['config branch.%s.merge' % normalize_branch(branch)]
81
+ end
82
+
83
+ def http_clone?
84
+ GIT_CONFIG['config --bool hub.http-clone'] == 'true'
85
+ end
86
+
87
+ def github_url(options = {})
88
+ repo = options[:repo]
89
+ user, repo = repo.split('/') if repo && repo.index('/')
90
+ user ||= options[:user] || github_user
91
+ repo ||= repo_name
92
+ secure = options[:private]
93
+
94
+ if options[:web] == 'wiki'
95
+ scheme = secure ? 'https:' : 'http:'
96
+ '%s//wiki.github.com/%s/%s/' % [scheme, user, repo]
97
+ elsif options[:web]
98
+ scheme = secure ? 'https:' : 'http:'
99
+ path = options[:web] == true ? '' : options[:web].to_s
100
+ '%s//github.com/%s/%s%s' % [scheme, user, repo, path]
101
+ else
102
+ if secure
103
+ 'git@github.com:%s/%s.git'
104
+ elsif http_clone?
105
+ 'http://github.com/%s/%s.git'
106
+ else
107
+ 'git://github.com/%s/%s.git'
108
+ end % [user, repo]
109
+ end
110
+ end
111
+ end
112
+ end
data/lib/hub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hub
2
- Version = '1.1.0'
2
+ Version = VERSION = '1.3.0'
3
3
  end
data/lib/hub.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'hub/version'
2
2
  require 'hub/args'
3
+ require 'hub/context'
3
4
  require 'hub/commands'
4
5
  require 'hub/runner'
data/man/hub.1 CHANGED
@@ -1,5 +1,5 @@
1
- .\" generated with Ron/v0.3
2
- .\" http://github.com/rtomayko/ron/
1
+ .\" generated with Ronn/v0.5
2
+ .\" http://github.com/rtomayko/ronn/
3
3
  .
4
4
  .TH "HUB" "1" "April 2010" "DEFUNKT" "Git Manual"
5
5
  .
@@ -7,121 +7,101 @@
7
7
  \fBhub\fR \-\- git + hub = github
8
8
  .
9
9
  .SH "SYNOPSIS"
10
- \fBhub\fR \fICOMMAND\fR \fIOPTIONS\fR \fBhub alias\fR [\fB-s\fR] \fISHELL\fR
10
+ \fBhub\fR \fICOMMAND\fR \fIOPTIONS\fR
11
+ .
12
+ .br
13
+ \fBhub alias\fR [\fB\-s\fR] \fISHELL\fR
11
14
  .
12
15
  .P
13
- \fBgit init -g\fR \fIOPTIONS\fR
16
+ \fBgit init \-g\fR \fIOPTIONS\fR
14
17
  .
15
18
  .br
16
- \fBgit clone\fR [\fB-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
19
+ \fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
17
20
  .
18
21
  .br
19
- \fBgit remote add\fR [\fB-p\fR] \fIOPTIONS\fR \fIUSER\fR[/\fIREPOSITORY\fR]
22
+ \fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[/\fIREPOSITORY\fR]
20
23
  .
21
24
  .br
22
25
  \fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,...,\fIREMOTE\-N\fR \fIREF\fR
23
26
  .
24
27
  .br
25
- \fBgit fork\fR
28
+ \fBgit browse\fR [\fB\-p\fR] [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE]
29
+ .
30
+ .br
31
+ \fBgit compare\fR [\fB\-p\fR] [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR...]\fIEND\fR
26
32
  .
27
33
  .br
28
- \fBgit browse\fR [\fB-p\fR] [\fIUSER\fR/]\fIREPOSITORY\fR
34
+ \fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
29
35
  .
30
36
  .br
31
- \fBgit submodule add\fR [\fB-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
37
+ \fBgit fork\fR [\fB\-\-no\-remote\fR]
32
38
  .
33
39
  .SH "DESCRIPTION"
34
40
  \fBhub\fR enhances various \fBgit\fR commands with GitHub remote expansion. The
35
41
  alias command displays information on configuring your environment:
36
42
  .
37
43
  .TP
38
- \fBhub alias\fR [\fB-s\fR] \fISHELL\fR:
44
+ \fBhub alias\fR [\fB\-s\fR] \fISHELL\fR
45
+ Writes shell aliasing code for \fISHELL\fR (\fBbash\fR, \fBsh\fR, \fBzsh\fR, \fBcsh\fR) to standard output. With the \fB\-s\fR option, the output of
46
+ this command can be evaluated directly within the shell:
39
47
  .
40
48
  .br
41
- Writes shell aliasing code for \fISHELL\fR (\fBbash\fR, \fBsh\fR, \fBzsh\fR, \fBcsh\fR) to standard output. With the \fB-s\fR option, the output of
42
- this command can be evaluated directly within the shell
43
- \fBeval $(hub alias -s bash)\fR
49
+ \fBeval $(hub alias \-s bash)\fR
44
50
  .
45
51
  .TP
46
- \fBgit init\fR \fB-g\fR \fIOPTIONS\fR:
47
- .
48
- .br
49
- Create a git repository as with git\-init(1) and add remote \fBorigin\fR at
50
- "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git"; \fIUSER\fR is your GitHub username and
51
- \fIREPOSITORY\fR is the current working directory's basename.
52
-
52
+ \fBgit init\fR \fB\-g\fR \fIOPTIONS\fR
53
+ Create a git repository as with git\-init(1) and add remote \fBorigin\fR at
54
+ "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git"; \fIUSER\fR is your GitHub username and \fIREPOSITORY\fR is the current working directory's basename.
53
55
  .
54
56
  .TP
55
- \fBgit clone\fR [\fB-p\fR] \fIOPTIONS\fR [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR \fIDIRECTORY\fR:
56
- .
57
- .br
57
+ \fBgit clone\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR \fIDIRECTORY\fR
58
58
  Clone repository "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" into \fIDIRECTORY\fR as with git\-clone(1). When \fIUSER\fR/ is omitted, assumes
59
- your GitHub login. With \fB-p\fR, use private remote
59
+ your GitHub login. With \fB\-p\fR, use private remote
60
60
  "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git".
61
-
62
61
  .
63
62
  .TP
64
- \fBgit remote add\fR [\fB-p\fR] \fIOPTIONS\fR \fIUSER\fR[\fB/\fR\fIREPOSITORY\fR]:
65
- .
66
- .br
63
+ \fBgit remote add\fR [\fB\-p\fR] \fIOPTIONS\fR \fIUSER\fR[\fB/\fR\fIREPOSITORY\fR]
67
64
  Add remote "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" as with
68
65
  git\-remote(1). When /\fIREPOSITORY\fR is omitted, the basename of the
69
- current working directory is used. With \fB-p\fR, use private remote
66
+ current working directory is used. With \fB\-p\fR, use private remote
70
67
  "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git". If \fIUSER\fR is "origin"
71
68
  then uses your GitHub login.
72
-
73
69
  .
74
70
  .TP
75
- \fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,...,\fIREMOTE\-N\fR \fIREF\fR:
76
- .
77
- .br
71
+ \fBgit push\fR \fIREMOTE\-1\fR,\fIREMOTE\-2\fR,...,\fIREMOTE\-N\fR \fIREF\fR
78
72
  Push \fIREF\fR to each of \fIREMOTE\-1\fR through \fIREMOTE\-N\fR by executing
79
73
  multiple \fBgit push\fR commands.
80
-
81
- .
82
- .TP
83
- \fBgit fork\fR:
84
- .
85
- .br
86
- Forks the original repo on GitHub and adds the new remote under your
87
- username. It requires your GitHub login and token to be present. See
88
- CONFIGURATION below.
89
-
90
74
  .
91
75
  .TP
92
- \fBgit browse\fR [\fB-p\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR]:
93
- .
94
- .br
76
+ \fBgit browse\fR [\fB\-p\fR] [\fB\-u\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR] [SUBPAGE]
95
77
  Open repository's GitHub page in the system's default web browser
96
- using \fBopen(1)\fR or the \fBBROWSER\fR env variable. Use \fB-p\fR to open a
78
+ using \fBopen(1)\fR or the \fBBROWSER\fR env variable. Use \fB\-p\fR to open a
97
79
  page with https. If the repository isn't specified, \fBbrowse\fR opens
98
- the page of the repository found in the current directory.
99
-
80
+ the page of the repository found in the current directory. If SUBPAGE
81
+ is specified, the browser will open on the specified subpage: one of
82
+ "wiki", "commits", "issues" or other (the default is "tree").
100
83
  .
101
84
  .TP
102
- \fBgit submodule add\fR [\fB-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR:
85
+ \fBgit compare\fR [\fB\-p\fR] [\fB\-u\fR] [\fIUSER\fR] [\fISTART\fR...]\fIEND\fR
86
+ Open a GitHub compare view page in the system's default web browser. \fISTART\fR to \fIEND\fR are branch names, tag names, or commit SHA1s specifying
87
+ the range of history to compare. If \fISTART\fR is omitted, GitHub will
88
+ compare against the base branch (the default is "master").
103
89
  .
104
- .br
90
+ .TP
91
+ \fBgit submodule add\fR [\fB\-p\fR] \fIOPTIONS\fR [\fIUSER\fR/]\fIREPOSITORY\fR \fIDIRECTORY\fR
105
92
  Submodule repository "git://github.com/\fIUSER\fR/\fIREPOSITORY\fR.git" into \fIDIRECTORY\fR as with git\-submodule(1). When \fIUSER\fR/ is omitted, assumes
106
- your GitHub login. With \fB-p\fR, use private remote
93
+ your GitHub login. With \fB\-p\fR, use private remote
107
94
  "git@github.com:\fIUSER\fR/\fIREPOSITORY\fR.git".
108
-
109
95
  .
110
96
  .TP
111
- \fBgit fork\fR [\fB--no-remote\fR]:
112
- .
113
- .br
114
- Forks the original project (as specified in "origin" remote) on GitHub
115
- and adds a new remote named \fIUSER\fR referencing the newly created repo.
116
- Requires \fBgithub.token\fR to be set (see CONFIGURATION).
117
-
97
+ \fBgit fork\fR [\fB\-\-no\-remote\fR]
98
+ Forks the original project (referenced by "origin" remote) on GitHub and
99
+ adds a new remote for it under your username. Requires \fBgithub.token\fR to
100
+ be set (see CONFIGURATION).
118
101
  .
119
102
  .TP
120
- \fBgit help\fR:
121
- .
122
- .br
103
+ \fBgit help\fR
123
104
  Display enhanced git\-help(1).
124
-
125
105
  .
126
106
  .SH "CONFIGURATION"
127
107
  Use git\-config(1) to display the currently configured GitHub username:
@@ -130,7 +110,7 @@ Use git\-config(1) to display the currently configured GitHub username:
130
110
  .
131
111
  .nf
132
112
 
133
- \fB$ git config --global github.user \fR
113
+ $ git config \-\-global github.user
134
114
  .
135
115
  .fi
136
116
  .
@@ -143,8 +123,8 @@ Or, set the GitHub username and token with:
143
123
  .
144
124
  .nf
145
125
 
146
- \fB$ git config --global github.user <username>
147
- $ git config --global github.token <token> \fR
126
+ $ git config \-\-global github.user <username>
127
+ $ git config \-\-global github.token <token>
148
128
  .
149
129
  .fi
150
130
  .
@@ -162,7 +142,7 @@ cloning:
162
142
  .
163
143
  .nf
164
144
 
165
- \fB$ git config --global --add hub.http-clone yes \fR
145
+ $ git config \-\-global \-\-bool hub.http\-clone true
166
146
  .
167
147
  .fi
168
148
  .
@@ -174,17 +154,17 @@ cloning:
174
154
  .
175
155
  .nf
176
156
 
177
- \fB$ git clone schacon/ticgit
178
- > git clone git://github.com/schacon/ticgit.git
179
- $ git clone -p schacon/ticgit
157
+ $ git clone schacon/ticgit
158
+ > git clone git://github.com/schacon/ticgit.git
159
+
160
+ $ git clone \-p schacon/ticgit
180
161
  > git clone git@github.com:schacon/ticgit.git
181
162
 
182
163
  $ git clone resque
183
164
  > git clone git://github.com/YOUR_USER/resque.git
184
165
 
185
- $ git clone -p resque
166
+ $ git clone \-p resque
186
167
  > git clone git@github.com:YOUR_USER/resque.git
187
- \fR
188
168
  .
189
169
  .fi
190
170
  .
@@ -192,14 +172,14 @@ $ git clone -p resque
192
172
  .
193
173
  .nf
194
174
 
195
- \fB$ git remote add rtomayko
196
- > git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git
197
- $ git remote add -p rtomayko
175
+ $ git remote add rtomayko
176
+ > git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git
177
+
178
+ $ git remote add \-p rtomayko
198
179
  > git remote add rtomayko git@github.com:rtomayko/CURRENT_REPO.git
199
180
 
200
181
  $ git remote add origin
201
182
  > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
202
- \fR
203
183
  .
204
184
  .fi
205
185
  .
@@ -207,9 +187,9 @@ $ git remote add origin
207
187
  .
208
188
  .nf
209
189
 
210
- \fB$ git fork
190
+ $ git fork
211
191
  ... hardcore forking action ...
212
- > git remote add YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git \fR
192
+ > git remote add YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
213
193
  .
214
194
  .fi
215
195
  .
@@ -217,9 +197,9 @@ $ git remote add origin
217
197
  .
218
198
  .nf
219
199
 
220
- \fB$ git init -g
200
+ $ git init \-g
221
201
  > git init
222
- > git remote add origin git@github.com:YOUR_USER/REPO.git \fR
202
+ > git remote add origin git@github.com:YOUR_USER/REPO.git
223
203
  .
224
204
  .fi
225
205
  .
@@ -227,10 +207,10 @@ $ git remote add origin
227
207
  .
228
208
  .nf
229
209
 
230
- \fB$ git push origin,staging,qa bert_timeout
210
+ $ git push origin,staging,qa bert_timeout
231
211
  > git push origin bert_timeout
232
212
  > git push staging bert_timeout
233
- > git push qa bert_timeout \fR
213
+ > git push qa bert_timeout
234
214
  .
235
215
  .fi
236
216
  .
@@ -238,17 +218,44 @@ $ git remote add origin
238
218
  .
239
219
  .nf
240
220
 
241
- \fB$ git browse schacon/ticgit
242
- > open http://github.com/schacon/ticgit
243
- $ git browse -p schacon/ticgit
221
+ $ git browse
222
+ > open http://github.com/CURRENT_REPO
223
+
224
+ $ git browse \-\- issues
225
+ > open http://github.com/CURRENT_REPO/issues
226
+
227
+ $ git browse schacon/ticgit
244
228
  > open http://github.com/schacon/ticgit
245
229
 
230
+ $ git browse \-p schacon/ticgit
231
+ > open https://github.com/schacon/ticgit
232
+
246
233
  $ git browse resque
247
234
  > open http://github.com/YOUR_USER/resque
248
235
 
249
- $ git browse -p resque
250
- > open https://github.com:YOUR_USER/resque
251
- \fR
236
+ $ git browse resque network
237
+ > open http://github.com/YOUR_USER/resque/network
238
+
239
+ $ git browse \-p resque
240
+ > open https://github.com/YOUR_USER/resque
241
+ .
242
+ .fi
243
+ .
244
+ .SS "git compare"
245
+ .
246
+ .nf
247
+
248
+ $ git compare refactor
249
+ > open http://github.com/CURRENT_REPO/compare/refactor
250
+
251
+ $ git compare 1.0...1.1
252
+ > open http://github.com/CURRENT_REPO/compare/1.0...1.1
253
+
254
+ $ git compare \-u fix
255
+ > (http://github.com/CURRENT_REPO/compare/fix)
256
+
257
+ $ git compare other\-user patch
258
+ > open http://github.com/other\-user/REPO/compare/patch
252
259
  .
253
260
  .fi
254
261
  .
@@ -256,10 +263,10 @@ $ git browse -p resque
256
263
  .
257
264
  .nf
258
265
 
259
- \fB$ git help
266
+ $ git help
260
267
  > (improved git help)
261
268
  $ git help hub
262
- > (hub man page) \fR
269
+ > (hub man page)
263
270
  .
264
271
  .fi
265
272
  .
@@ -270,4 +277,4 @@ $ git help hub
270
277
  Chris Wanstrath :: chris@ozmm.org :: @defunkt
271
278
  .
272
279
  .SH "SEE ALSO"
273
- git(1), git\-clone(1), git\-remote(1), git\-init(1),\fIhttp://github.com\fR, \fIhttp://github.com/defunkt/hub\fR
280
+ git(1), git\-clone(1), git\-remote(1), git\-init(1), \fIhttp://github.com\fR, \fIhttp://github.com/defunkt/hub\fR