From db1e79c1c5deb122aa3b05de8a83179dfae37446 Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Wed, 23 Oct 2019 01:46:32 +0000 Subject: [PATCH] Fix gclient crash with unicode strings in .gclient files. Older .gclient files might have explicit u'' strings in their specs; as part of upgrading code to Python3 compatibility, we apparently recently introduced a bug in the handling of this that might cause them to fail on Windows. This CL fixes that issue by ensuring that the GIT_DIR env var is always set to a regular string, regardless of whether the solution name was specified to be a regular string or a unicode string. Bug: 1016599 Change-Id: I295d220559eac20a2ced876672d5ccdb787a5338 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1874704 Reviewed-by: Edward Lesmes Commit-Queue: Dirk Pranke --- gclient_scm.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 30fac0700..8d311d4fd 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -1269,8 +1269,14 @@ class GitWrapper(SCMWrapper): # we don't accidentally go corrupting parent git checks too. See # https://crbug.com/1000825 for an example. if set_git_dir: - env.setdefault('GIT_DIR', os.path.abspath(os.path.join( - self.checkout_path, '.git'))) + + git_dir = os.path.abspath(os.path.join(self.checkout_path, '.git')) + + # Depending on how the .gclient file was defined, self.checkout_path + # might be set to a unicode string, not a regular string; on Windows + # Python2, we can't set env vars to be unicode strings, so we + # forcibly cast the value to a string before setting it. + env.setdefault('GIT_DIR', str(git_dir)) ret = subprocess2.check_output( ['git'] + args, env=env, **kwargs).decode('utf-8') if strip: