1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-27 23:08:02 +02:00

Don't try to shorten branch names that are already 3 characters or less

This fixes a potential crash when the available width is very small and the
branch name is one to three characters long.
This commit is contained in:
Stefan Haller 2024-01-13 14:10:34 +01:00
parent 080aa78266
commit 36e57d16bd
2 changed files with 29 additions and 1 deletions

View File

@ -78,7 +78,8 @@ func getBranchDisplayStrings(
nameTextStyle = theme.DiffTerminalColor
}
if len(displayName) > availableWidth {
// Don't bother shortening branch names that are already 3 characters or less
if len(displayName) > utils.Max(availableWidth, 3) {
// Never shorten the branch name to less then 3 characters
len := utils.Max(availableWidth, 4)
displayName = displayName[:len-1] + "…"

View File

@ -176,6 +176,33 @@ func Test_getBranchDisplayStrings(t *testing.T) {
checkedOutByWorktree: false,
expected: []string{"1m", "branc… Pushing |"},
},
{
branch: &models.Branch{Name: "abc", Recency: "1m"},
itemOperation: types.ItemOperationPushing,
fullDescription: false,
viewWidth: -1,
useIcons: false,
checkedOutByWorktree: false,
expected: []string{"1m", "abc Pushing |"},
},
{
branch: &models.Branch{Name: "ab", Recency: "1m"},
itemOperation: types.ItemOperationPushing,
fullDescription: false,
viewWidth: -1,
useIcons: false,
checkedOutByWorktree: false,
expected: []string{"1m", "ab Pushing |"},
},
{
branch: &models.Branch{Name: "a", Recency: "1m"},
itemOperation: types.ItemOperationPushing,
fullDescription: false,
viewWidth: -1,
useIcons: false,
checkedOutByWorktree: false,
expected: []string{"1m", "a Pushing |"},
},
{
branch: &models.Branch{
Name: "branch_name",