From 1b3fdb18e370de39e95c969f480aeea9d7b2eac1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Sep 2018 01:57:21 -0500 Subject: [PATCH] fix: change subprocess.Popen calls to work on Linux too (#14689) * fix: remove 'shell=True' when calling 'git diff' Calling subprocess.Popen() with a list of args and shell=True causes the args to be ignored, so ['git', 'diff', '--name-only', '--staged'] was turning into just 'git'. Instead of getting a list of changed files, we got the --help message. Two possible fixes: change it from a list to a single string, or remove 'shell=True'. The shell doesn't seem to be needed, so I chose that. More reading: https://stackoverflow.com/questions/26417658/subprocess-call-arguments-ignored-when-using-shell-true-w-list * fix: remove 'shell=True' when calling clang-format Same problem / rationale as previous commit. * fix: re-add shell=True for win; use different fix --- script/run-clang-format.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/script/run-clang-format.py b/script/run-clang-format.py index a14d56938477..9c2bc7fa3045 100644 --- a/script/run-clang-format.py +++ b/script/run-clang-format.py @@ -107,11 +107,11 @@ def run_clang_format_diff(args, file_name): invocation = [args.clang_format_executable, file_name] try: proc = subprocess.Popen( - invocation, + ' '.join(invocation), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, - shell = True) + shell=True) except OSError as exc: raise DiffError(str(exc)) proc_stdout = proc.stdout @@ -253,10 +253,10 @@ def main(): parse_files = [] if args.changed: popen = subprocess.Popen( - ["git", "diff", "--name-only", "--cached"], + 'git diff --name-only --cached', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - shell = True + shell=True ) for line in popen.stdout: file_name = line.rstrip()