diff --git a/README.md b/README.md
index 79b9840d9ab76534188dec7c743be74151e240ed..5bd83656355824e8cda7b09007cb5cf4f91d79a4 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb
index 855962fd2972becfad8d927a7efc0851a79696d8..40b4f7228337c0d8c4cdecc2a55b8c043a80c36f 100644
--- a/lib/hub/commands.rb
+++ b/lib/hub/commands.rb
@@ -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,12 +162,20 @@ module Hub
protocol = args.delete('-p') ? 'https' : 'http'
dest = args.pop
- if dest.include? '/'
- # $ hub browse pjhyett/github-services
- user, repo = dest.split('/')
+ if dest
+ if dest.include? '/'
+ # $ hub browse pjhyett/github-services
+ user, repo = dest.split('/')
+ else
+ # $ hub browse github-services
+ user, repo = github_user, dest
+ end
+ elsif !OWNER.empty?
+ # $ hub browse
+ user, repo = OWNER, REPO
else
- # $ hub browse github-services
- user, repo = github_user, dest
+ $stderr.puts "Usage: hub browse [/]"
+ exit(1)
end
args.executable = ENV['BROWSER'] || 'open'
diff --git a/man/hub.1 b/man/hub.1
index 9e772d3672efb16e21e3d5951582a8fd9ef21f84..19b2ad559d1526e1474b1cf8a0321d11b35208a2 100644
--- a/man/hub.1
+++ b/man/hub.1
@@ -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
diff --git a/man/hub.1.html b/man/hub.1.html
index 354fee2532092effc1a523da8cdc1c1445baaf60..0e41874fc8ba02f1cab38763f83ce8d85911d864 100644
--- a/man/hub.1.html
+++ b/man/hub.1.html
@@ -122,11 +122,11 @@ then uses your GitHub login.
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).
diff --git a/man/hub.1.ron b/man/hub.1.ron
index 5e9bde18526006d611f2b7a5a83052700be3fd0d..4bb3c992e1822a89e6375d154f78be38c4064647 100644
--- a/man/hub.1.ron
+++ b/man/hub.1.ron
@@ -46,10 +46,11 @@ After configuring the alias, the following commands have superpowers:
Push [ to each of through by executing
multiple `git push` commands.
- * `git browse` [`-p`] [`/`]:
+ * `git browse` [`-p`] [[`/`]]:
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).
diff --git a/test/hub_test.rb b/test/hub_test.rb
index 7836a164402810738ffa401431b0eb6df84d4a47..ebb08949fce5bfab1cbcc90a8521beeef7a54234 100644
--- a/test/hub_test.rb
+++ b/test/hub_test.rb
@@ -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 [/]\n", hub(input)
+ end
end
]