fix-issue-12328: fix commit messages truncation in the CLI#12448
fix-issue-12328: fix commit messages truncation in the CLI#12448Byron merged 4 commits intogitbutlerapp:masterfrom
Conversation
|
@gonchihernandez is attempting to deploy a commit to the GitButler Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Updates the legacy but status CLI rendering to truncate commit messages, PR titles, and the common-base line based on detected terminal width (with an ellipsis suffix), instead of using fixed .take(N) limits.
Changes:
- Added
terminal_width()(80-col fallback) andtruncate_text()(adds…on truncation). - Replaced fixed-length truncation for commit messages, PR titles, and common merge base message with terminal-width-based truncation.
- Added in-module unit tests covering
truncate_text()behavior.
Byron
left a comment
There was a problem hiding this comment.
Thanks a lot for making your first contribution!
What I like is that there are before/after screenshots, that's very helpful.
The PR description is too wordy to me and if I suspect it's waltzed out by AI I am not going to read it. This makes me wonder if I am missing anything by not reading "Possible Improvements", but for now let me assume that you will suggest follow-ups based on what you feel is needed.
Lastly, I truly think that the estimations have to be turned into knowledge for precise numbers for how much of the line is left for the comment.
Thanks again for making commit message handling 🙏.
PS: For commits, we use message(#issue-number)
7a196f3 to
a567eaa
Compare
a567eaa to
aeac27d
Compare
Thanks a lot for the response and the guidance! I did a commit amend to use the message(#number-issue) and did the respective changes! While working on this I noticed we now have three places doing terminal width + truncation — truncate_string() in tui/table.rs, an inline closure in help.rs, and this new truncate_text(). I think it might be worth pulling them into a shared util so we stop reinventing it. Thanks again for the review! I am happy :) |
aeac27d to
acd5840
Compare
acd5840 to
9866b3c
Compare
9866b3c to
76aff01
Compare
76aff01 to
ae5d72b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
crates/but/src/command/legacy/status/mod.rs:1096
- There are multiple trailing blank lines at the end of the file; this tends to get reverted by
rustfmtand creates noisy diffs. Consider trimming the file to a single newline at EOF.
crates/but/src/tui/table.rs:211 - There are a couple of extra blank lines at the end of this module after removing the old helpers. Trimming them will keep the file consistent with
rustfmtoutput and reduce diff noise.
|
@Byron I've been working a little bit more on the requested changes, also added the improvements on a separate commit and added an explanation into the Pr description. |
Review Notes
|
b2bc9ea to
2fd7953
Compare
Show an elipsis instead of wrapping.
|
@gonchihernandez Sorry for sending you down the prefix route, as I now believe this was the wrong call for being unmaintainable. The goal here is to use the available width of the terminal to show more of the commit message. However, the prefix computations, which in theory would have to be handled for each and every command for consistency, seems like an impossible chore at the great expense of maintainability. So I am going to see if the new pager implementation is suitable to allow not truncating at all. |
That way, users see more without any perceived disadvantage.
This might be controversial, but it's worth a try now that we have `less -FXRS` paging. This is a bit of a 'problem' for `but status -v` as that makes the pager likely to kick in, and using `S` is needed for the pager to kick in when there is horizontal overshoot. Generally, I think we'd never want wrapping as it destroys our layout. Also I noticed that my environment has `LESS` set, so I was initially confused about the pager not working like I think we need it. But if that ever is a problem, we might be able to get to using `minus` as built-in pager and configure it, or disrespect the user pager settings.
|
And here is the result: Generally all code that truncates now does so properly, aware of asian languages and ANSI codes. Overall, this is a cleanup PR, with an easily revertable change to enable paging for No pager allowed via
|

🎫 Affected issues
Fixes: #12328
🧢 Changes
but statustruncate_text()helper that appends…when text is truncatedterminal_width()helper (reusing the existingterminal_sizecrate dependency).crates/but/src/command/legacy/status/mod.rs:CommitMessage::display_cli): was.take(50), now usesterminal_width() - 15ForgeReview::display_cli): was.take(50), now usesterminal_width() - 25..take(40), now usesterminal_width() - 40…when text is shortened, instead of silently cutting offForgeReview::display_cliwheretrim_end_matcheswould strip the…suffix — moved the trim to run on the raw title before truncationtruncate_texthelper inline, following the project convention of keeping unit tests for private functions in-module☕️ Reasoning
Commit messages longer than 50 characters were silently truncated in
but statusregardless of terminal width. For example, on a 120-column terminal:Before:
After:
The truncation limit now adapts to the actual terminal width, and whenever truncation occurs, an
…character clearly indicates that the message continues. This follows the same patterns already used incrates/but/src/tui/table.rsandcrates/but/src/command/help.rs.🧪 Manual testing
cargo build -p butbut setupbut statuson a wide terminal (~120 cols) → full message should be visible.but statuson a narrow terminal (~60 cols) → message should be truncated with….but statuswith a short commit message → no truncation, no….┴line) also truncates with…on narrow terminals.rm -rf ~/but-truncation-test🔭 Improvements (out of scope for this PR) changes made in this commit
Shared text truncation —
tui::textSame "detect terminal width and shorten text" logic was in five places.
Now it's in one:
crates/but/src/tui/text.rs.Also fixed a panic in
help.rs(byte-slicing non-ASCII) and wrong widthmeasurements in
oplog.rs/pick.rs(char count vs display columns).🎬 Demo
Before:

After: