提交 ef3271a8 编写于 作者: M Mislav Marohnić

`hub browse` with no repository specified defaults to current repo

useful for jumping to the GitHub page of the repo checked out in the current directory
上级 236cfe67
......@@ -146,6 +146,9 @@ superpowers:
### git browse
$ git browse
> open http://github.com/CURRENT_REPO
$ git browse schacon/ticgit
> open http://github.com/schacon/ticgit
......
......@@ -143,6 +143,9 @@ module Hub
args.after after
end
# $ hub browse
# > open http://github.com/CURRENT_REPO
#
# $ hub browse pjhyett/github-services
# > open http://github.com/pjhyett/github-services
#
......@@ -159,6 +162,7 @@ module Hub
protocol = args.delete('-p') ? 'https' : 'http'
dest = args.pop
if dest
if dest.include? '/'
# $ hub browse pjhyett/github-services
user, repo = dest.split('/')
......@@ -166,6 +170,13 @@ module Hub
# $ hub browse github-services
user, repo = github_user, dest
end
elsif !OWNER.empty?
# $ hub browse
user, repo = OWNER, REPO
else
$stderr.puts "Usage: hub browse [<USER>/]<REPOSITORY>"
exit(1)
end
args.executable = ENV['BROWSER'] || 'open'
args.push "#{protocol}://github.com/#{user}/#{repo}"
......
......@@ -65,10 +65,11 @@ Push \fIREF\fR to each of \fIREMOTE\-1\fR through \fIREMOTE\-N\fR by executing
multiple \fBgit push\fR commands.
.
.TP
\fBgit browse\fR [\fB\-p\fR] [\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR
\fBgit browse\fR [\fB\-p\fR] [[\fIUSER\fR\fB/\fR]\fIREPOSITORY\fR]
Open repository's GitHub page in the system's default web browser
using \fBopen(1)\fR or the \fBBROWSER\fR env variable. Use \fB\-p\fR to open a
page with https.
page with https. If the repository isn't specified, \fBbrowse\fR opens
the page of the repository found in the current directory.
.
.TP
\fBgit help\fR
......
......@@ -122,11 +122,11 @@ then uses your GitHub login.</p></dd>
<dd><p>Push <var>REF</var> to each of <var>REMOTE-1</var> through <var>REMOTE-N</var> by executing
multiple <code>git push</code> commands.</p></dd>
<dt>
<code>git browse</code> [<code>-p</code>] [<var>USER</var><code>/</code>]<var>REPOSITORY</var>
</dt>
<code>git browse</code> [<code>-p</code>] [[<var>USER</var><code>/</code>]<var>REPOSITORY</var>]</dt>
<dd><p>Open repository's GitHub page in the system's default web browser
using <code>open(1)</code> or the <code>BROWSER</code> env variable. Use <code>-p</code> to open a
page with https.</p></dd>
page with https. If the repository isn't specified, <code>browse</code> opens
the page of the repository found in the current directory.</p></dd>
<dt><code>git help</code></dt>
<dd><p>Display enhanced git-help(1).</p></dd>
</dl>
......
......@@ -46,10 +46,11 @@ After configuring the alias, the following commands have superpowers:
Push <REF> to each of <REMOTE-1> through <REMOTE-N> by executing
multiple `git push` commands.
* `git browse` [`-p`] [<USER>`/`]<REPOSITORY>:
* `git browse` [`-p`] [[<USER>`/`]<REPOSITORY>]:
Open repository's GitHub page in the system's default web browser
using `open(1)` or the `BROWSER` env variable. Use `-p` to open a
page with https.
page with https. If the repository isn't specified, `browse` opens
the page of the repository found in the current directory.
* `git help`:
Display enhanced git-help(1).
......
......@@ -182,4 +182,18 @@ config
def test_hub_open_self_private
assert_command "browse -p github", "open https://github.com/tpw/github"
end
def test_hub_open_current
assert_command "browse", "open http://github.com/defunkt/hub"
end
def test_hub_open_current_private
assert_command "browse -p", "open https://github.com/defunkt/hub"
end
def test_hub_open_no_repo
Hub::Commands::OWNER.replace("")
input = "browse"
assert_equal "Usage: hub browse [<USER>/]<REPOSITORY>\n", hub(input)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册