[depot_tools] Use git fetch to optimize the properly configured that use git-svn
in the way <http://code.google.com/p/chromium/wiki/UsingNewGit#Initial_checkout>
describes.

R=maruel@chromium.org
TEST=gclient sync with safesync_url is faster.
BUG=109184


Review URL: http://codereview.chromium.org/9379005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@121988 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py
index c0c8728..581b273 100755
--- a/tests/gclient_scm_test.py
+++ b/tests/gclient_scm_test.py
@@ -1188,10 +1188,17 @@
     gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='1'
         ).AndReturn(self.fake_hash_1)
     gclient_scm.scm.GIT.GetSha1ForSvnRev(cwd=self.base_path, rev='3'
-        ).AndReturn(self.fake_hash_2)
+        ).MultipleTimes().AndReturn(self.fake_hash_2)
 
     # Ensure that we call git svn fetch if our LKGR is > the git-svn HEAD rev.
     self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
+    gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
+                                cwd=self.base_path).AndReturn('blah')
+    gclient_scm.scm.GIT.Capture(['fetch'], cwd=self.base_path)
+    gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
+    error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr')
+    gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'],
+                                cwd=self.base_path).AndRaise(error)
     gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path)
 
     self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
@@ -1211,15 +1218,20 @@
 
     git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
                                     relpath=self.relpath)
-    # Without an existing checkout, this should fail. TODO(dbeam) Fix this.
+    # Without an existing checkout, this should fail.
+    # TODO(dbeam) Fix this. http://crbug.com/109184
     self.assertRaises(gclient_scm.gclient_utils.Error,
                       git_svn_scm.GetUsableRev, '1', options)
     # Given an SVN revision with a git-svn checkout, it should be translated to
     # a git sha1 and be usable.
     self.assertEquals(git_svn_scm.GetUsableRev('1', options),
                       self.fake_hash_1)
-    # Our fake HEAD rev is r2, so this should call git svn fetch to get more
-    # revs (pymox will complain if this doesn't happen).
+    # Our fake HEAD rev is r2, so this should call git fetch and git svn fetch
+    # to get more revs (pymox will complain if this doesn't happen). We mock an
+    # optimized checkout the first time, so this run should call git fetch.
+    self.assertEquals(git_svn_scm.GetUsableRev('3', options),
+                      self.fake_hash_2)
+    # The time we pretend we're not optimized, so no git fetch should fire.
     self.assertEquals(git_svn_scm.GetUsableRev('3', options),
                       self.fake_hash_2)
     # Given a git sha1 with a git-svn checkout, it should be used as is.