Don't show branch heads in reflog subcommits

It's tricky to get this right for reflog commits wrt what's the current branch
for each one; so just disable it entirely here, it's probably not something
anybody needs here.
This commit is contained in:
Stefan Haller 2023-07-25 11:33:39 +02:00
parent 6dc25d796b
commit f5c9764dd2
8 changed files with 105 additions and 2 deletions

View file

@ -83,3 +83,7 @@ func (self *BranchesContext) GetDiffTerminals() []string {
}
return nil
}
func (self *BranchesContext) ShowBranchHeadsInSubCommits() bool {
return true
}

View file

@ -86,3 +86,7 @@ func (self *ReflogCommitsContext) GetDiffTerminals() []string {
return []string{itemId}
}
func (self *ReflogCommitsContext) ShowBranchHeadsInSubCommits() bool {
return false
}

View file

@ -72,3 +72,7 @@ func (self *RemoteBranchesContext) GetDiffTerminals() []string {
return []string{itemId}
}
func (self *RemoteBranchesContext) ShowBranchHeadsInSubCommits() bool {
return true
}

View file

@ -51,10 +51,14 @@ func NewSubCommitsContext(
selectedCommitSha = selectedCommit.Sha
}
}
branches := []*models.Branch{}
if viewModel.GetShowBranchHeads() {
branches = c.Model().Branches
}
return presentation.GetCommitListDisplayStrings(
c.Common,
c.Model().SubCommits,
c.Model().Branches,
branches,
viewModel.GetRef().RefName(),
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(),
@ -106,7 +110,8 @@ type SubCommitsViewModel struct {
ref types.Ref
*ListViewModel[*models.Commit]
limitCommits bool
limitCommits bool
showBranchHeads bool
}
func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
@ -117,6 +122,14 @@ func (self *SubCommitsViewModel) GetRef() types.Ref {
return self.ref
}
func (self *SubCommitsViewModel) SetShowBranchHeads(value bool) {
self.showBranchHeads = value
}
func (self *SubCommitsViewModel) GetShowBranchHeads() bool {
return self.showBranchHeads
}
func (self *SubCommitsContext) GetSelectedItemId() string {
item := self.GetSelected()
if item == nil {

View file

@ -69,3 +69,7 @@ func (self *TagsContext) GetDiffTerminals() []string {
return []string{itemId}
}
func (self *TagsContext) ShowBranchHeadsInSubCommits() bool {
return true
}

View file

@ -11,6 +11,7 @@ var _ types.IController = &SwitchToSubCommitsController{}
type CanSwitchToSubCommits interface {
types.Context
GetSelectedRef() types.Ref
ShowBranchHeadsInSubCommits() bool
}
type SwitchToSubCommitsController struct {
@ -79,6 +80,7 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
subCommitsContext.SetTitleRef(ref.Description())
subCommitsContext.SetRef(ref)
subCommitsContext.SetLimitCommits(true)
subCommitsContext.SetShowBranchHeads(self.context.ShowBranchHeadsInSubCommits())
subCommitsContext.ClearSearchString()
subCommitsContext.GetView().ClearSearch()

View file

@ -0,0 +1,71 @@
package reflog
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DoNotShowBranchMarkersInReflogSubcommits = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Verify that no branch heads are shown in the subcommits view of a reflog entry",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.NewBranch("branch1")
shell.EmptyCommit("one")
shell.EmptyCommit("two")
shell.NewBranch("branch2")
shell.EmptyCommit("three")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
// Check that the local commits view does show a branch marker for branch1
t.Views().Commits().
Lines(
Contains("CI three"),
Contains("CI * two"),
Contains("CI one"),
)
t.Views().Branches().
Focus().
// Check out branch1
NavigateToLine(Contains("branch1")).
PressPrimaryAction().
// Look at the subcommits of branch2
NavigateToLine(Contains("branch2")).
PressEnter().
// Check that we see a marker for branch1 here (but not for
// branch2), even though branch1 is checked out
Tap(func() {
t.Views().SubCommits().
IsFocused().
Lines(
Contains("CI three"),
Contains("CI * two"),
Contains("CI one"),
).
PressEscape()
}).
// Check out branch2 again
NavigateToLine(Contains("branch2")).
PressPrimaryAction()
t.Views().ReflogCommits().
Focus().
TopLines(
Contains("checkout: moving from branch1 to branch2").IsSelected(),
).
PressEnter().
// Check that the subcommits view for a reflog entry doesn't show
// any branch markers
Tap(func() {
t.Views().SubCommits().
IsFocused().
Lines(
Contains("CI three"),
Contains("CI two"),
Contains("CI one"),
)
})
},
})

View file

@ -163,6 +163,7 @@ var tests = []*components.IntegrationTest{
patch_building.StartNewPatch,
reflog.Checkout,
reflog.CherryPick,
reflog.DoNotShowBranchMarkersInReflogSubcommits,
reflog.Patch,
reflog.Reset,
staging.DiffContextChange,