Skip to content

fix: strip trailing newlines from show line output#500

Merged
shcheklein merged 1 commit into
iterative:mainfrom
w3lld1:fix/454-strip-show-line-newlines
Jul 9, 2026
Merged

fix: strip trailing newlines from show line output#500
shcheklein merged 1 commit into
iterative:mainfrom
w3lld1:fix/454-strip-show-line-newlines

Conversation

@w3lld1

@w3lld1 w3lld1 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #454 by normalizing gto show single-line outputs so tag/ref/version values that already contain trailing CR/LF characters do not produce an extra blank line in CLI output.

Changes

  • Strip trailing \r/\n from values emitted through format_echo(..., \"line\") and format_echo(..., \"lines\").
  • Keep Click's normal single terminating newline for terminal-friendly output.
  • Add a regression test covering gto show --ref and gto show --version when returned values contain trailing newlines.

Verification

  • pytest tests/test_cli.py::test_show_line_flags_strip_value_newlines tests/test_cli.py::test_commands tests/test_cli.py::test_show_ref_flag_not_applicable -q
  • pytest -q
    • 189 passed, 1 warning
  • python -m py_compile gto/*.py
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an output-normalization issue in the CLI where gto show single-line outputs could contain an extra blank line when the underlying value already ended with \r/\n, by stripping trailing newline characters before emitting via Click.

Changes:

  • Add a small helper to strip trailing \r/\n from values printed via format_echo(..., "line") and format_echo(..., "lines").
  • Update format_echo to use the normalization helper for the line/lines formats.
  • Add a regression test covering gto show --ref and gto show --version when returned values include trailing CR/LF.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
gto/utils.py Normalizes line/lines output by stripping trailing CR/LF before click.echo, preventing extra blank lines.
tests/test_cli.py Adds regression coverage ensuring gto show --ref/--version emits exactly one trailing newline even if values contain CR/LF.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shcheklein

Copy link
Copy Markdown
Member

@w3lld1 please TAL / resolve and fix. Thanks for the contribution.

@w3lld1 w3lld1 force-pushed the fix/454-strip-show-line-newlines branch from d5dc743 to 058e029 Compare July 9, 2026 21:58
@w3lld1

w3lld1 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased this onto current main, resolved the conflict with the adjacent show-version test, and fixed the ruff-format failure. Local validation now passes: python -m pytest tests/test_cli.py::test_show_line_flag_empty_result tests/test_cli.py::test_show_line_flags_strip_value_newlines -q and pre-commit run --all-files.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@shcheklein shcheklein merged commit 4ffc873 into iterative:main Jul 9, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gto show returns tag names with a \n newline at the end.

4 participants