<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,7 +6,8 @@ module Capistrano
     module Strategy
       class RsyncWithRemoteCache &lt; Remote
 
-        # The deployment method itself, in three major steps.
+        # The deployment method itself, in three major steps: update the local cache, update the remote
+        # cache, and copy the remote cache into place.
         def deploy!
 
           # Step 1: Update the local cache.
@@ -61,27 +62,32 @@ module Capistrano
             server.host
           end
         end
-        
+
         # Command to get source from SCM on the local side. If the local_cache directory exists,
         # we check to see if it's an SCM checkout that matches the currently configured repository.
         # If it matches, we update it. If it doesn't match (either it's for another repository or
         # not a checkout at all), we remove the directory and recreate it with a fresh SCM checkout.
         # If the directory doesn't exist, we create it with a fresh SCM checkout.
+        # TODO: punt in some sensible way if local_cache exists but is a regular file.
         def command
+          case configuration[:scm].to_s
+          when 'subversion'
+            info_command = &quot;svn info #{local_cache} | sed -n 's/URL: //p'&quot;
+          when 'git'
+            info_command = &quot;cd #{local_cache} &amp;&amp; git config remote.origin.url&quot;
+          else
+            # an effective no-op
+            info_command = &quot;echo #{configuration[:repository]}&quot;
+          end
+          cache_info = IO.popen(info_command)
 
-          # FIXME: This logic only takes place if the SCM is Subversion. At some point, similar logic
-          # will probably be necessary for Git and other SCMs we might use.
-          #
-          # TODO: punt in some sensible way if local_cache exists but is a regular file.
-          if configuration[:scm] == :subversion
-            svn_info = IO.popen(&quot;svn info #{local_cache} | sed -n 's/URL: //p'&quot;)
-            svn_url = svn_info.gets
-            svn_info.close
-            if svn_url &amp;&amp; svn_url.chomp != configuration[:repository]
-              logger.trace &quot;repository has changed; removing old local cache&quot;
-              FileUtils.rm_rf local_cache
-            end
+          cached_repository = cache_info.gets
+          cache_info.close
+          if cached_repository &amp;&amp; cached_repository.chomp != configuration[:repository]
+            logger.trace &quot;repository has changed; removing old local cache&quot;
+            FileUtils.rm_rf local_cache
           end
+
           if File.exists?(local_cache) &amp;&amp; File.directory?(local_cache)
             logger.trace &quot;updating local cache to revision #{revision}&quot;
             cmd = source.sync(revision, local_cache)</diff>
      <filename>lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,14 @@ class CapistranoRsyncWithRemoteCacheTest &lt; Test::Unit::TestCase
     source_stub.expects(:checkout)
     @rwrc.expects(:source).returns(source_stub)
   end
-  
+
+  def stub_detection_of_changed_local_cache(command, returns)
+    cache_info_stub = stub()
+    cache_info_stub.expects(:gets).returns(returns)
+    cache_info_stub.expects(:close)
+    IO.expects(:popen).with(command).returns(cache_info_stub)
+  end
+
   context 'RsyncWithRemoteCache' do
     setup do
       @rwrc = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new
@@ -117,42 +124,37 @@ class CapistranoRsyncWithRemoteCacheTest &lt; Test::Unit::TestCase
     end
 
     context 'command' do
-      should 'purge and recreate local cache if it detects subversion info has changed' do
+      should 'purge local cache if it detects subversion info has changed' do
         stub_configuration(:scm =&gt; :subversion, :repository =&gt; 'repository')        
+        stub_detection_of_changed_local_cache(&quot;svn info .rsync_cache | sed -n 's/URL: //p'&quot;, &quot;URL: url\n&quot;)
+        FileUtils.expects(:rm_rf).with('.rsync_cache')
+        stub_creation_of_new_local_cache
 
-        svn_info_stub = stub()
-        svn_info_stub.expects(:gets).returns(&quot;URL: url\n&quot;)
-        svn_info_stub.expects(:close)
-        IO.expects(:popen).with(&quot;svn info .rsync_cache | sed -n 's/URL: //p'&quot;).returns(svn_info_stub)
+        @rwrc.send(:command)
+      end
 
+      should 'purge local cache if it detects git info has changed' do
+        stub_configuration(:scm =&gt; :git, :repository =&gt; 'repository')        
+        stub_detection_of_changed_local_cache(&quot;cd .rsync_cache &amp;&amp; git config remote.origin.url&quot;, &quot;beep\n&quot;)
         FileUtils.expects(:rm_rf).with('.rsync_cache')
-
         stub_creation_of_new_local_cache
 
         @rwrc.send(:command)
       end
 
-      should 'not attempt to purge and recreate local cache that does not exist' do
+      should 'not attempt to purge local cache that does not exist' do
         stub_configuration(:scm =&gt; :subversion, :repository =&gt; 'repository')        
-
-        svn_info_stub = stub()
-        svn_info_stub.expects(:gets).returns(nil)
-        svn_info_stub.expects(:close)
-        IO.expects(:popen).with(&quot;svn info .rsync_cache | sed -n 's/URL: //p'&quot;).returns(svn_info_stub)
-
+        stub_detection_of_changed_local_cache(&quot;svn info .rsync_cache | sed -n 's/URL: //p'&quot;, nil)
         FileUtils.expects(:rm_rf).with('.rsync_cache').never
-
         stub_creation_of_new_local_cache
 
         @rwrc.send(:command)
       end
 
-      should 'not attempt to purge and recreate local cache if the scm is not subversion' do
-        stub_configuration(:scm =&gt; :git, :repository =&gt; 'repository')        
-
-        IO.expects(:popen).with(&quot;svn info .rsync_cache | sed -n 's/URL: //p'&quot;).never
+      should 'not attempt to purge local cache if the scm is not supported by this gem' do
+        stub_configuration(:scm =&gt; :bzr, :repository =&gt; 'repository')        
+        stub_detection_of_changed_local_cache(&quot;echo repository&quot;, &quot;repository\n&quot;)
         FileUtils.expects(:rm_rf).with('.rsync_cache').never
-
         stub_creation_of_new_local_cache
 
         @rwrc.send(:command)</diff>
      <filename>test/capistrano_rsync_with_remote_cache_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>788f41ae3084d1f9029231a075828145ec06f2a1</id>
    </parent>
  </parents>
  <author>
    <name>Mark Cornick</name>
    <email>mcornick@gmail.com</email>
  </author>
  <url>http://github.com/vigetlabs/capistrano_rsync_with_remote_cache/commit/0e0da60f94eb83c9329358de426a544db677cfbf</url>
  <id>0e0da60f94eb83c9329358de426a544db677cfbf</id>
  <committed-date>2009-05-19T08:50:12-07:00</committed-date>
  <authored-date>2009-05-19T08:50:12-07:00</authored-date>
  <message>detect changed local cache for git as well as subversion</message>
  <tree>a5eb059ab0b33dade270a936b57bb4541c607f4a</tree>
  <committer>
    <name>Mark Cornick</name>
    <email>mcornick@gmail.com</email>
  </committer>
</commit>
