Fix hook disable logic in gclient_scm (non-atomic os.rename on Windows)

crrev.com/348703002 has introduced some code into gclient_scm.py which
disables the .git/hooks when gclient is running in managed mode.
The disabling logic renames the individual hook files to hook.disabled
using os.rename. Conversely to what happen on Posix OSs, on Windows
os.rename does not have atomic rename semantics [1] and it fails if the
destination file already exists.
This change improves the hook disable logic.

[1] See https://bugs.python.org/issue8828 and os.replace in Python 3

BUG=474218

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294715 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_scm.py b/gclient_scm.py
index c6e9b68..8115dc8 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -318,8 +318,10 @@
       return
     for f in os.listdir(hook_dir):
       if not f.endswith('.sample') and not f.endswith('.disabled'):
-        os.rename(os.path.join(hook_dir, f),
-                  os.path.join(hook_dir, f + '.disabled'))
+        disabled_hook_path = os.path.join(hook_dir, f + '.disabled')
+        if os.path.exists(disabled_hook_path):
+          os.remove(disabled_hook_path)
+        os.rename(os.path.join(hook_dir, f), disabled_hook_path)
 
   def update(self, options, args, file_list):
     """Runs git to update or transparently checkout the working copy.