diff --git a/lib/hub/context.rb b/lib/hub/context.rb index ae7c89c98601dd25e05e07df142539b8e4581c8a..8579388e9f1652a3fcc9bbaeb3669334cf45da3c 100644 --- a/lib/hub/context.rb +++ b/lib/hub/context.rb @@ -185,7 +185,11 @@ module Hub end def known_hosts - git_config('hub.host', :all).to_s.split("\n") + [default_host] + hosts = git_config('hub.host', :all).to_s.split("\n") + hosts << default_host + # support ssh.github.com + # https://help.github.com/articles/using-ssh-over-the-https-port + hosts << "ssh.#{default_host}" end def self.default_host @@ -217,6 +221,7 @@ module Hub def initialize(*args) super self.host ||= (local_repo || LocalRepo).default_host + self.host = host.sub(/^ssh\./i, '') if 'ssh.github.com' == host.downcase end def private? diff --git a/test/hub_test.rb b/test/hub_test.rb index f062834443b90db39ba3d16fa6b430fac0bf2c4e..3987195391919d50f0632e941d25b017c7263b1d 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -4,6 +4,7 @@ require 'rbconfig' require 'yaml' require 'forwardable' require 'fileutils' +require 'tempfile' WebMock::BodyPattern.class_eval do undef normalize_hash @@ -578,12 +579,19 @@ class HubTest < Test::Unit::TestCase end def test_hub_browse_ssh_alias - with_ssh_config do + with_ssh_config "Host gh\n User git\n HostName github.com" do stub_repo_url "gh:singingwolfboy/sekrit.git" assert_command "browse", "open https://github.com/singingwolfboy/sekrit" end end + def test_hub_browse_ssh_github_alias + with_ssh_config "Host github.com\n HostName ssh.github.com" do + stub_repo_url "git@github.com:suan/git-sanity.git" + assert_command "browse", "open https://github.com/suan/git-sanity" + end + end + def test_custom_browser with_browser_env("custom") do assert_browser("custom") @@ -748,10 +756,17 @@ class HubTest < Test::Unit::TestCase Hub::Commands.send :improved_help_text end - def with_ssh_config - config_file = File.expand_path '../ssh_config', __FILE__ - Hub::SshConfig::CONFIG_FILES.replace [config_file] - yield + def with_ssh_config content + config_file = Tempfile.open 'ssh_config' + config_file << content + config_file.close + + begin + Hub::SshConfig::CONFIG_FILES.replace [config_file.path] + yield + ensure + config_file.unlink + end end end diff --git a/test/ssh_config b/test/ssh_config deleted file mode 100644 index 1e86613061d46adb2dd74378ea37395b94cff322..0000000000000000000000000000000000000000 --- a/test/ssh_config +++ /dev/null @@ -1,3 +0,0 @@ -Host gh - User git - HostName github.com