Commit 4126556b authored by primiano@chromium.org's avatar primiano@chromium.org

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
parent e8bc1aa8
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment