1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00

Fix crash with short branch names (#3219)

This commit is contained in:
Stefan Haller 2024-01-15 13:28:36 +01:00 committed by GitHub
commit 53acbc8f18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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",