summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/branches_context.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/context/branches_context.go')
-rw-r--r--pkg/gui/context/branches_context.go53
1 files changed, 33 insertions, 20 deletions
diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go
index a3e404fdb..1d6453c13 100644
--- a/pkg/gui/context/branches_context.go
+++ b/pkg/gui/context/branches_context.go
@@ -1,8 +1,8 @@
package context
import (
- "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -11,40 +11,40 @@ type BranchesContext struct {
*ListContextTrait
}
-var _ types.IListContext = (*BranchesContext)(nil)
-
-func NewBranchesContext(
- getModel func() []*models.Branch,
- view *gocui.View,
- getDisplayStrings func(startIdx int, length int) [][]string,
+var (
+ _ types.IListContext = (*BranchesContext)(nil)
+ _ types.DiffableContext = (*BranchesContext)(nil)
+)
- onFocus func(types.OnFocusOpts) error,
- onRenderToMain func() error,
- onFocusLost func(opts types.OnFocusLostOpts) error,
+func NewBranchesContext(c *ContextCommon) *BranchesContext {
+ viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches })
- c *types.HelperCommon,
-) *BranchesContext {
- viewModel := NewBasicViewModel(getModel)
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetBranchListDisplayStrings(
+ c.Model().Branches,
+ c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
+ c.Modes().Diffing.Ref,
+ c.Tr,
+ )
+ }
- return &BranchesContext{
+ self := &BranchesContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- View: view,
+ View: c.Views().Branches,
WindowName: "branches",
Key: LOCAL_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
Focusable: true,
- }), ContextCallbackOpts{
- OnFocus: onFocus,
- OnFocusLost: onFocusLost,
- OnRenderToMain: onRenderToMain,
- }),
+ })),
list: viewModel,
getDisplayStrings: getDisplayStrings,
c: c,
},
}
+
+ return self
}
func (self *BranchesContext) GetSelectedItemId() string {
@@ -63,3 +63,16 @@ func (self *BranchesContext) GetSelectedRef() types.Ref {
}
return branch
}
+
+func (self *BranchesContext) GetDiffTerminals() []string {
+ // for our local branches we want to include both the branch and its upstream
+ branch := self.GetSelected()
+ if branch != nil {
+ names := []string{branch.ID()}
+ if branch.IsTrackingRemote() {
+ names = append(names, branch.ID()+"@{u}")
+ }
+ return names
+ }
+ return nil
+}