Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: Don't swallow all push output #203

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 14 additions & 5 deletions revup/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import (
IO,
Any,
Callable,
Coroutine,
Dict,
List,
Expand Down Expand Up @@ -45,7 +46,10 @@ def merge_dicts(x: Dict[K, V], y: Dict[K, V]) -> Dict[K, V]:


async def process_stream(
proc_stream: Optional[asyncio.StreamReader], setting: _HANDLE, default_stream: IO[str]
proc_stream: Optional[asyncio.StreamReader],
setting: _HANDLE,
default_stream: IO[str],
transform: Optional[Callable],
) -> bytes:
# The things we do for logging...
#
Expand All @@ -69,13 +73,15 @@ async def process_stream(
except asyncio.IncompleteReadError as e:
line = e.partial
if not line:
if isinstance(setting, int) and setting != -1:
if isinstance(setting, int) and setting not in (-1, subprocess.PIPE, subprocess.STDOUT):
os.close(setting)
break
if transform:
line = transform(line)
if setting == subprocess.PIPE:
output.append(line)
elif setting == subprocess.STDOUT:
sys.stdout.buffer.write(line)
logging.info(line.decode("utf-8").strip())
elif isinstance(setting, int) and setting != -1:
os.write(setting, line)
elif setting is None:
Expand Down Expand Up @@ -137,6 +143,7 @@ async def create_sh_task(
input_str: Optional[str] = None,
stdin: _HANDLE = None,
stdout: _HANDLE = subprocess.PIPE,
output_transform: Optional[Callable] = None,
) -> Tuple[
Coroutine[Any, Any, None],
Coroutine[Any, Any, bytes],
Expand All @@ -163,8 +170,8 @@ async def create_sh_task(

return (
feed_input(ret.stdin, input_str),
process_stream(ret.stdout, stdout, sys.stdout),
process_stream(ret.stderr, stderr, sys.stderr),
process_stream(ret.stdout, stdout, sys.stdout, output_transform),
process_stream(ret.stderr, stderr, sys.stderr, output_transform),
ret.wait(),
)

Expand All @@ -179,6 +186,7 @@ async def sh(
stdout: _HANDLE = subprocess.PIPE,
raiseonerror: bool = True,
quiet: bool = False,
output_transform: Optional[Callable] = None,
) -> Tuple[int, str]:
"""
Run a command specified by args, and return string representing
Expand Down Expand Up @@ -210,6 +218,7 @@ async def sh(
input_str=input_str,
stdin=stdin,
stdout=stdout,
output_transform=output_transform,
)

_, out, err, ret = await asyncio.gather(*tasks)
Expand Down
7 changes: 6 additions & 1 deletion revup/topic_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,12 @@ async def push_git_refs(self, uploader: str, create_local_branches: bool) -> Non
self.git_ctx.remote_name,
*push_targets,
]
await self.git_ctx.git(*push_args, stderr=subprocess.PIPE)
await self.git_ctx.git(
*push_args,
stdout=subprocess.STDOUT,
stderr=subprocess.STDOUT,
output_transform=lambda l: b"" if l.startswith(b"remote: ") else l,
)

async def query_github(self) -> None:
"""
Expand Down
Loading