Skip to content

Commit

Permalink
git: Don't swallow all push output
Browse files Browse the repository at this point in the history
In certain situations "git push" will need to auth interactively. However
we don't show the user any output from git push because of github's automatic
"create a pr test" that is generally not what we want since revup handles pr
creation. This does make these auth situations confusing though.

Instead of hiding all output, default to showing output except for lines prefixed
with "remote:" which will get hidden.

Topic: outpush3
Closes: #33
Reviewers: aaron, brian-k
  • Loading branch information
jerry-skydio committed Dec 28, 2024
1 parent c7b92e8 commit f3377df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
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 @@ -68,14 +72,16 @@ async def process_stream(
line = await proc_stream.readexactly(e.consumed)
except asyncio.IncompleteReadError as e:
line = e.partial
if transform:
line = transform(line)
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 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
8 changes: 7 additions & 1 deletion revup/topic_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,13 @@ 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,
# Hide the remote output that says "Create a pull request for '' on GitHub"
output_transform=lambda l: b"" if l.startswith(b"remote: ") else l,
)

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

0 comments on commit f3377df

Please sign in to comment.