From f8073c7188159c699563f2cf9b8aaea7bcbccdf8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 16 Sep 2024 20:50:31 +0200 Subject: [PATCH] Fix crash when viewing the divergence of a branch which is up to date with its upstream This was introduced by #3838, specifically by commit e675025411. Add a regression test that would have crashed without the fix. --- pkg/gui/context/list_renderer.go | 5 ++- ..._divergence_from_upstream_no_divergence.go | 34 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 pkg/integration/tests/branch/show_divergence_from_upstream_no_divergence.go diff --git a/pkg/gui/context/list_renderer.go b/pkg/gui/context/list_renderer.go index b89eccf8b22..06fc69b0c0e 100644 --- a/pkg/gui/context/list_renderer.go +++ b/pkg/gui/context/list_renderer.go @@ -121,7 +121,10 @@ func (self *ListRenderer) insertNonModelItems( break } if item.Index+offset >= startIdx { - padding := strings.Repeat(" ", columnPositions[item.Column]) + padding := "" + if columnPositions != nil { + padding = strings.Repeat(" ", columnPositions[item.Column]) + } lines = slices.Insert(lines, item.Index+offset-startIdx, padding+item.Content) } offset++ diff --git a/pkg/integration/tests/branch/show_divergence_from_upstream_no_divergence.go b/pkg/integration/tests/branch/show_divergence_from_upstream_no_divergence.go new file mode 100644 index 00000000000..5b446fcb83b --- /dev/null +++ b/pkg/integration/tests/branch/show_divergence_from_upstream_no_divergence.go @@ -0,0 +1,34 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ShowDivergenceFromUpstreamNoDivergence = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Show divergence from upstream when the divergence view is empty", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("commit1") + shell.CloneIntoRemote("origin") + shell.SetBranchUpstream("master", "origin/master") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines(Contains("master")). + Press(keys.Branches.SetUpstream) + + t.ExpectPopup().Menu().Title(Contains("Upstream")).Select(Contains("View divergence from upstream")).Confirm() + + t.Views().SubCommits(). + IsFocused(). + Title(Contains("Commits (master <-> origin/master)")). + Lines( + Contains("--- Remote ---"), + Contains("--- Local ---"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 301a5a53035..db79247ffea 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -65,6 +65,7 @@ var tests = []*components.IntegrationTest{ branch.SetUpstream, branch.ShowDivergenceFromBaseBranch, branch.ShowDivergenceFromUpstream, + branch.ShowDivergenceFromUpstreamNoDivergence, branch.SortLocalBranches, branch.SortRemoteBranches, branch.SquashMerge,