Skip to content

Commit

Permalink
Merge pull request #2775 from pre-commit/called-process-error-trailin…
Browse files Browse the repository at this point in the history
…g-whitespace

fix trailing whitespace in CalledProcessError output
  • Loading branch information
asottile committed Feb 21, 2023
2 parents 192be60 + 4ded56e commit cdd3606
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pre_commit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
def __bytes__(self) -> bytes:
def _indent_or_none(part: bytes | None) -> bytes:
if part:
return b'\n ' + part.replace(b'\n', b'\n ')
return b'\n ' + part.replace(b'\n', b'\n ').rstrip()
else:
return b' (none)'

Expand Down
4 changes: 1 addition & 3 deletions tests/staged_files_only_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@ def test_failed_diff_does_not_discard_changes(in_git_dir, patch_dir):
r'stdout: \(none\)\n'
r'stderr:\n'
r' error: open\("1"\): Permission denied\n'
r' fatal: cannot hash 1\n'
# TODO: not sure why there's weird whitespace here
r' $',
r' fatal: cannot hash 1$',
).assert_matches(msg)

# even though it errored, the unstaged changes should still be present
Expand Down
2 changes: 1 addition & 1 deletion tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def test_CalledProcessError_str():
error = CalledProcessError(1, ('exe',), b'output', b'errors')
error = CalledProcessError(1, ('exe',), b'output\n', b'errors\n')
assert str(error) == (
"command: ('exe',)\n"
'return code: 1\n'
Expand Down

0 comments on commit cdd3606

Please sign in to comment.