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

support ssh.github.com

Fixes #208
上级 ec15f331
......@@ -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?
......
......@@ -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]
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
Host gh
User git
HostName github.com
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册