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:
commit
53acbc8f18
@ -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] + "…"
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user