From 3dad4373075da800e008caf64c4da4c1699ca41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 19 Jul 2012 00:55:08 +0200 Subject: [PATCH] support ssh.github.com Fixes #208 --- lib/hub/context.rb | 7 ++++++- test/hub_test.rb | 25 ++++++++++++++++++++----- test/ssh_config | 3 --- 3 files changed, 26 insertions(+), 9 deletions(-) delete mode 100644 test/ssh_config diff --git a/lib/hub/context.rb b/lib/hub/context.rb index ae7c89c9..8579388e 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 f0628344..39871953 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 1e866130..00000000 --- a/test/ssh_config +++ /dev/null @@ -1,3 +0,0 @@ -Host gh - User git - HostName github.com -- GitLab