Revert of Another attempt: gclient: delete mismatching checkouts (https://codereview.chromium.org/183283003/)

Reason for revert:
Broke `gclient sync` for me, failing with:

Error: 1> Can't update/checkout /Volumes/MacintoshHD2/src/chrome-git/src if an unversioned directory is present. Delete the directory and try again.


For someone else, it broke it with:

% gclient sync

________ unmanaged solution; skipping src

Error: Command svn info --xml returned non-zero exit status 1 in /Users/pawliger/chromium/src/.

<?xml version="1.0" encoding="UTF-8"?>

<info>

svn: E155007: '/Users/pawliger/chromium/src' is not a working copy

Original issue's description:
> Another attempt: gclient: delete mismatching checkouts
> 
> Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=255930

TBR=iannucci@chromium.org,szager@chromium.org,maruel@chromium.org,mmoss@chromium.org,borenet@google.com
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/192323006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@256005 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py
index 1bb0efd..a0a0887 100755
--- a/tests/gclient_scm_test.py
+++ b/tests/gclient_scm_test.py
@@ -135,6 +135,7 @@
 
   def testRunCommandException(self):
     options = self.Options(verbose=False)
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
 
     self.mox.ReplayAll()
@@ -155,6 +156,7 @@
     gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
         ).AndReturn('1.5.1')
     # It'll to a checkout instead.
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
     # Checkout.
     gclient_scm.os.path.exists(self.base_path).AndReturn(False)
@@ -186,6 +188,7 @@
     gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
     # Checkout.
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(False)
     parent = gclient_scm.os.path.dirname(self.base_path)
@@ -311,6 +314,7 @@
     file_info.url = self.url
     file_info.uuid = 'ABC'
     file_info.revision = 42
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
     # Checkout.
     gclient_scm.os.path.exists(self.base_path).AndReturn(False)
@@ -343,9 +347,8 @@
       'UUID': 'ABC',
       'Revision': 42,
     }
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
 
     # Checkout or update.
@@ -390,9 +393,8 @@
       'UUID': 'ABC',
       'Revision': 42,
     }
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
 
     # Checkout or update.
@@ -427,9 +429,8 @@
       'UUID': 'ABC',
       'Revision': 42,
     }
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
 
     # Checkout or update.
@@ -494,9 +495,8 @@
         file_list=files_list)
 
     # Now we fall back on scm.update().
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
     gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
     gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
@@ -565,9 +565,8 @@
         file_list=files_list)
 
     # Now we fall back on scm.update().
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
     gclient_scm.scm.SVN._CaptureInfo(
         [], join(self.base_path, ".")).AndReturn(file_info)
@@ -602,9 +601,8 @@
 
     # Now we fall back on scm.update().
     files_list = self.mox.CreateMockAnything()
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(True)
     gclient_scm.scm.SVN._CaptureInfo(
         [], join(self.base_path, '.')).AndReturn(file_info)
@@ -622,75 +620,20 @@
 
   def testUpdateGit(self):
     options = self.Options(verbose=True)
-    file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
-    gclient_scm.os.path.exists(file_path).AndReturn(False)
-    gclient_scm.os.path.exists(self.base_path).AndReturn(True)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
-    error = gclient_scm.subprocess2.CalledProcessError(
-        1, 'cmd', '/cwd', 'stdout', 'stderr')
-    gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
-
-    self.mox.ReplayAll()
-    scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
-                            relpath=self.relpath)
-    error = ('Can\'t update/checkout %s if an unversioned directory is '
-             'present. Delete the directory and try again.' % self.base_path)
-    self.assertRaisesError(error, scm.update, options, None, [])
-
-  def testUpdateGitForce(self):
-    options = self.Options(verbose=True, force=True)
-    file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
-    gclient_scm.os.path.exists(file_path).AndReturn(False)
-    gclient_scm.os.path.exists(self.base_path).AndReturn(True)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
-    error = gclient_scm.subprocess2.CalledProcessError(
-        1, 'cmd', '/cwd', 'stdout', 'stderr')
-    gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
-    gclient_scm.gclient_utils.rmtree(self.base_path)
-    gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
-    gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
-        ).AndReturn('1.5.1')
-    gclient_scm.scm.SVN.RunAndGetFileList(
-        options.verbose,
-        ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
-        cwd=self.root_dir,
-        file_list=[])
-
-    gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
-        ).AndReturn({'Revision': 100})
+    file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
+    gclient_scm.os.path.exists(file_path).AndReturn(True)
 
     self.mox.ReplayAll()
     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
                             relpath=self.relpath)
     file_list = []
-    scm.update(options, None, file_list)
-    self.checkstdout('Removing troublesome path %s\n' % self.base_path)
-
-  def testUpdateGitSvn(self):
-    options = self.Options(verbose=True)
-    file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
-    gclient_scm.os.path.exists(file_path).AndReturn(False)
-    gclient_scm.os.path.exists(self.base_path).AndReturn(True)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
-    gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
-    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
-    gclient_scm.scm.GIT.Capture(['config', '--local', '--get',
-                                 'svn-remote.svn.url'],
-                                cwd=self.base_path).AndReturn(self.url)
-
-    self.mox.ReplayAll()
-    scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
-                            relpath=self.relpath)
-    file_list = []
-    scm.update(options, [], file_list)
+    scm.update(options, self.args, file_list)
     self.checkstdout(
-        ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath)
-        )
+        ('________ found .git directory; skipping %s\n' % self.relpath))
 
   def testUpdateHg(self):
     options = self.Options(verbose=True)
+    gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
 
     self.mox.ReplayAll()
@@ -1255,63 +1198,6 @@
     self.assertRaises(gclient_scm.gclient_utils.Error,
                       git_svn_scm.GetUsableRev, too_big, options)
 
-  def testUpdateNoDotGit(self):
-    options = self.Options()
-
-    gclient_scm.os.path.exists(self.base_path).AndReturn(True)
-    gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
-    gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
-                               ).AndReturn(False)
-    gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
-    gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
-                               ).AndReturn(False)
-
-    self.mox.ReplayAll()
-    scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
-                            relpath=self.relpath)
-    error = ('\n____ %s at refs/remotes/origin/master\n\tPath is not a git '
-             'repo. No .git dir.\n\tTo resolve:\n\t\trm -rf %s\n\tAnd run '
-             'gclient sync again\n\tOr run with --force\n' % (self.relpath,
-                                                              self.relpath))
-    self.assertRaisesError(error, scm.update, options, None, [])
-
-  def testUpdateNoDotGitForce(self):
-    options = self.Options(force=True)
-
-    gclient_scm.os.path.exists(self.base_path).AndReturn(True)
-    gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
-    gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
-                               ).AndReturn(False)
-    gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
-    gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
-                               ).AndReturn(False)
-    gclient_scm.gclient_utils.rmtree(self.base_path)
-    self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
-    # pylint: disable=E1120
-    gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
-                                  options)
-    # pylint: disable=E1120
-    self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig',
-                             True)
-    gclient_scm.GitWrapper.UpdateSubmoduleConfig()
-    self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
-    gclient_scm.subprocess2.check_output(['git', 'ls-files'],
-                                         cwd=self.base_path,
-                                         stderr=gclient_scm.subprocess2.VOID,
-                                         ).AndReturn('')
-    gclient_scm.subprocess2.check_output(
-        ['git', 'rev-parse', '--verify', 'HEAD'],
-        cwd=self.base_path,
-        stderr=gclient_scm.subprocess2.VOID,
-        ).AndReturn('')
-
-    self.mox.ReplayAll()
-    scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
-                            relpath=self.relpath)
-    scm.update(options, None, [])
-    self.checkstdout('_____ Conflicting directory found in %s. Removing.\n\n'
-                     % self.base_path)
-
 
 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
   def testUpdateUpdate(self):