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/git_cl.py b/git_cl.py
index f11cee8..1a62794 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -23,7 +23,6 @@
import re
import stat
import sys
-import tempfile
import textwrap
import traceback
import urllib
@@ -973,20 +972,19 @@
return False
# Gerrit's project.config is really a git config file.
# So, parse it as such.
- with tempfile.NamedTemporaryFile(prefix='git_cl_proj_config') as f:
- f.write(project_config_data)
- # Make sure OS sees this, but don't close the file just yet,
- # as NamedTemporaryFile deletes it on closing.
- f.flush()
+ with gclient_utils.temporary_directory() as tempdir:
+ project_config_file = os.path.join(tempdir, 'project.config')
+ gclient_utils.FileWrite(project_config_file, project_config_data)
def get_opts(x):
code, out = cls._run_git_with_code(
- ['config', '-f', f.name, '--get-all',
+ ['config', '-f', project_config_file, '--get-all',
'plugin.git-numberer.validate-%s-refglob' % x])
if code == 0:
return out.strip().splitlines()
return []
enabled, disabled = map(get_opts, ['enabled', 'disabled'])
+
logging.info('validator config enabled %s disabled %s refglobs for '
'(this ref: %s)', enabled, disabled, ref)