Fix git cl on windows for git-numberer repos.
Git cl decides if git-numberer is enabled on a repository by writing
Gerrit's project.config from refs/meta/config into a tempfile, which is
then queried using `git config -f tempfile --get ...`. The file itself
is only flushed, but not closed after writing because Python's
tempfile.NamedTemporaryFile is deleted on closing. This worked fine on
Linix/Mac, but not on Windows, where `git config` apparently doesn't see
file or its contents.
This CL rewrites the above using yet another contexmanager temp
directory into which a file is written and closed before git config is
ran.
R=machenbach@chromium.org,grt@chromium.org
BUG=683202
Change-Id: I7974d66b1b2b0478ab4b6f7ac04e547a4981c46c
Reviewed-on: https://chromium-review.googlesource.com/430719
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: Vadim Shtayura <vadimsh@chromium.org>
diff --git a/gclient_utils.py b/gclient_utils.py
index c21a3fd..d46dbd1 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -5,6 +5,7 @@
"""Generic utils."""
import codecs
+import contextlib
import cStringIO
import datetime
import logging
@@ -143,6 +144,16 @@
f.write(content)
+@contextlib.contextmanager
+def temporary_directory(**kwargs):
+ tdir = tempfile.mkdtemp(**kwargs)
+ try:
+ yield tdir
+ finally:
+ if tdir:
+ rmtree(tdir)
+
+
def safe_rename(old, new):
"""Renames a file reliably.