mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
include stash in commitish controller
This commit is contained in:
parent
e842d1bc9e
commit
a643957f89
13 changed files with 135 additions and 113 deletions
|
@ -86,6 +86,16 @@ func (self *LocalCommitsContext) CanRebase() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (self *LocalCommitsContext) GetSelectedRefName() string {
|
||||
item := self.GetSelected()
|
||||
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return item.RefName()
|
||||
}
|
||||
|
||||
func (self *LocalCommitsViewModel) GetItemsLength() int {
|
||||
return len(self.getModel())
|
||||
}
|
||||
|
|
|
@ -62,6 +62,16 @@ func (self *ReflogCommitsContext) CanRebase() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (self *ReflogCommitsContext) GetSelectedRefName() string {
|
||||
item := self.GetSelected()
|
||||
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return item.RefName()
|
||||
}
|
||||
|
||||
type ReflogCommitsViewModel struct {
|
||||
*traits.ListCursor
|
||||
getModel func() []*models.Commit
|
||||
|
|
|
@ -58,6 +58,20 @@ func (self *StashContext) GetSelectedItemId() string {
|
|||
return item.ID()
|
||||
}
|
||||
|
||||
func (self *StashContext) CanRebase() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *StashContext) GetSelectedRefName() string {
|
||||
item := self.GetSelected()
|
||||
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return item.RefName()
|
||||
}
|
||||
|
||||
type StashViewModel struct {
|
||||
*traits.ListCursor
|
||||
getModel func() []*models.StashEntry
|
||||
|
|
|
@ -63,6 +63,16 @@ func (self *SubCommitsContext) CanRebase() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (self *SubCommitsContext) GetSelectedRefName() string {
|
||||
item := self.GetSelected()
|
||||
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return item.RefName()
|
||||
}
|
||||
|
||||
type SubCommitsViewModel struct {
|
||||
*traits.ListCursor
|
||||
getModel func() []*models.Commit
|
||||
|
|
82
pkg/gui/controllers/commitish_controller.go
Normal file
82
pkg/gui/controllers/commitish_controller.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
// This controller is for all contexts that contain commit files.
|
||||
|
||||
type CommitishControllerFactory struct {
|
||||
controllerCommon *controllerCommon
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error
|
||||
}
|
||||
|
||||
var _ types.IController = &CommitishController{}
|
||||
|
||||
type Commitish interface {
|
||||
types.Context
|
||||
CanRebase() bool
|
||||
GetSelectedRefName() string
|
||||
}
|
||||
|
||||
type CommitishController struct {
|
||||
baseController
|
||||
*controllerCommon
|
||||
context Commitish
|
||||
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error
|
||||
}
|
||||
|
||||
func NewCommitishControllerFactory(
|
||||
common *controllerCommon,
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error,
|
||||
) *CommitishControllerFactory {
|
||||
return &CommitishControllerFactory{
|
||||
controllerCommon: common,
|
||||
viewFiles: viewFiles,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommitishControllerFactory) Create(context Commitish) *CommitishController {
|
||||
return &CommitishController{
|
||||
baseController: baseController{},
|
||||
controllerCommon: self.controllerCommon,
|
||||
context: context,
|
||||
viewFiles: self.viewFiles,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommitishController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.checkSelected(self.enter),
|
||||
Description: self.c.Tr.LcViewItemFiles,
|
||||
},
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *CommitishController) checkSelected(callback func(string) error) func() error {
|
||||
return func() error {
|
||||
refName := self.context.GetSelectedRefName()
|
||||
if refName == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return callback(refName)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommitishController) enter(refName string) error {
|
||||
return self.viewFiles(SwitchToCommitFilesContextOpts{
|
||||
RefName: refName,
|
||||
CanRebase: self.context.CanRebase(),
|
||||
Context: self.context,
|
||||
})
|
||||
}
|
||||
|
||||
func (self *CommitishController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type CommonCommitControllerFactory struct {
|
||||
controllerCommon *controllerCommon
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error
|
||||
}
|
||||
|
||||
var _ types.IController = &CommonCommitController{}
|
||||
|
||||
type CommitContext interface {
|
||||
types.Context
|
||||
CanRebase() bool
|
||||
GetSelected() *models.Commit
|
||||
}
|
||||
|
||||
type CommonCommitController struct {
|
||||
baseController
|
||||
*controllerCommon
|
||||
context CommitContext
|
||||
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error
|
||||
}
|
||||
|
||||
func NewCommonCommitControllerFactory(
|
||||
common *controllerCommon,
|
||||
viewFiles func(SwitchToCommitFilesContextOpts) error,
|
||||
) *CommonCommitControllerFactory {
|
||||
return &CommonCommitControllerFactory{
|
||||
controllerCommon: common,
|
||||
viewFiles: viewFiles,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommonCommitControllerFactory) Create(context CommitContext) *CommonCommitController {
|
||||
return &CommonCommitController{
|
||||
baseController: baseController{},
|
||||
controllerCommon: self.controllerCommon,
|
||||
context: context,
|
||||
viewFiles: self.viewFiles,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommonCommitController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.checkSelected(self.enter),
|
||||
Description: self.c.Tr.LcViewCommitFiles,
|
||||
},
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *CommonCommitController) checkSelected(callback func(*models.Commit) error) func() error {
|
||||
return func() error {
|
||||
commit := self.context.GetSelected()
|
||||
if commit == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return callback(commit)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommonCommitController) enter(commit *models.Commit) error {
|
||||
return self.viewFiles(SwitchToCommitFilesContextOpts{
|
||||
RefName: commit.Sha,
|
||||
CanRebase: self.context.CanRebase(),
|
||||
Context: self.context,
|
||||
})
|
||||
}
|
||||
|
||||
func (self *CommonCommitController) Context() types.Context {
|
||||
return self.context
|
||||
}
|
|
@ -580,17 +580,18 @@ func (gui *Gui) resetControllers() {
|
|||
controllers.AttachControllers(context, switchToSubCommitsControllerFactory.Create(context))
|
||||
}
|
||||
|
||||
commonCommitControllerFactory := controllers.NewCommonCommitControllerFactory(
|
||||
commitishControllerFactory := controllers.NewCommitishControllerFactory(
|
||||
common,
|
||||
gui.SwitchToCommitFilesContext,
|
||||
)
|
||||
|
||||
for _, context := range []controllers.CommitContext{
|
||||
for _, context := range []controllers.Commitish{
|
||||
gui.State.Contexts.LocalCommits,
|
||||
gui.State.Contexts.ReflogCommits,
|
||||
gui.State.Contexts.SubCommits,
|
||||
gui.State.Contexts.Stash,
|
||||
} {
|
||||
controllers.AttachControllers(context, commonCommitControllerFactory.Create(context))
|
||||
controllers.AttachControllers(context, commitishControllerFactory.Create(context))
|
||||
}
|
||||
|
||||
controllers.AttachControllers(gui.State.Contexts.Branches, branchesController, gitFlowController)
|
||||
|
|
|
@ -430,12 +430,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
|||
Handler: self.handleCopySelectedSideContextItemToClipboard,
|
||||
Description: self.c.Tr.LcCopyCommitShaToClipboard,
|
||||
},
|
||||
{
|
||||
ViewName: "stash",
|
||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
||||
Handler: self.handleViewStashFiles,
|
||||
Description: self.c.Tr.LcViewStashFiles,
|
||||
},
|
||||
{
|
||||
ViewName: "stash",
|
||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||
|
|
|
@ -2,7 +2,6 @@ package gui
|
|||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
|
@ -114,19 +113,6 @@ func (gui *Gui) postStashRefresh() error {
|
|||
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleViewStashFiles() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return gui.SwitchToCommitFilesContext(controllers.SwitchToCommitFilesContextOpts{
|
||||
RefName: stashEntry.RefName(),
|
||||
CanRebase: false,
|
||||
Context: gui.State.Contexts.Stash,
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleNewBranchOffStashEntry() error {
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
|
|
|
@ -245,7 +245,7 @@ func chineseTranslationSet() TranslationSet {
|
|||
CheckingOutStatus: "检出",
|
||||
CommittingStatus: "正在提交",
|
||||
CommitFiles: "提交文件",
|
||||
LcViewCommitFiles: "查看提交的文件",
|
||||
LcViewItemFiles: "查看提交的文件",
|
||||
CommitFilesTitle: "提交文件",
|
||||
LcCheckoutCommitFile: "检出文件",
|
||||
LcDiscardOldFileChange: "放弃对此文件的提交更改",
|
||||
|
@ -380,7 +380,6 @@ func chineseTranslationSet() TranslationSet {
|
|||
UnstageLinesTitle: "未暂存的行",
|
||||
UnstageLinesPrompt: "您确定要删除所选的行(git reset)吗?这是不可逆的。\n要禁用此对话框,请将 'gui.skipUnstageLineWarning' 的配置键设置为 true",
|
||||
LcCreateNewBranchFromCommit: "从提交创建新分支",
|
||||
LcViewStashFiles: "查看贮藏条目中的文件",
|
||||
LcBuildingPatch: "正在构建补丁",
|
||||
LcViewCommits: "查看提交",
|
||||
MinGitVersionError: "Git 版本必须至少为 2.0(即从 2014 年开始)。请升级您的 git 版本。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。",
|
||||
|
|
|
@ -214,7 +214,7 @@ func dutchTranslationSet() TranslationSet {
|
|||
RedoingStatus: "redoing",
|
||||
CheckingOutStatus: "uitchecken",
|
||||
CommitFiles: "Commit bestanden",
|
||||
LcViewCommitFiles: "bekijk gecommite bestanden",
|
||||
LcViewItemFiles: "bekijk gecommite bestanden",
|
||||
CommitFilesTitle: "Commit bestanden",
|
||||
LcCheckoutCommitFile: "bestand uitchecken",
|
||||
LcDiscardOldFileChange: "uitsluit deze commit zijn veranderingen aan dit bestand",
|
||||
|
@ -357,7 +357,6 @@ func dutchTranslationSet() TranslationSet {
|
|||
LcAddSubmodule: "voeg nieuwe submodule toe",
|
||||
LcInitSubmodule: "initialiseer submodule",
|
||||
LcViewBulkSubmoduleOptions: "bekijk bulk submodule opties",
|
||||
LcViewStashFiles: "bekijk bestanden van stash entry",
|
||||
CreatePullRequestOptions: "Bekijk opties voor pull-aanvraag",
|
||||
LcCreatePullRequestOptions: "bekijk opties voor pull-aanvraag",
|
||||
ConfirmRevertCommit: "Weet u zeker dat u {{.selectedCommit}} ongedaan wilt maken?",
|
||||
|
|
|
@ -231,7 +231,7 @@ type TranslationSet struct {
|
|||
CheckingOutStatus string
|
||||
CommittingStatus string
|
||||
CommitFiles string
|
||||
LcViewCommitFiles string
|
||||
LcViewItemFiles string
|
||||
CommitFilesTitle string
|
||||
LcCheckoutCommitFile string
|
||||
LcDiscardOldFileChange string
|
||||
|
@ -375,7 +375,6 @@ type TranslationSet struct {
|
|||
UnstageLinesTitle string
|
||||
UnstageLinesPrompt string
|
||||
LcCreateNewBranchFromCommit string
|
||||
LcViewStashFiles string
|
||||
LcBuildingPatch string
|
||||
LcViewCommits string
|
||||
MinGitVersionError string
|
||||
|
@ -804,7 +803,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||
CheckingOutStatus: "checking out",
|
||||
CommittingStatus: "committing",
|
||||
CommitFiles: "Commit files",
|
||||
LcViewCommitFiles: "view commit's files",
|
||||
LcViewItemFiles: "view selected item's files",
|
||||
CommitFilesTitle: "Commit Files",
|
||||
LcCheckoutCommitFile: "checkout file",
|
||||
LcDiscardOldFileChange: "discard this commit's changes to this file",
|
||||
|
@ -949,7 +948,6 @@ func EnglishTranslationSet() TranslationSet {
|
|||
UnstageLinesTitle: "Unstage lines",
|
||||
UnstageLinesPrompt: "Are you sure you want to delete the selected lines (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipUnstageLineWarning' to true",
|
||||
LcCreateNewBranchFromCommit: "create new branch off of commit",
|
||||
LcViewStashFiles: "view stash entry's files",
|
||||
LcBuildingPatch: "building patch",
|
||||
LcViewCommits: "view commits",
|
||||
MinGitVersionError: "Git version must be at least 2.0 (i.e. from 2014 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.",
|
||||
|
|
|
@ -175,7 +175,7 @@ func polishTranslationSet() TranslationSet {
|
|||
AmendingStatus: "poprawianie",
|
||||
CherryPickingStatus: "przebieranie",
|
||||
CommitFiles: "Pliki commita",
|
||||
LcViewCommitFiles: "przeglądaj pliki commita",
|
||||
LcViewItemFiles: "przeglądaj pliki commita",
|
||||
CommitFilesTitle: "Pliki commita",
|
||||
LcCheckoutCommitFile: "plik wybierania",
|
||||
LcDiscardOldFileChange: "porzuć zmiany commita dla tego pliku",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue