瀏覽代碼

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
primiano@chromium.org 10 年之前
父節點
當前提交
4126556b4a
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      gclient_scm.py

+ 4 - 2
gclient_scm.py

@@ -318,8 +318,10 @@ class GitWrapper(SCMWrapper):
       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.