mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-09 01:17:06 +02:00
include stash in commitish controller
This commit is contained in:
@ -86,6 +86,16 @@ func (self *LocalCommitsContext) CanRebase() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *LocalCommitsContext) GetSelectedRefName() string {
|
||||||
|
item := self.GetSelected()
|
||||||
|
|
||||||
|
if item == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return item.RefName()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *LocalCommitsViewModel) GetItemsLength() int {
|
func (self *LocalCommitsViewModel) GetItemsLength() int {
|
||||||
return len(self.getModel())
|
return len(self.getModel())
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,16 @@ func (self *ReflogCommitsContext) CanRebase() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *ReflogCommitsContext) GetSelectedRefName() string {
|
||||||
|
item := self.GetSelected()
|
||||||
|
|
||||||
|
if item == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return item.RefName()
|
||||||
|
}
|
||||||
|
|
||||||
type ReflogCommitsViewModel struct {
|
type ReflogCommitsViewModel struct {
|
||||||
*traits.ListCursor
|
*traits.ListCursor
|
||||||
getModel func() []*models.Commit
|
getModel func() []*models.Commit
|
||||||
|
@ -58,6 +58,20 @@ func (self *StashContext) GetSelectedItemId() string {
|
|||||||
return item.ID()
|
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 {
|
type StashViewModel struct {
|
||||||
*traits.ListCursor
|
*traits.ListCursor
|
||||||
getModel func() []*models.StashEntry
|
getModel func() []*models.StashEntry
|
||||||
|
@ -63,6 +63,16 @@ func (self *SubCommitsContext) CanRebase() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SubCommitsContext) GetSelectedRefName() string {
|
||||||
|
item := self.GetSelected()
|
||||||
|
|
||||||
|
if item == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return item.RefName()
|
||||||
|
}
|
||||||
|
|
||||||
type SubCommitsViewModel struct {
|
type SubCommitsViewModel struct {
|
||||||
*traits.ListCursor
|
*traits.ListCursor
|
||||||
getModel func() []*models.Commit
|
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))
|
controllers.AttachControllers(context, switchToSubCommitsControllerFactory.Create(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
commonCommitControllerFactory := controllers.NewCommonCommitControllerFactory(
|
commitishControllerFactory := controllers.NewCommitishControllerFactory(
|
||||||
common,
|
common,
|
||||||
gui.SwitchToCommitFilesContext,
|
gui.SwitchToCommitFilesContext,
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, context := range []controllers.CommitContext{
|
for _, context := range []controllers.Commitish{
|
||||||
gui.State.Contexts.LocalCommits,
|
gui.State.Contexts.LocalCommits,
|
||||||
gui.State.Contexts.ReflogCommits,
|
gui.State.Contexts.ReflogCommits,
|
||||||
gui.State.Contexts.SubCommits,
|
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)
|
controllers.AttachControllers(gui.State.Contexts.Branches, branchesController, gitFlowController)
|
||||||
|
@ -430,12 +430,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
|||||||
Handler: self.handleCopySelectedSideContextItemToClipboard,
|
Handler: self.handleCopySelectedSideContextItemToClipboard,
|
||||||
Description: self.c.Tr.LcCopyCommitShaToClipboard,
|
Description: self.c.Tr.LcCopyCommitShaToClipboard,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "stash",
|
|
||||||
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
|
||||||
Handler: self.handleViewStashFiles,
|
|
||||||
Description: self.c.Tr.LcViewStashFiles,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
ViewName: "stash",
|
ViewName: "stash",
|
||||||
Key: opts.GetKey(opts.Config.Universal.Select),
|
Key: opts.GetKey(opts.Config.Universal.Select),
|
||||||
|
@ -2,7 +2,6 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"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}})
|
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 {
|
func (gui *Gui) handleNewBranchOffStashEntry() error {
|
||||||
stashEntry := gui.getSelectedStashEntry()
|
stashEntry := gui.getSelectedStashEntry()
|
||||||
if stashEntry == nil {
|
if stashEntry == nil {
|
||||||
|
@ -245,7 +245,7 @@ func chineseTranslationSet() TranslationSet {
|
|||||||
CheckingOutStatus: "检出",
|
CheckingOutStatus: "检出",
|
||||||
CommittingStatus: "正在提交",
|
CommittingStatus: "正在提交",
|
||||||
CommitFiles: "提交文件",
|
CommitFiles: "提交文件",
|
||||||
LcViewCommitFiles: "查看提交的文件",
|
LcViewItemFiles: "查看提交的文件",
|
||||||
CommitFilesTitle: "提交文件",
|
CommitFilesTitle: "提交文件",
|
||||||
LcCheckoutCommitFile: "检出文件",
|
LcCheckoutCommitFile: "检出文件",
|
||||||
LcDiscardOldFileChange: "放弃对此文件的提交更改",
|
LcDiscardOldFileChange: "放弃对此文件的提交更改",
|
||||||
@ -380,7 +380,6 @@ func chineseTranslationSet() TranslationSet {
|
|||||||
UnstageLinesTitle: "未暂存的行",
|
UnstageLinesTitle: "未暂存的行",
|
||||||
UnstageLinesPrompt: "您确定要删除所选的行(git reset)吗?这是不可逆的。\n要禁用此对话框,请将 'gui.skipUnstageLineWarning' 的配置键设置为 true",
|
UnstageLinesPrompt: "您确定要删除所选的行(git reset)吗?这是不可逆的。\n要禁用此对话框,请将 'gui.skipUnstageLineWarning' 的配置键设置为 true",
|
||||||
LcCreateNewBranchFromCommit: "从提交创建新分支",
|
LcCreateNewBranchFromCommit: "从提交创建新分支",
|
||||||
LcViewStashFiles: "查看贮藏条目中的文件",
|
|
||||||
LcBuildingPatch: "正在构建补丁",
|
LcBuildingPatch: "正在构建补丁",
|
||||||
LcViewCommits: "查看提交",
|
LcViewCommits: "查看提交",
|
||||||
MinGitVersionError: "Git 版本必须至少为 2.0(即从 2014 年开始)。请升级您的 git 版本。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。",
|
MinGitVersionError: "Git 版本必须至少为 2.0(即从 2014 年开始)。请升级您的 git 版本。或者在 https://github.com/jesseduffield/lazygit/issues 上提出一个问题,以使 lazygit 更加向后兼容。",
|
||||||
|
@ -214,7 +214,7 @@ func dutchTranslationSet() TranslationSet {
|
|||||||
RedoingStatus: "redoing",
|
RedoingStatus: "redoing",
|
||||||
CheckingOutStatus: "uitchecken",
|
CheckingOutStatus: "uitchecken",
|
||||||
CommitFiles: "Commit bestanden",
|
CommitFiles: "Commit bestanden",
|
||||||
LcViewCommitFiles: "bekijk gecommite bestanden",
|
LcViewItemFiles: "bekijk gecommite bestanden",
|
||||||
CommitFilesTitle: "Commit bestanden",
|
CommitFilesTitle: "Commit bestanden",
|
||||||
LcCheckoutCommitFile: "bestand uitchecken",
|
LcCheckoutCommitFile: "bestand uitchecken",
|
||||||
LcDiscardOldFileChange: "uitsluit deze commit zijn veranderingen aan dit bestand",
|
LcDiscardOldFileChange: "uitsluit deze commit zijn veranderingen aan dit bestand",
|
||||||
@ -357,7 +357,6 @@ func dutchTranslationSet() TranslationSet {
|
|||||||
LcAddSubmodule: "voeg nieuwe submodule toe",
|
LcAddSubmodule: "voeg nieuwe submodule toe",
|
||||||
LcInitSubmodule: "initialiseer submodule",
|
LcInitSubmodule: "initialiseer submodule",
|
||||||
LcViewBulkSubmoduleOptions: "bekijk bulk submodule opties",
|
LcViewBulkSubmoduleOptions: "bekijk bulk submodule opties",
|
||||||
LcViewStashFiles: "bekijk bestanden van stash entry",
|
|
||||||
CreatePullRequestOptions: "Bekijk opties voor pull-aanvraag",
|
CreatePullRequestOptions: "Bekijk opties voor pull-aanvraag",
|
||||||
LcCreatePullRequestOptions: "bekijk opties voor pull-aanvraag",
|
LcCreatePullRequestOptions: "bekijk opties voor pull-aanvraag",
|
||||||
ConfirmRevertCommit: "Weet u zeker dat u {{.selectedCommit}} ongedaan wilt maken?",
|
ConfirmRevertCommit: "Weet u zeker dat u {{.selectedCommit}} ongedaan wilt maken?",
|
||||||
|
@ -231,7 +231,7 @@ type TranslationSet struct {
|
|||||||
CheckingOutStatus string
|
CheckingOutStatus string
|
||||||
CommittingStatus string
|
CommittingStatus string
|
||||||
CommitFiles string
|
CommitFiles string
|
||||||
LcViewCommitFiles string
|
LcViewItemFiles string
|
||||||
CommitFilesTitle string
|
CommitFilesTitle string
|
||||||
LcCheckoutCommitFile string
|
LcCheckoutCommitFile string
|
||||||
LcDiscardOldFileChange string
|
LcDiscardOldFileChange string
|
||||||
@ -375,7 +375,6 @@ type TranslationSet struct {
|
|||||||
UnstageLinesTitle string
|
UnstageLinesTitle string
|
||||||
UnstageLinesPrompt string
|
UnstageLinesPrompt string
|
||||||
LcCreateNewBranchFromCommit string
|
LcCreateNewBranchFromCommit string
|
||||||
LcViewStashFiles string
|
|
||||||
LcBuildingPatch string
|
LcBuildingPatch string
|
||||||
LcViewCommits string
|
LcViewCommits string
|
||||||
MinGitVersionError string
|
MinGitVersionError string
|
||||||
@ -804,7 +803,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
CheckingOutStatus: "checking out",
|
CheckingOutStatus: "checking out",
|
||||||
CommittingStatus: "committing",
|
CommittingStatus: "committing",
|
||||||
CommitFiles: "Commit files",
|
CommitFiles: "Commit files",
|
||||||
LcViewCommitFiles: "view commit's files",
|
LcViewItemFiles: "view selected item's files",
|
||||||
CommitFilesTitle: "Commit Files",
|
CommitFilesTitle: "Commit Files",
|
||||||
LcCheckoutCommitFile: "checkout file",
|
LcCheckoutCommitFile: "checkout file",
|
||||||
LcDiscardOldFileChange: "discard this commit's changes to this file",
|
LcDiscardOldFileChange: "discard this commit's changes to this file",
|
||||||
@ -949,7 +948,6 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
UnstageLinesTitle: "Unstage lines",
|
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",
|
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",
|
LcCreateNewBranchFromCommit: "create new branch off of commit",
|
||||||
LcViewStashFiles: "view stash entry's files",
|
|
||||||
LcBuildingPatch: "building patch",
|
LcBuildingPatch: "building patch",
|
||||||
LcViewCommits: "view commits",
|
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.",
|
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",
|
AmendingStatus: "poprawianie",
|
||||||
CherryPickingStatus: "przebieranie",
|
CherryPickingStatus: "przebieranie",
|
||||||
CommitFiles: "Pliki commita",
|
CommitFiles: "Pliki commita",
|
||||||
LcViewCommitFiles: "przeglądaj pliki commita",
|
LcViewItemFiles: "przeglądaj pliki commita",
|
||||||
CommitFilesTitle: "Pliki commita",
|
CommitFilesTitle: "Pliki commita",
|
||||||
LcCheckoutCommitFile: "plik wybierania",
|
LcCheckoutCommitFile: "plik wybierania",
|
||||||
LcDiscardOldFileChange: "porzuć zmiany commita dla tego pliku",
|
LcDiscardOldFileChange: "porzuć zmiany commita dla tego pliku",
|
||||||
|
Reference in New Issue
Block a user