Skip to content

Commit

Permalink
Don't show branch heads in reflog subcommits
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stefanhaller committed Jul 31, 2023
1 parent 6dc25d7 commit f5c9764
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/gui/context/branches_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ func (self *BranchesContext) GetDiffTerminals() []string {
}
return nil
}

func (self *BranchesContext) ShowBranchHeadsInSubCommits() bool {
return true
}
4 changes: 4 additions & 0 deletions pkg/gui/context/reflog_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ func (self *ReflogCommitsContext) GetDiffTerminals() []string {

return []string{itemId}
}

func (self *ReflogCommitsContext) ShowBranchHeadsInSubCommits() bool {
return false
}
4 changes: 4 additions & 0 deletions pkg/gui/context/remote_branches_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ func (self *RemoteBranchesContext) GetDiffTerminals() []string {

return []string{itemId}
}

func (self *RemoteBranchesContext) ShowBranchHeadsInSubCommits() bool {
return true
}
17 changes: 15 additions & 2 deletions pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/context/tags_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ func (self *TagsContext) GetDiffTerminals() []string {

return []string{itemId}
}

func (self *TagsContext) ShowBranchHeadsInSubCommits() bool {
return true
}
2 changes: 2 additions & 0 deletions pkg/gui/controllers/switch_to_sub_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var _ types.IController = &SwitchToSubCommitsController{}
type CanSwitchToSubCommits interface {
types.Context
GetSelectedRef() types.Ref
ShowBranchHeadsInSubCommits() bool
}

type SwitchToSubCommitsController struct {
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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"),
)
})
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ var tests = []*components.IntegrationTest{
patch_building.StartNewPatch,
reflog.Checkout,
reflog.CherryPick,
reflog.DoNotShowBranchMarkersInReflogSubcommits,
reflog.Patch,
reflog.Reset,
staging.DiffContextChange,
Expand Down

0 comments on commit f5c9764

Please sign in to comment.