Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix `browse` command when not on any branch

Closes #145
  • Loading branch information...
commit 1e45ad9e16f4da5871c78cb18d0c57b8bf75b1f8 1 parent 1e16a51
@mislav mislav authored
Showing with 8 additions and 3 deletions.
  1. +2 −2 lib/hub/commands.rb
  2. +1 −1  lib/hub/context.rb
  3. +5 −0 test/hub_test.rb
View
4 lib/hub/commands.rb
@@ -537,9 +537,11 @@ def browse(args)
# $ hub browse pjhyett/github-services
# $ hub browse github-services
project = github_project dest
+ branch = master_branch
else
# $ hub browse
project = current_project
+ branch = current_branch && current_branch.upstream || master_branch
end
abort "Usage: hub browse [<USER>/]<REPOSITORY>" unless project
@@ -547,10 +549,8 @@ def browse(args)
# $ hub browse -- wiki
path = case subpage = args.shift
when 'commits'
- branch = (!dest && current_branch.upstream) || master_branch
"/commits/#{branch.short_name}"
when 'tree', NilClass
- branch = !dest && current_branch.upstream
"/tree/#{branch.short_name}" if branch and !branch.master?
else
"/#{subpage}"
View
2  lib/hub/context.rb
@@ -130,7 +130,7 @@ def main_project
end
def upstream_project
- if upstream = current_branch.upstream
+ if branch = current_branch and upstream = branch.upstream
remote = remote_by_name upstream.remote_name
remote.project
end
View
5 test/hub_test.rb
@@ -1156,6 +1156,11 @@ def test_hub_browse_on_complex_branch
'open https://github.com/mislav/hub/tree/feature/bar'
end
+ def test_hub_browse_no_branch
+ stub_branch(nil)
+ assert_command 'browse', 'open https://github.com/defunkt/hub'
+ end
+
def test_hub_browse_current
assert_command "browse", "open https://github.com/defunkt/hub"
assert_command "browse --", "open https://github.com/defunkt/hub"
Please sign in to comment.
Something went wrong with that request. Please try again.