diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index bef06c3d8..79966ebc8 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -57,12 +57,13 @@ func getBranchDisplayStrings( checkedOutByWorkTree := git_commands.CheckedOutByOtherWorktree(b, worktrees) showCommitHash := fullDescription || userConfig.Gui.ShowBranchCommitHash branchStatus := BranchStatus(b, itemOperation, tr, now, userConfig) + divergence := divergenceStr(b, itemOperation, tr, userConfig) worktreeIcon := lo.Ternary(icons.IsIconEnabled(), icons.LINKED_WORKTREE_ICON, fmt.Sprintf("(%s)", tr.LcWorktree)) // Recency is always three characters, plus one for the space availableWidth := viewWidth - 4 - if len(branchStatus) > 0 { - availableWidth -= utils.StringWidth(utils.Decolorise(branchStatus)) + 1 + if len(divergence) > 0 { + availableWidth -= utils.StringWidth(divergence) + 1 } if icons.IsIconEnabled() { availableWidth -= 2 // one for the icon, one for the space @@ -73,6 +74,11 @@ func getBranchDisplayStrings( if checkedOutByWorkTree { availableWidth -= utils.StringWidth(worktreeIcon) + 1 } + paddingNeededForDivergence := availableWidth + + if len(branchStatus) > 0 { + availableWidth -= utils.StringWidth(utils.Decolorise(branchStatus)) + 1 + } displayName := b.Name if b.DisplayName != "" { @@ -114,6 +120,13 @@ func getBranchDisplayStrings( res = append(res, utils.ShortHash(b.CommitHash)) } + if divergence != "" { + paddingNeededForDivergence -= utils.StringWidth(utils.Decolorise(coloredName)) - 1 + if paddingNeededForDivergence > 0 { + coloredName += strings.Repeat(" ", paddingNeededForDivergence) + coloredName += style.FgCyan.Sprint(divergence) + } + } res = append(res, coloredName) if fullDescription { @@ -185,16 +198,23 @@ func BranchStatus( } } - if userConfig.Gui.ShowDivergenceFromBaseBranch != "none" { + return result +} + +func divergenceStr( + branch *models.Branch, + itemOperation types.ItemOperation, + tr *i18n.TranslationSet, + userConfig *config.UserConfig, +) string { + result := "" + if ItemOperationToString(itemOperation, tr) == "" && userConfig.Gui.ShowDivergenceFromBaseBranch != "none" { behind := branch.BehindBaseBranch.Load() if behind != 0 { - if result != "" { - result += " " - } if userConfig.Gui.ShowDivergenceFromBaseBranch == "arrowAndNumber" { - result += style.FgCyan.Sprintf("↓%d", behind) + result += fmt.Sprintf("↓%d", behind) } else { - result += style.FgCyan.Sprintf("↓") + result += "↓" } } } diff --git a/pkg/gui/presentation/branches_test.go b/pkg/gui/presentation/branches_test.go index 01910f119..347802a6e 100644 --- a/pkg/gui/presentation/branches_test.go +++ b/pkg/gui/presentation/branches_test.go @@ -113,11 +113,11 @@ func Test_getBranchDisplayStrings(t *testing.T) { }, itemOperation: types.ItemOperationNone, fullDescription: false, - viewWidth: 100, + viewWidth: 20, useIcons: false, checkedOutByWorktree: false, showDivergenceCfg: "onlyArrow", - expected: []string{"1m", "branch_name ↓"}, + expected: []string{"1m", "branch_name ↓"}, }, { branch: &models.Branch{ @@ -130,11 +130,11 @@ func Test_getBranchDisplayStrings(t *testing.T) { }, itemOperation: types.ItemOperationNone, fullDescription: false, - viewWidth: 100, + viewWidth: 22, useIcons: false, checkedOutByWorktree: false, showDivergenceCfg: "arrowAndNumber", - expected: []string{"1m", "branch_name ✓ ↓2"}, + expected: []string{"1m", "branch_name ✓ ↓2"}, }, { branch: &models.Branch{ @@ -147,11 +147,11 @@ func Test_getBranchDisplayStrings(t *testing.T) { }, itemOperation: types.ItemOperationNone, fullDescription: false, - viewWidth: 100, + viewWidth: 26, useIcons: false, checkedOutByWorktree: false, showDivergenceCfg: "arrowAndNumber", - expected: []string{"1m", "branch_name ↓5↑3 ↓2"}, + expected: []string{"1m", "branch_name ↓5↑3 ↓2"}, }, { branch: &models.Branch{Name: "branch_name", Recency: "1m"}, @@ -240,6 +240,23 @@ func Test_getBranchDisplayStrings(t *testing.T) { showDivergenceCfg: "none", expected: []string{"1m", "branch_… ✓"}, }, + { + branch: &models.Branch{ + Name: "branch_name", + Recency: "1m", + UpstreamRemote: "origin", + AheadForPull: "3", + BehindForPull: "5", + BehindBaseBranch: makeAtomic(4), + }, + itemOperation: types.ItemOperationNone, + fullDescription: false, + viewWidth: 21, + useIcons: false, + checkedOutByWorktree: false, + showDivergenceCfg: "arrowAndNumber", + expected: []string{"1m", "branch_n… ↓5↑3 ↓4"}, + }, { branch: &models.Branch{ Name: "branch_name", diff --git a/pkg/integration/tests/branch/rebase_onto_base_branch.go b/pkg/integration/tests/branch/rebase_onto_base_branch.go index 0617c936b..8514e4f09 100644 --- a/pkg/integration/tests/branch/rebase_onto_base_branch.go +++ b/pkg/integration/tests/branch/rebase_onto_base_branch.go @@ -32,7 +32,7 @@ var RebaseOntoBaseBranch = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Branches(). Focus(). Lines( - Contains("feature ↓1").IsSelected(), + MatchesRegexp(`feature\s+↓1`).IsSelected(), Contains("master"), ). Press(keys.Branches.RebaseBranch) diff --git a/pkg/integration/tests/branch/show_divergence_from_base_branch.go b/pkg/integration/tests/branch/show_divergence_from_base_branch.go index 95e51370e..2903b7837 100644 --- a/pkg/integration/tests/branch/show_divergence_from_base_branch.go +++ b/pkg/integration/tests/branch/show_divergence_from_base_branch.go @@ -25,7 +25,7 @@ var ShowDivergenceFromBaseBranch = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Branches(). Focus(). Lines( - Contains("feature ↓1").IsSelected(), + MatchesRegexp(`feature\s+↓1`).IsSelected(), Contains("master"), ). Press(keys.Branches.SetUpstream) diff --git a/pkg/integration/tests/status/show_divergence_from_base_branch.go b/pkg/integration/tests/status/show_divergence_from_base_branch.go deleted file mode 100644 index 141108683..000000000 --- a/pkg/integration/tests/status/show_divergence_from_base_branch.go +++ /dev/null @@ -1,27 +0,0 @@ -package status - -import ( - "github.com/jesseduffield/lazygit/pkg/config" - . "github.com/jesseduffield/lazygit/pkg/integration/components" -) - -var ShowDivergenceFromBaseBranch = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Show divergence from base branch in the status panel", - ExtraCmdArgs: []string{}, - Skip: false, - SetupConfig: func(config *config.AppConfig) { - config.GetUserConfig().Gui.ShowDivergenceFromBaseBranch = "arrowAndNumber" - }, - SetupRepo: func(shell *Shell) { - shell.CreateNCommits(2) - shell.CloneIntoRemote("origin") - shell.NewBranch("feature") - shell.HardReset("HEAD^") - }, - Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.GlobalPress(keys.Universal.NextBlock) - - t.Views().Status(). - Content(Equals("↓1 repo → feature")) - }, -}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 57d7a05d0..3e94d39ea 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -373,7 +373,6 @@ var tests = []*components.IntegrationTest{ status.ClickWorkingTreeStateToOpenRebaseOptionsMenu, status.LogCmd, status.LogCmdStatusPanelAllBranchesLog, - status.ShowDivergenceFromBaseBranch, submodule.Add, submodule.Enter, submodule.EnterNested,