<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
     on multiple remote machines, via SSH.
   DESC
 
-  s.files = Dir.glob(&quot;{bin,lib,examples,test}/**/*&quot;) + %w(README MIT-LICENSE CHANGELOG THANKS)
+  s.files = Dir.glob(&quot;{bin,lib,examples,test}/**/*&quot;) + %w(README MIT-LICENSE CHANGELOG)
   s.require_path = 'lib'
   s.autorequire = 'capistrano'
 </diff>
      <filename>capistrano.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -1 +1,2 @@
 require 'capistrano/configuration'
+require 'capistrano/extensions'
\ No newline at end of file</diff>
      <filename>lib/capistrano.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+require 'capistrano'
 require 'capistrano/cli/execute'
 require 'capistrano/cli/help'
 require 'capistrano/cli/options'</diff>
      <filename>lib/capistrano/cli.rb</filename>
    </modified>
    <modified>
      <diff>@@ -75,7 +75,7 @@ module Capistrano
       def open_channels
         sessions.map do |session|
           session.open_channel do |channel|
-            channel[:host] = session.host
+            channel[:host] = session.real_host
             channel[:options] = options
             channel.request_pty :want_reply =&gt; true
 </diff>
      <filename>lib/capistrano/command.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,3 @@
-#require 'capistrano/extensions'
 require 'capistrano/logger'
 
 require 'capistrano/configuration/connections'</diff>
      <filename>lib/capistrano/configuration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,36 +1,41 @@
-# module Capistrano
-#   class ExtensionProxy
-#     def initialize(actor, mod)
-#       @actor = actor
-#       extend(mod)
-#     end
-# 
-#     def method_missing(sym, *args, &amp;block)
-#       @actor.send(sym, *args, &amp;block)
-#     end
-#   end
-# 
-#   EXTENSIONS = {}
-# 
-#   def self.plugin(name, mod)
-#     return false if EXTENSIONS.has_key?(name)
-# 
-#     Capistrano::Actor.class_eval &lt;&lt;-STR, __FILE__, __LINE__+1
-#       def #{name}
-#         @__#{name}_proxy ||= Capistrano::ExtensionProxy.new(self, Capistrano::EXTENSIONS[#{name.inspect}])
-#       end
-#     STR
-# 
-#     EXTENSIONS[name] = mod
-#     return true
-#   end
-# 
-#   def self.remove_plugin(name)
-#     if EXTENSIONS.delete(name)
-#       Capistrano::Actor.send(:remove_method, name)
-#       return true
-#     end
-# 
-#     return false
-#   end
-# end
+module Capistrano
+  class ExtensionProxy
+    def initialize(config, mod)
+      @config = config
+      extend(mod)
+    end
+
+    def method_missing(sym, *args, &amp;block)
+      @config.send(sym, *args, &amp;block)
+    end
+  end
+
+  EXTENSIONS = {}
+
+  def self.plugin(name, mod)
+    return false if EXTENSIONS.has_key?(name)
+
+    Capistrano::Configuration.class_eval &lt;&lt;-STR, __FILE__, __LINE__+1
+      def #{name}
+        @__#{name}_proxy ||= Capistrano::ExtensionProxy.new(self, Capistrano::EXTENSIONS[#{name.inspect}])
+      end
+    STR
+
+    EXTENSIONS[name] = mod
+    return true
+  end
+
+  def self.remove_plugin(name)
+    if EXTENSIONS.delete(name)
+      Capistrano::Configuration.send(:remove_method, name)
+      return true
+    end
+
+    return false
+  end
+
+  def self.configuration(*args)
+    warn &quot;[DEPRECATION] Capistrano.configuration is deprecated. Use Capistrano::Configuration.instance instead&quot;
+    Capistrano::Configuration.instance(*args)
+  end
+end</diff>
      <filename>lib/capistrano/extensions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -81,6 +81,7 @@ module Capistrano
           local_host = ServerDefinition.new(&quot;127.0.0.1&quot;, :user =&gt; server.user, :port =&gt; local_port)
           session.forward.local(local_port, server.host, server.port || 22)
           connection = SSH.connect(local_host, @options)
+          connection.real_host = server.host
           logger.trace &quot;connected: `#{server.host}' (via gateway)&quot; if logger
         rescue Errno::EADDRINUSE
           local_port = next_port</diff>
      <filename>lib/capistrano/gateway.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,20 @@ module Capistrano
 
   # A helper class for dealing with SSH connections.
   class SSH
+    # Patch an accessor onto an SSH connection so that we can record the &quot;real&quot;
+    # host behind the connection. This is useful because the gateway returns
+    # connections whose &quot;host&quot; is 127.0.0.1, instead of the host on the other
+    # side of the tunnel.
+    module RealHost #:nodoc:
+      def self.apply_to(connection, host)
+        connection.extend(RealHost)
+        connection.real_host = host
+        connection
+      end
+
+      attr_accessor :real_host
+    end
+
     # The default port for SSH.
     DEFAULT_PORT = 22
 
@@ -34,7 +48,8 @@ module Capistrano
                         :auth_methods =&gt; methods.shift }
         ssh_options.update(options[:ssh_options]) if options[:ssh_options]
         
-        Net::SSH.start(server.host, ssh_options, &amp;block)
+        connection = Net::SSH.start(server.host, ssh_options, &amp;block)
+        RealHost.apply_to(connection, server.host)
 
       rescue Net::SSH::AuthenticationFailed
         raise if methods.empty?</diff>
      <filename>lib/capistrano/ssh.rb</filename>
    </modified>
    <modified>
      <diff>@@ -53,7 +53,7 @@ class CommandTest &lt; Test::Unit::TestCase
   end
 
   def test_open_channel_should_set_host_key_on_channel
-    session = mock(:host =&gt; &quot;capistrano&quot;)
+    session = mock(:real_host =&gt; &quot;capistrano&quot;)
     channel = stub_everything
 
     session.expects(:open_channel).yields(channel)
@@ -63,7 +63,7 @@ class CommandTest &lt; Test::Unit::TestCase
   end
 
   def test_open_channel_should_set_options_key_on_channel
-    session = mock(:host =&gt; &quot;capistrano&quot;)
+    session = mock(:real_host =&gt; &quot;capistrano&quot;)
     channel = stub_everything
 
     session.expects(:open_channel).yields(channel)
@@ -73,7 +73,7 @@ class CommandTest &lt; Test::Unit::TestCase
   end
 
   def test_open_channel_should_request_pty
-    session = mock(:host =&gt; &quot;capistrano&quot;)
+    session = mock(:real_host =&gt; &quot;capistrano&quot;)
     channel = stub_everything
 
     session.expects(:open_channel).yields(channel)
@@ -240,7 +240,7 @@ class CommandTest &lt; Test::Unit::TestCase
     end
 
     def setup_for_extracting_channel_action(action, *args)
-      session = mock(:host =&gt; &quot;capistrano&quot;)
+      session = mock(:real_host =&gt; &quot;capistrano&quot;)
 
       channel = stub_everything
       session.expects(:open_channel).yields(channel)</diff>
      <filename>test/command_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,39 +25,46 @@ class GatewayTest &lt; Test::Unit::TestCase
 
   def test_connect_to_should_start_local_ports_at_65535
     gateway = new_gateway
-    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns :app1
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns(result = sess_with_real_host(&quot;app1&quot;))
     newsess = gateway.connect_to(server(&quot;app1&quot;))
-    assert_equal :app1, newsess
+    assert_equal result, newsess
     assert_equal [65535, &quot;app1&quot;, 22], gateway.session.forward.active_locals[65535]
   end
 
   def test_connect_to_should_decrement_port_and_retry_if_ports_are_in_use
     gateway = new_gateway(:reserved =&gt; lambda { |n| n &gt; 65000 })
-    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65000).returns :app1
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65000).returns(result = sess_with_real_host(&quot;app1&quot;))
     newsess = gateway.connect_to(server(&quot;app1&quot;))
-    assert_equal :app1, newsess
+    assert_equal result, newsess
     assert_equal [65000, &quot;app1&quot;, 22], gateway.session.forward.active_locals[65000]
   end
 
   def test_connect_to_should_honor_user_specification_in_server_definition
     gateway = new_gateway
-    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :user =&gt; &quot;jamis&quot;, :port =&gt; 65535).returns :app1
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :user =&gt; &quot;jamis&quot;, :port =&gt; 65535).returns(result = sess_with_real_host(&quot;app1&quot;))
     newsess = gateway.connect_to(server(&quot;jamis@app1&quot;))
-    assert_equal :app1, newsess
+    assert_equal result, newsess
     assert_equal [65535, &quot;app1&quot;, 22], gateway.session.forward.active_locals[65535]
   end
 
   def test_connect_to_should_honor_port_specification_in_server_definition
     gateway = new_gateway
-    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns :app1
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns(result = sess_with_real_host(&quot;app1&quot;))
     newsess = gateway.connect_to(server(&quot;app1:1234&quot;))
-    assert_equal :app1, newsess
+    assert_equal result, newsess
     assert_equal [65535, &quot;app1&quot;, 1234], gateway.session.forward.active_locals[65535]
   end
 
+  def test_connect_to_should_set_real_host_to_tunnel_target
+    gateway = new_gateway
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns(result = sess_with_real_host(&quot;app1&quot;))
+    newsess = gateway.connect_to(server(&quot;app1:1234&quot;))
+    assert_equal result, newsess
+  end
+
   def test_shutdown_should_cancel_active_forwarded_ports
     gateway = new_gateway
-    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns :app1
+    expect_connect_to(:host =&gt; &quot;127.0.0.1&quot;, :port =&gt; 65535).returns(sess_with_real_host(&quot;app1&quot;))
     gateway.connect_to(server(&quot;app1&quot;))
     assert !gateway.session.forward.active_locals.empty?
     gateway.shutdown!
@@ -73,6 +80,12 @@ class GatewayTest &lt; Test::Unit::TestCase
 
   private
 
+    def sess_with_real_host(host)
+      sess = mock(&quot;session&quot;)
+      sess.expects(:real_host=).with(host)
+      sess
+    end
+
     def expect_connect_to(options={})
       Capistrano::SSH.expects(:connect).with do |server,config|
         options.all? do |key, value|</diff>
      <filename>test/gateway_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,14 +11,14 @@ class SSHTest &lt; Test::Unit::TestCase
   end
 
   def test_connect_with_bare_server_without_options_or_config_with_public_key_succeeding_should_only_loop_once
-    Net::SSH.expects(:start).with(@server.host, @options).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server)
+    Net::SSH.expects(:start).with(@server.host, @options).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server)
   end
 
   def test_connect_with_bare_server_without_options_with_public_key_failing_should_try_password
     Net::SSH.expects(:start).with(@server.host, @options).raises(Net::SSH::AuthenticationFailed)
-    Net::SSH.expects(:start).with(@server.host, @options.merge(:password =&gt; &quot;f4b13n&quot;, :auth_methods =&gt; %w(password keyboard-interactive))).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server, :password =&gt; &quot;f4b13n&quot;)
+    Net::SSH.expects(:start).with(@server.host, @options.merge(:password =&gt; &quot;f4b13n&quot;, :auth_methods =&gt; %w(password keyboard-interactive))).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server, :password =&gt; &quot;f4b13n&quot;)
   end
 
   def test_connect_with_bare_server_without_options_public_key_and_password_failing_should_raise_error
@@ -30,49 +30,57 @@ class SSHTest &lt; Test::Unit::TestCase
   end
 
   def test_connect_with_bare_server_and_user_via_public_key_should_pass_user_to_net_ssh
-    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;jamis&quot;)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server, :user =&gt; &quot;jamis&quot;)
+    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;jamis&quot;)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server, :user =&gt; &quot;jamis&quot;)
   end
 
   def test_connect_with_bare_server_and_user_via_password_should_pass_user_to_net_ssh
     Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;jamis&quot;)).raises(Net::SSH::AuthenticationFailed)
-    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;jamis&quot;, :password =&gt; &quot;f4b13n&quot;, :auth_methods =&gt; %w(password keyboard-interactive))).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server, :user =&gt; &quot;jamis&quot;, :password =&gt; &quot;f4b13n&quot;)
+    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;jamis&quot;, :password =&gt; &quot;f4b13n&quot;, :auth_methods =&gt; %w(password keyboard-interactive))).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server, :user =&gt; &quot;jamis&quot;, :password =&gt; &quot;f4b13n&quot;)
   end
 
   def test_connect_with_bare_server_with_explicit_port_should_pass_port_to_net_ssh
-    Net::SSH.expects(:start).with(@server.host, @options.merge(:port =&gt; 1234)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server, :port =&gt; 1234)
+    Net::SSH.expects(:start).with(@server.host, @options.merge(:port =&gt; 1234)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server, :port =&gt; 1234)
   end
 
   def test_connect_with_server_with_user_should_pass_user_to_net_ssh
     server = server(&quot;jamis@capistrano&quot;)
-    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;jamis&quot;)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(server)
+    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;jamis&quot;)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(server)
   end
 
   def test_connect_with_server_with_port_should_pass_port_to_net_ssh
     server = server(&quot;capistrano:1235&quot;)
-    Net::SSH.expects(:start).with(server.host, @options.merge(:port =&gt; 1235)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(server)
+    Net::SSH.expects(:start).with(server.host, @options.merge(:port =&gt; 1235)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(server)
   end
 
   def test_connect_with_server_with_user_and_port_should_pass_user_and_port_to_net_ssh
     server = server(&quot;jamis@capistrano:1235&quot;)
-    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;jamis&quot;, :port =&gt; 1235)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(server)
+    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;jamis&quot;, :port =&gt; 1235)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(server)
   end
 
   def test_connect_with_ssh_options_should_override_options
     ssh_options = { :username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125 }
-    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(@server, {:ssh_options =&gt; ssh_options, :user =&gt; &quot;jamis&quot;, :port =&gt; 1235})
+    Net::SSH.expects(:start).with(@server.host, @options.merge(:username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options =&gt; ssh_options, :user =&gt; &quot;jamis&quot;, :port =&gt; 1235})
   end
 
   def test_connect_with_ssh_options_should_override_server_options
     ssh_options = { :username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125 }
     server = server(&quot;jamis@capistrano:1235&quot;)
-    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125)).returns(:success)
-    assert_equal :success, Capistrano::SSH.connect(server, {:ssh_options =&gt; ssh_options})
+    Net::SSH.expects(:start).with(server.host, @options.merge(:username =&gt; &quot;JamisMan&quot;, :port =&gt; 8125)).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(server, {:ssh_options =&gt; ssh_options})
+  end
+
+  def test_connect_should_add_real_host_accessor_to_connection
+    Net::SSH.expects(:start).with(@server.host, @options).returns(success = Object.new)
+    assert_equal success, Capistrano::SSH.connect(@server)
+    assert success.respond_to?(:real_host)
+    assert success.respond_to?(:real_host=)
+    assert_equal success.real_host, @server.host
   end
 end</diff>
      <filename>test/ssh_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f8d425ef0d91d437ea9b5d80553c0cb1e76d680f</id>
    </parent>
  </parents>
  <author>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </author>
  <url>http://github.com/jamis/capistrano/commit/55e194c3f058615680602fa14df25710806c120c</url>
  <id>55e194c3f058615680602fa14df25710806c120c</id>
  <committed-date>2007-03-16T14:22:10-07:00</committed-date>
  <authored-date>2007-03-16T14:22:10-07:00</authored-date>
  <message>restore plugin extension mechanism, fix hostname problem for tunnelled connections


git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6436 5ecf4fe2-1ee6-0310-87b1-e25e094e27de</message>
  <tree>7c11390f88bd6f202ecccd910368632dd607644d</tree>
  <committer>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </committer>
</commit>
