Improve SVN.Revert() to catch more corner cases.

Add a unit test to catch potential regressions. Remove an old test new code broke.

TEST=unit tests
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@76805 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/scm.py b/scm.py
index 2690f1f..471b9d7 100644
--- a/scm.py
+++ b/scm.py
@@ -878,21 +878,26 @@
 
       # svn revert is really stupid. It fails on inconsistent line-endings,
       # on switched directories, etc. So take no chance and delete everything!
-      if file_status[0][0] == 'D':
-        # Deleted file requires manual intervention and require calling
+      if file_status[0][0] in ('D', 'A') or file_status[0][2] != ' ':
+        # Added, deleted file requires manual intervention and require calling
         # revert, like for properties.
-        gclient_utils.CheckCall(
-            ['svn', 'revert', file_status[1]], cwd=repo_root)
+        try:
+          SVN.Capture(['revert', file_status[1]], cwd=repo_root)
+        except gclient_utils.CheckCallError:
+          if not os.path.exists(file_path):
+            continue
+          raise
+
+      if not os.path.exists(file_path):
+        continue
+
+      if os.path.isfile(file_path) or os.path.islink(file_path):
+        logging.info('os.remove(%s)' % file_path)
+        os.remove(file_path)
+      elif os.path.isdir(file_path):
+        logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
+        gclient_utils.RemoveDirectory(file_path)
       else:
-        if not os.path.exists(file_path):
-          pass
-        elif os.path.isfile(file_path) or os.path.islink(file_path):
-          logging.info('os.remove(%s)' % file_path)
-          os.remove(file_path)
-        elif os.path.isdir(file_path):
-          logging.info('gclient_utils.RemoveDirectory(%s)' % file_path)
-          gclient_utils.RemoveDirectory(file_path)
-        else:
-          logging.critical(
-            ('No idea what is %s.\nYou just found a bug in gclient'
-             ', please ping maruel@chromium.org ASAP!') % file_path)
+        logging.critical(
+          ('No idea what is %s.\nYou just found a bug in gclient'
+            ', please ping maruel@chromium.org ASAP!') % file_path)