<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,9 @@
 == (unreleased)
 
+* Bump Net::SSH dependency to version 2.0.10 [Jamis Buck]
+
+* Use 'user' from .ssh/config appropriately [Jamis Buck]
+
 * Allow respond_to?() method to accept optional second parameter (include_priv) [Matthias Marschall]
 
 * Make sure sudo prompts are retried correctly even if &quot;try again&quot; and the prompt appear in the same text chunk from the server [Jamis Buck]</diff>
      <filename>CHANGELOG.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,7 @@ Echoe.new('capistrano', version) do |p|
   p.need_zip         = true
   p.rdoc_pattern     = /^(lib|README.rdoc|CHANGELOG.rdoc)/
 
-  p.dependencies     = [&quot;net-ssh         &gt;=2.0.0&quot;,
+  p.dependencies     = [&quot;net-ssh         &gt;=2.0.10&quot;,
                         &quot;net-sftp        &gt;=2.0.0&quot;,
                         &quot;net-scp         &gt;=1.0.0&quot;,
                         &quot;net-ssh-gateway &gt;=1.0.0&quot;,</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 begin
   require 'rubygems'
-  gem 'net-ssh', &quot;&gt;= 1.99.1&quot;
+  gem 'net-ssh', &quot;&gt;= 2.0.10&quot;
 rescue LoadError, NameError
 end
 
@@ -55,12 +55,32 @@ module Capistrano
       methods = [ %w(publickey hostbased), %w(password keyboard-interactive) ]
       password_value = nil
 
-      ssh_options = (server.options[:ssh_options] || {}).merge(options[:ssh_options] || {})
-      user        = server.user || options[:user] || ssh_options[:username] || ServerDefinition.default_user
-      port        = server.port || options[:port] || ssh_options[:port]
+      # construct the hash of ssh options that should be passed more-or-less
+      # directly to Net::SSH. This will be the general ssh options, merged with
+      # the server-specific ssh-options.
+      ssh_options = (options[:ssh_options] || {}).merge(server.options[:ssh_options] || {})
+
+      # load any SSH configuration files that were specified in the SSH options. This
+      # will load from ~/.ssh/config and /etc/ssh_config by default (see Net::SSH
+      # for details). Merge the explicitly given ssh_options over the top of the info
+      # from the config file.
+      ssh_options = Net::SSH.configuration_for(server.host, ssh_options.fetch(:config, true)).merge(ssh_options)
+
+      # Once we've loaded the config, we don't need Net::SSH to do it again.
+      ssh_options[:config] = false
+
+      user = server.user || options[:user] || ssh_options[:username] ||
+             ssh_options[:user] || ServerDefinition.default_user
+      port = server.port || options[:port] || ssh_options[:port]
+
+      # the .ssh/config file might have changed the host-name on us
+      host = ssh_options.fetch(:host_name, server.host) 
 
       ssh_options[:port] = port if port
+
+      # delete these, since we've determined which username to use by this point
       ssh_options.delete(:username)
+      ssh_options.delete(:user)
 
       begin
         connection_options = ssh_options.merge(
@@ -68,7 +88,7 @@ module Capistrano
           :auth_methods =&gt; ssh_options[:auth_methods] || methods.shift
         )
 
-        yield server.host, user, connection_options
+        yield host, user, connection_options
       rescue Net::SSH::AuthenticationFailed
         raise if methods.empty? || ssh_options[:auth_methods]
         password_value = options[:password]</diff>
      <filename>lib/capistrano/ssh.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@ class ConfigurationConnectionsTest &lt; Test::Unit::TestCase
   def setup
     @config = MockConfig.new
     @config.stubs(:logger).returns(stub_everything)
+    Net::SSH.stubs(:configuration_for).returns({})
     @ssh_options = {
       :user        =&gt; &quot;user&quot;,
       :port        =&gt; 8080,
@@ -60,29 +61,29 @@ class ConfigurationConnectionsTest &lt; Test::Unit::TestCase
 
   def test_should_connect_through_gateway_if_gateway_variable_is_set
     @config.values[:gateway] = &quot;j@gateway&quot;
-    Net::SSH::Gateway.expects(:new).with(&quot;gateway&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased)).returns(stub_everything)
+    Net::SSH::Gateway.expects(:new).with(&quot;gateway&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased), :config =&gt; false).returns(stub_everything)
     assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
   end
 
   def test_connection_factory_as_gateway_should_honor_config_options
     @config.values[:gateway] = &quot;gateway&quot;
     @config.values.update(@ssh_options)
-    Net::SSH::Gateway.expects(:new).with(&quot;gateway&quot;, &quot;user&quot;, :debug =&gt; :verbose, :port =&gt; 8080, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased)).returns(stub_everything)
+    Net::SSH::Gateway.expects(:new).with(&quot;gateway&quot;, &quot;user&quot;, :debug =&gt; :verbose, :port =&gt; 8080, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased), :config =&gt; false).returns(stub_everything)
     assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
   end
   
   def test_connection_factory_as_gateway_should_chain_gateways_if_gateway_variable_is_an_array
     @config.values[:gateway] = [&quot;j@gateway1&quot;, &quot;k@gateway2&quot;]
     gateway1 = mock
-    Net::SSH::Gateway.expects(:new).with(&quot;gateway1&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased)).returns(gateway1)
+    Net::SSH::Gateway.expects(:new).with(&quot;gateway1&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased), :config =&gt; false).returns(gateway1)
     gateway1.expects(:open).returns(65535)
-    Net::SSH::Gateway.expects(:new).with(&quot;127.0.0.1&quot;, &quot;k&quot;, :port =&gt; 65535, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased)).returns(stub_everything)
+    Net::SSH::Gateway.expects(:new).with(&quot;127.0.0.1&quot;, &quot;k&quot;, :port =&gt; 65535, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased), :config =&gt; false).returns(stub_everything)
     assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
   end
   
   def test_connection_factory_as_gateway_should_share_gateway_between_connections
     @config.values[:gateway] = &quot;j@gateway&quot;
-    Net::SSH::Gateway.expects(:new).once.with(&quot;gateway&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased)).returns(stub_everything)
+    Net::SSH::Gateway.expects(:new).once.with(&quot;gateway&quot;, &quot;j&quot;, :password =&gt; nil, :auth_methods =&gt; %w(publickey hostbased), :config =&gt; false).returns(stub_everything)
     Capistrano::SSH.stubs(:connect).returns(stub_everything)
     assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
     @config.establish_connections_to(server(&quot;capistrano&quot;))</diff>
      <filename>test/configuration/connections_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,10 @@ class SSHTest &lt; Test::Unit::TestCase
   def setup
     Capistrano::ServerDefinition.stubs(:default_user).returns(&quot;default-user&quot;)
     @options = { :password =&gt; nil,
-                 :auth_methods =&gt; %w(publickey hostbased) }
+                 :auth_methods =&gt; %w(publickey hostbased),
+                 :config =&gt; false }
     @server = server(&quot;capistrano&quot;)
+    Net::SSH.stubs(:configuration_for).returns({})
   end
 
   def test_connect_with_bare_server_without_options_or_config_with_public_key_succeeding_should_only_loop_once
@@ -69,8 +71,8 @@ class SSHTest &lt; Test::Unit::TestCase
   end
 
   def test_connect_with_ssh_options_should_use_ssh_options
-    ssh_options = { :username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125 }
-    Net::SSH.expects(:start).with(@server.host, &quot;JamisMan&quot;, @options.merge(:port =&gt; 8125)).returns(success = Object.new)
+    ssh_options = { :username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125, :config =&gt; false }
+    Net::SSH.expects(:start).with(@server.host, &quot;JamisMan&quot;, @options.merge(:port =&gt; 8125, :config =&gt; false)).returns(success = Object.new)
     assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options =&gt; ssh_options})
   end
 
@@ -83,7 +85,7 @@ class SSHTest &lt; Test::Unit::TestCase
   def test_connect_with_ssh_options_should_see_server_options_override_ssh_options
     ssh_options = { :username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125, :forward_agent =&gt; true }
     server = server(&quot;jamis@capistrano:1235&quot;)
-    Net::SSH.expects(:start).with(server.host, &quot;jamis&quot;, @options.merge(:port =&gt; 1235, :forward_agent =&gt; true)).returns(success = Object.new)
+    Net::SSH.expects(:start).with(server.host, &quot;jamis&quot;, @options.merge(:port =&gt; 1235, :forward_agent =&gt; true, :config =&gt; false)).returns(success = Object.new)
     assert_equal success, Capistrano::SSH.connect(server, {:ssh_options =&gt; ssh_options})
   end
 </diff>
      <filename>test/ssh_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f70fccaf372c7b11e579223dcc7f1e426c383e85</id>
    </parent>
  </parents>
  <author>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </author>
  <url>http://github.com/mbailey/capistrano/commit/9a281b2d13aef75e6afdd4132c6c1a8d5255099f</url>
  <id>9a281b2d13aef75e6afdd4132c6c1a8d5255099f</id>
  <committed-date>2009-02-02T22:11:22-08:00</committed-date>
  <authored-date>2009-02-02T22:11:22-08:00</authored-date>
  <message>Use 'user' from .ssh/config appropriately, and bump Net::SSH dependency to 2.0.10</message>
  <tree>5d531b7ccaa58b74ab11c997e248858a9ca0838d</tree>
  <committer>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </committer>
</commit>
