diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index cc48b499e..2265fadf5 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -597,27 +597,18 @@ def _clean_git_checkout(destination_path): "-nxdff", ] print_line(b"vcs", b"executing %r\n" % args) - p = subprocess.Popen( + p = subprocess.run( args, - # Disable buffering because we want to receive output - # as it is generated so timestamps in logs are - # accurate. - bufsize=0, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - stdin=sys.stdin.fileno(), + encoding="latin1", cwd=destination_path, env=os.environ, + check=True, ) - stdout = io.TextIOWrapper(p.stdout, encoding="latin1") - ret = p.wait() - if ret: - sys.exit(ret) - data = stdout.read() prefix = "Would remove " filenames = [ os.path.join(destination_path, line[len(prefix) :]) - for line in data.splitlines() + for line in p.stdout.splitlines() ] print_line(b"vcs", b"removing %r\n" % filenames) for filename in filenames: diff --git a/test/test_scripts_run_task.py b/test/test_scripts_run_task.py index ccba1a440..f88c7ebeb 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -1,5 +1,4 @@ import functools -import io import os import site import stat @@ -293,23 +292,20 @@ def test_clean_git_checkout(monkeypatch, mock_stdin, run_task_mod): output_str = ( f"{prefix}{untracked_dir_rel_path}/\n{prefix}{untracked_file_rel_path}\n" ) - output_bytes = output_str.encode("latin1") - output = io.BytesIO(output_bytes) + + real_popen = subprocess.Popen def _Popen( args, - bufsize=None, - stdout=None, - stderr=None, - stdin=None, - cwd=None, - env=None, **kwargs, ): - return Mock( - stdout=output, - wait=lambda: 0, + kwargs["stdin"] = subprocess.PIPE + proc = real_popen( + ["cat"], + **kwargs, ) + proc.stdin.write(output_str) + return proc monkeypatch.setattr( subprocess,