Skip to content

Commit 611fabd

Browse files
authored
Fix crash when viewing the divergence of a branch which is up to date with its upstream (#3918)
This was introduced by #3838, specifically by commit e675025. Fixes #3900 and #3917.
2 parents 4dadcd2 + f8073c7 commit 611fabd

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Diff for: pkg/gui/context/list_renderer.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ func (self *ListRenderer) insertNonModelItems(
121121
break
122122
}
123123
if item.Index+offset >= startIdx {
124-
padding := strings.Repeat(" ", columnPositions[item.Column])
124+
padding := ""
125+
if columnPositions != nil {
126+
padding = strings.Repeat(" ", columnPositions[item.Column])
127+
}
125128
lines = slices.Insert(lines, item.Index+offset-startIdx, padding+item.Content)
126129
}
127130
offset++
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var ShowDivergenceFromUpstreamNoDivergence = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Show divergence from upstream when the divergence view is empty",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("commit1")
15+
shell.CloneIntoRemote("origin")
16+
shell.SetBranchUpstream("master", "origin/master")
17+
},
18+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
19+
t.Views().Branches().
20+
Focus().
21+
Lines(Contains("master")).
22+
Press(keys.Branches.SetUpstream)
23+
24+
t.ExpectPopup().Menu().Title(Contains("Upstream")).Select(Contains("View divergence from upstream")).Confirm()
25+
26+
t.Views().SubCommits().
27+
IsFocused().
28+
Title(Contains("Commits (master <-> origin/master)")).
29+
Lines(
30+
Contains("--- Remote ---"),
31+
Contains("--- Local ---"),
32+
)
33+
},
34+
})

Diff for: pkg/integration/tests/test_list.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var tests = []*components.IntegrationTest{
6565
branch.SetUpstream,
6666
branch.ShowDivergenceFromBaseBranch,
6767
branch.ShowDivergenceFromUpstream,
68+
branch.ShowDivergenceFromUpstreamNoDivergence,
6869
branch.SortLocalBranches,
6970
branch.SortRemoteBranches,
7071
branch.SquashMerge,

0 commit comments

Comments
 (0)