Skip to content

Commit 8167610

Browse files
committed
git: Don't swallow all push output
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
1 parent 159f964 commit 8167610

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

revup/shell.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import (
99
IO,
1010
Any,
11+
Callable,
1112
Coroutine,
1213
Dict,
1314
List,
@@ -45,7 +46,10 @@ def merge_dicts(x: Dict[K, V], y: Dict[K, V]) -> Dict[K, V]:
4546

4647

4748
async def process_stream(
48-
proc_stream: Optional[asyncio.StreamReader], setting: _HANDLE, default_stream: IO[str]
49+
proc_stream: Optional[asyncio.StreamReader],
50+
setting: _HANDLE,
51+
default_stream: IO[str],
52+
transform: Optional[Callable[[bytes], bytes]],
4953
) -> bytes:
5054
# The things we do for logging...
5155
#
@@ -68,14 +72,16 @@ async def process_stream(
6872
line = await proc_stream.readexactly(e.consumed)
6973
except asyncio.IncompleteReadError as e:
7074
line = e.partial
75+
if transform:
76+
line = transform(line)
7177
if not line:
72-
if isinstance(setting, int) and setting != -1:
78+
if isinstance(setting, int) and setting not in (-1, subprocess.PIPE, subprocess.STDOUT):
7379
os.close(setting)
7480
break
7581
if setting == subprocess.PIPE:
7682
output.append(line)
7783
elif setting == subprocess.STDOUT:
78-
sys.stdout.buffer.write(line)
84+
logging.info(line.decode("utf-8").strip())
7985
elif isinstance(setting, int) and setting != -1:
8086
os.write(setting, line)
8187
elif setting is None:
@@ -137,6 +143,7 @@ async def create_sh_task(
137143
input_str: Optional[str] = None,
138144
stdin: _HANDLE = None,
139145
stdout: _HANDLE = subprocess.PIPE,
146+
output_transform: Optional[Callable[[bytes], bytes]] = None,
140147
) -> Tuple[
141148
Coroutine[Any, Any, None],
142149
Coroutine[Any, Any, bytes],
@@ -163,8 +170,8 @@ async def create_sh_task(
163170

164171
return (
165172
feed_input(ret.stdin, input_str),
166-
process_stream(ret.stdout, stdout, sys.stdout),
167-
process_stream(ret.stderr, stderr, sys.stderr),
173+
process_stream(ret.stdout, stdout, sys.stdout, output_transform),
174+
process_stream(ret.stderr, stderr, sys.stderr, output_transform),
168175
ret.wait(),
169176
)
170177

@@ -179,6 +186,7 @@ async def sh(
179186
stdout: _HANDLE = subprocess.PIPE,
180187
raiseonerror: bool = True,
181188
quiet: bool = False,
189+
output_transform: Optional[Callable[[bytes], bytes]] = None,
182190
) -> Tuple[int, str]:
183191
"""
184192
Run a command specified by args, and return string representing
@@ -210,6 +218,7 @@ async def sh(
210218
input_str=input_str,
211219
stdin=stdin,
212220
stdout=stdout,
221+
output_transform=output_transform,
213222
)
214223

215224
_, out, err, ret = await asyncio.gather(*tasks)

revup/topic_stack.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,13 @@ async def push_git_refs(self, uploader: str, create_local_branches: bool) -> Non
10391039
self.git_ctx.remote_name,
10401040
*push_targets,
10411041
]
1042-
await self.git_ctx.git(*push_args, stderr=subprocess.PIPE)
1042+
await self.git_ctx.git(
1043+
*push_args,
1044+
stdout=subprocess.STDOUT,
1045+
stderr=subprocess.STDOUT,
1046+
# Hide the remote output that says "Create a pull request for '' on GitHub"
1047+
output_transform=lambda l: b"" if l.startswith(b"remote: ") else l,
1048+
)
10431049

10441050
async def query_github(self) -> None:
10451051
"""

0 commit comments

Comments
 (0)