Skip to content

Commit 75e72ca

Browse files
tonyclaude
andcommitted
fix(run): Restore bytes mode to preserve carriage returns for in-place progress updates
why: Commit 80b480e switched to text=True which interfered with carriage return handling, causing git progress output to appear on separate lines instead of overwriting the same line. what: - Revert subprocess to text=False (bytes mode) - Restore console_to_str() function for proper bytes-to-string conversion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4f85cd7 commit 75e72ca

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/libvcs/_internal/run.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222

2323
logger = logging.getLogger(__name__)
2424

25+
console_encoding = sys.stdout.encoding
26+
27+
28+
def console_to_str(s: bytes) -> str:
29+
"""From pypa/pip project, pip.backwardwardcompat. License MIT."""
30+
try:
31+
return s.decode(console_encoding)
32+
except UnicodeDecodeError:
33+
return s.decode("utf_8")
34+
except AttributeError: # for tests, #13
35+
return str(s)
36+
2537

2638
if t.TYPE_CHECKING:
2739
_LoggerAdapter = logging.LoggerAdapter[logging.Logger]
@@ -182,7 +194,7 @@ def progress_cb(output, timestamp):
182194
restore_signals=restore_signals,
183195
start_new_session=start_new_session,
184196
pass_fds=pass_fds,
185-
text=True,
197+
text=False, # Keep in bytes mode to preserve \r properly
186198
encoding=encoding,
187199
errors=errors,
188200
user=user,
@@ -213,25 +225,17 @@ def progress_cb(output: t.AnyStr, timestamp: datetime.datetime) -> None:
213225
code = proc.poll()
214226

215227
if callback and callable(callback) and proc.stderr is not None:
216-
line = str(proc.stderr.read(128))
228+
line = console_to_str(proc.stderr.read(128))
217229
if line:
218230
callback(output=line, timestamp=datetime.datetime.now())
219231
if callback and callable(callback):
220232
callback(output="\r", timestamp=datetime.datetime.now())
221233

222-
lines = (
223-
filter(None, (line.strip() for line in proc.stdout.readlines()))
224-
if proc.stdout is not None
225-
else []
226-
)
227-
all_output = "\n".join(lines)
234+
lines = filter(None, (line.strip() for line in proc.stdout.readlines()))
235+
all_output = console_to_str(b"\n".join(lines))
228236
if code:
229-
stderr_lines = (
230-
filter(None, (line.strip() for line in proc.stderr.readlines()))
231-
if proc.stderr is not None
232-
else []
233-
)
234-
all_output = "".join(stderr_lines)
237+
stderr_lines = filter(None, (line.strip() for line in proc.stderr.readlines()))
238+
all_output = console_to_str(b"".join(stderr_lines))
235239
output = "".join(all_output)
236240
if code != 0 and check_returncode:
237241
raise exc.CommandError(

0 commit comments

Comments
 (0)