Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/taskgraph/run-task/run-task
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 8 additions & 12 deletions test/test_scripts_run_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import io
import os
import site
import stat
Expand Down Expand Up @@ -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,
Expand Down
Loading