mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
standardise helper args
This commit is contained in:
@ -15,55 +15,49 @@ func (gui *Gui) resetControllers() {
|
|||||||
helperCommon := gui.c
|
helperCommon := gui.c
|
||||||
osCommand := gui.os
|
osCommand := gui.os
|
||||||
model := gui.State.Model
|
model := gui.State.Model
|
||||||
refsHelper := helpers.NewRefsHelper(
|
refsHelper := helpers.NewRefsHelper(helperCommon)
|
||||||
helperCommon,
|
|
||||||
gui.git,
|
|
||||||
gui.State.Contexts,
|
|
||||||
model,
|
|
||||||
)
|
|
||||||
|
|
||||||
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper)
|
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, refsHelper)
|
||||||
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon, model, gui.State.Contexts)
|
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon)
|
||||||
setCommitMessage := gui.getSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage })
|
setCommitMessage := gui.getSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage })
|
||||||
getSavedCommitMessage := func() string {
|
getSavedCommitMessage := func() string {
|
||||||
return gui.State.savedCommitMessage
|
return gui.State.savedCommitMessage
|
||||||
}
|
}
|
||||||
gpgHelper := helpers.NewGpgHelper(helperCommon, gui.os, gui.git)
|
gpgHelper := helpers.NewGpgHelper(helperCommon)
|
||||||
viewHelper := helpers.NewViewHelper(helperCommon, gui.State.Contexts)
|
viewHelper := helpers.NewViewHelper(helperCommon, gui.State.Contexts)
|
||||||
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
|
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
|
||||||
patchBuildingHelper := helpers.NewPatchBuildingHelper(helperCommon, gui.git, gui.State.Contexts)
|
patchBuildingHelper := helpers.NewPatchBuildingHelper(helperCommon)
|
||||||
stagingHelper := helpers.NewStagingHelper(helperCommon, gui.git, gui.State.Contexts)
|
stagingHelper := helpers.NewStagingHelper(helperCommon)
|
||||||
mergeConflictsHelper := helpers.NewMergeConflictsHelper(helperCommon, gui.State.Contexts, gui.git)
|
mergeConflictsHelper := helpers.NewMergeConflictsHelper(helperCommon)
|
||||||
refreshHelper := helpers.NewRefreshHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper, rebaseHelper, patchBuildingHelper, stagingHelper, mergeConflictsHelper, gui.fileWatcher)
|
refreshHelper := helpers.NewRefreshHelper(helperCommon, refsHelper, rebaseHelper, patchBuildingHelper, stagingHelper, mergeConflictsHelper, gui.fileWatcher)
|
||||||
gui.helpers = &helpers.Helpers{
|
gui.helpers = &helpers.Helpers{
|
||||||
Refs: refsHelper,
|
Refs: refsHelper,
|
||||||
Host: helpers.NewHostHelper(helperCommon, gui.git),
|
Host: helpers.NewHostHelper(helperCommon),
|
||||||
PatchBuilding: patchBuildingHelper,
|
PatchBuilding: patchBuildingHelper,
|
||||||
Staging: stagingHelper,
|
Staging: stagingHelper,
|
||||||
Bisect: helpers.NewBisectHelper(helperCommon),
|
Bisect: helpers.NewBisectHelper(helperCommon),
|
||||||
Suggestions: suggestionsHelper,
|
Suggestions: suggestionsHelper,
|
||||||
Files: helpers.NewFilesHelper(helperCommon, gui.git, osCommand),
|
Files: helpers.NewFilesHelper(helperCommon),
|
||||||
WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, gui.git, gui.State.Contexts, refsHelper, model, setCommitMessage, getSavedCommitMessage),
|
WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, refsHelper, setCommitMessage, getSavedCommitMessage),
|
||||||
Tags: helpers.NewTagsHelper(helperCommon, gui.git),
|
Tags: helpers.NewTagsHelper(helperCommon),
|
||||||
GPG: gpgHelper,
|
GPG: gpgHelper,
|
||||||
MergeAndRebase: rebaseHelper,
|
MergeAndRebase: rebaseHelper,
|
||||||
MergeConflicts: mergeConflictsHelper,
|
MergeConflicts: mergeConflictsHelper,
|
||||||
CherryPick: helpers.NewCherryPickHelper(
|
CherryPick: helpers.NewCherryPickHelper(
|
||||||
helperCommon,
|
helperCommon,
|
||||||
gui.State.Contexts,
|
|
||||||
rebaseHelper,
|
rebaseHelper,
|
||||||
),
|
),
|
||||||
Upstream: helpers.NewUpstreamHelper(helperCommon, model, suggestionsHelper.GetRemoteBranchesSuggestionsFunc),
|
Upstream: helpers.NewUpstreamHelper(helperCommon, suggestionsHelper.GetRemoteBranchesSuggestionsFunc),
|
||||||
AmendHelper: helpers.NewAmendHelper(helperCommon, gui.git, gpgHelper),
|
AmendHelper: helpers.NewAmendHelper(helperCommon, gpgHelper),
|
||||||
Snake: helpers.NewSnakeHelper(helperCommon),
|
Snake: helpers.NewSnakeHelper(helperCommon),
|
||||||
Diff: helpers.NewDiffHelper(helperCommon),
|
Diff: helpers.NewDiffHelper(helperCommon),
|
||||||
Repos: helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo),
|
Repos: helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo),
|
||||||
RecordDirectory: recordDirectoryHelper,
|
RecordDirectory: recordDirectoryHelper,
|
||||||
Update: helpers.NewUpdateHelper(helperCommon, gui.Updater),
|
Update: helpers.NewUpdateHelper(helperCommon, gui.Updater),
|
||||||
Window: helpers.NewWindowHelper(helperCommon, viewHelper, gui.State.Contexts),
|
Window: helpers.NewWindowHelper(helperCommon, viewHelper),
|
||||||
View: viewHelper,
|
View: viewHelper,
|
||||||
Refresh: refreshHelper,
|
Refresh: refreshHelper,
|
||||||
Confirmation: helpers.NewConfirmationHelper(helperCommon, gui.State.Contexts),
|
Confirmation: helpers.NewConfirmationHelper(helperCommon),
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.CustomCommandsClient = custom_commands.NewClient(
|
gui.CustomCommandsClient = custom_commands.NewClient(
|
||||||
|
@ -1,24 +1,20 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AmendHelper struct {
|
type AmendHelper struct {
|
||||||
c *types.HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
gpg *GpgHelper
|
gpg *GpgHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAmendHelper(
|
func NewAmendHelper(
|
||||||
c *types.HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
gpg *GpgHelper,
|
gpg *GpgHelper,
|
||||||
) *AmendHelper {
|
) *AmendHelper {
|
||||||
return &AmendHelper{
|
return &AmendHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
gpg: gpg,
|
gpg: gpg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,7 +24,7 @@ func (self *AmendHelper) AmendHead() error {
|
|||||||
Title: self.c.Tr.AmendLastCommitTitle,
|
Title: self.c.Tr.AmendLastCommitTitle,
|
||||||
Prompt: self.c.Tr.SureToAmend,
|
Prompt: self.c.Tr.SureToAmend,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
cmdObj := self.git.Commit.AmendHeadCmdObj()
|
cmdObj := self.c.Git().Commit.AmendHeadCmdObj()
|
||||||
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
|
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
|
||||||
return self.gpg.WithGpgHandling(cmdObj, self.c.Tr.AmendingStatus, nil)
|
return self.gpg.WithGpgHandling(cmdObj, self.c.Tr.AmendingStatus, nil)
|
||||||
},
|
},
|
||||||
|
@ -2,7 +2,6 @@ package helpers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -10,8 +9,6 @@ import (
|
|||||||
type CherryPickHelper struct {
|
type CherryPickHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
|
|
||||||
contexts *context.ContextTree
|
|
||||||
|
|
||||||
rebaseHelper *MergeAndRebaseHelper
|
rebaseHelper *MergeAndRebaseHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +17,10 @@ type CherryPickHelper struct {
|
|||||||
|
|
||||||
func NewCherryPickHelper(
|
func NewCherryPickHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
contexts *context.ContextTree,
|
|
||||||
rebaseHelper *MergeAndRebaseHelper,
|
rebaseHelper *MergeAndRebaseHelper,
|
||||||
) *CherryPickHelper {
|
) *CherryPickHelper {
|
||||||
return &CherryPickHelper{
|
return &CherryPickHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
rebaseHelper: rebaseHelper,
|
rebaseHelper: rebaseHelper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,9 +106,9 @@ func (self *CherryPickHelper) resetIfNecessary(context types.Context) error {
|
|||||||
|
|
||||||
func (self *CherryPickHelper) rerender() error {
|
func (self *CherryPickHelper) rerender() error {
|
||||||
for _, context := range []types.Context{
|
for _, context := range []types.Context{
|
||||||
self.contexts.LocalCommits,
|
self.c.Contexts().LocalCommits,
|
||||||
self.contexts.ReflogCommits,
|
self.c.Contexts().ReflogCommits,
|
||||||
self.contexts.SubCommits,
|
self.c.Contexts().SubCommits,
|
||||||
} {
|
} {
|
||||||
if err := self.c.PostRefreshUpdate(context); err != nil {
|
if err := self.c.PostRefreshUpdate(context); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
@ -15,17 +14,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ConfirmationHelper struct {
|
type ConfirmationHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfirmationHelper(
|
func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper {
|
||||||
c *HelperCommon,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
) *ConfirmationHelper {
|
|
||||||
return &ConfirmationHelper{
|
return &ConfirmationHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +127,7 @@ func (self *ConfirmationHelper) prepareConfirmationPanel(
|
|||||||
self.c.Views().Confirmation.Mask = runeForMask(opts.Mask)
|
self.c.Views().Confirmation.Mask = runeForMask(opts.Mask)
|
||||||
_ = self.c.Views().Confirmation.SetOrigin(0, 0)
|
_ = self.c.Views().Confirmation.SetOrigin(0, 0)
|
||||||
|
|
||||||
suggestionsContext := self.contexts.Suggestions
|
suggestionsContext := self.c.Contexts().Suggestions
|
||||||
suggestionsContext.State.FindSuggestions = opts.FindSuggestionsFunc
|
suggestionsContext.State.FindSuggestions = opts.FindSuggestionsFunc
|
||||||
if opts.FindSuggestionsFunc != nil {
|
if opts.FindSuggestionsFunc != nil {
|
||||||
suggestionsView := self.c.Views().Suggestions
|
suggestionsView := self.c.Views().Suggestions
|
||||||
@ -210,7 +204,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
|
|||||||
|
|
||||||
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts)
|
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts)
|
||||||
|
|
||||||
return self.c.PushContext(self.contexts.Confirmation)
|
return self.c.PushContext(self.c.Contexts().Confirmation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) error {
|
func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) error {
|
||||||
@ -229,24 +223,24 @@ func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts
|
|||||||
|
|
||||||
onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
|
onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
|
||||||
|
|
||||||
self.contexts.Confirmation.State.OnConfirm = onConfirm
|
self.c.Contexts().Confirmation.State.OnConfirm = onConfirm
|
||||||
self.contexts.Confirmation.State.OnClose = onClose
|
self.c.Contexts().Confirmation.State.OnClose = onClose
|
||||||
self.contexts.Suggestions.State.OnConfirm = onSuggestionConfirm
|
self.c.Contexts().Suggestions.State.OnConfirm = onSuggestionConfirm
|
||||||
self.contexts.Suggestions.State.OnClose = onClose
|
self.c.Contexts().Suggestions.State.OnClose = onClose
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) clearConfirmationViewKeyBindings() {
|
func (self *ConfirmationHelper) clearConfirmationViewKeyBindings() {
|
||||||
noop := func() error { return nil }
|
noop := func() error { return nil }
|
||||||
self.contexts.Confirmation.State.OnConfirm = noop
|
self.c.Contexts().Confirmation.State.OnConfirm = noop
|
||||||
self.contexts.Confirmation.State.OnClose = noop
|
self.c.Contexts().Confirmation.State.OnClose = noop
|
||||||
self.contexts.Suggestions.State.OnConfirm = noop
|
self.c.Contexts().Suggestions.State.OnConfirm = noop
|
||||||
self.contexts.Suggestions.State.OnClose = noop
|
self.c.Contexts().Suggestions.State.OnClose = noop
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) getSelectedSuggestionValue() string {
|
func (self *ConfirmationHelper) getSelectedSuggestionValue() string {
|
||||||
selectedSuggestion := self.contexts.Suggestions.GetSelected()
|
selectedSuggestion := self.c.Contexts().Suggestions.GetSelected()
|
||||||
|
|
||||||
if selectedSuggestion != nil {
|
if selectedSuggestion != nil {
|
||||||
return selectedSuggestion.Value
|
return selectedSuggestion.Value
|
||||||
@ -300,7 +294,7 @@ func (self *ConfirmationHelper) ResizePopupPanel(v *gocui.View, content string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) resizeMenu() {
|
func (self *ConfirmationHelper) resizeMenu() {
|
||||||
itemCount := self.contexts.Menu.GetList().Len()
|
itemCount := self.c.Contexts().Menu.GetList().Len()
|
||||||
offset := 3
|
offset := 3
|
||||||
panelWidth := self.getConfirmationPanelWidth()
|
panelWidth := self.getConfirmationPanelWidth()
|
||||||
x0, y0, x1, y1 := self.getConfirmationPanelDimensionsForContentHeight(panelWidth, itemCount+offset)
|
x0, y0, x1, y1 := self.getConfirmationPanelDimensionsForContentHeight(panelWidth, itemCount+offset)
|
||||||
@ -308,7 +302,7 @@ func (self *ConfirmationHelper) resizeMenu() {
|
|||||||
_, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0)
|
_, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0)
|
||||||
|
|
||||||
tooltipTop := menuBottom + 1
|
tooltipTop := menuBottom + 1
|
||||||
tooltipHeight := getMessageHeight(true, self.contexts.Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame
|
tooltipHeight := getMessageHeight(true, self.c.Contexts().Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame
|
||||||
_, _ = self.c.GocuiGui().SetView(self.c.Views().Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
|
_, _ = self.c.GocuiGui().SetView(self.c.Views().Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IFilesHelper interface {
|
type IFilesHelper interface {
|
||||||
EditFile(filename string) error
|
EditFile(filename string) error
|
||||||
EditFileAtLine(filename string, lineNumber int) error
|
EditFileAtLine(filename string, lineNumber int) error
|
||||||
@ -12,37 +7,29 @@ type IFilesHelper interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilesHelper struct {
|
type FilesHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
os *oscommands.OSCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilesHelper(
|
func NewFilesHelper(c *HelperCommon) *FilesHelper {
|
||||||
c *HelperCommon,
|
|
||||||
git *commands.GitCommand,
|
|
||||||
os *oscommands.OSCommand,
|
|
||||||
) *FilesHelper {
|
|
||||||
return &FilesHelper{
|
return &FilesHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
os: os,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IFilesHelper = &FilesHelper{}
|
var _ IFilesHelper = &FilesHelper{}
|
||||||
|
|
||||||
func (self *FilesHelper) EditFile(filename string) error {
|
func (self *FilesHelper) EditFile(filename string) error {
|
||||||
cmdStr, editInTerminal := self.git.File.GetEditCmdStr(filename)
|
cmdStr, editInTerminal := self.c.Git().File.GetEditCmdStr(filename)
|
||||||
return self.callEditor(cmdStr, editInTerminal)
|
return self.callEditor(cmdStr, editInTerminal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
|
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
|
||||||
cmdStr, editInTerminal := self.git.File.GetEditAtLineCmdStr(filename, lineNumber)
|
cmdStr, editInTerminal := self.c.Git().File.GetEditAtLineCmdStr(filename, lineNumber)
|
||||||
return self.callEditor(cmdStr, editInTerminal)
|
return self.callEditor(cmdStr, editInTerminal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int) error {
|
func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int) error {
|
||||||
cmdStr := self.git.File.GetEditAtLineAndWaitCmdStr(filename, lineNumber)
|
cmdStr := self.c.Git().File.GetEditAtLineAndWaitCmdStr(filename, lineNumber)
|
||||||
|
|
||||||
// Always suspend, regardless of the value of the editInTerminal config,
|
// Always suspend, regardless of the value of the editInTerminal config,
|
||||||
// since we want to prevent interacting with the UI until the editor
|
// since we want to prevent interacting with the UI until the editor
|
||||||
@ -53,16 +40,16 @@ func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int)
|
|||||||
func (self *FilesHelper) callEditor(cmdStr string, editInTerminal bool) error {
|
func (self *FilesHelper) callEditor(cmdStr string, editInTerminal bool) error {
|
||||||
if editInTerminal {
|
if editInTerminal {
|
||||||
return self.c.RunSubprocessAndRefresh(
|
return self.c.RunSubprocessAndRefresh(
|
||||||
self.os.Cmd.NewShell(cmdStr),
|
self.c.OS().Cmd.NewShell(cmdStr),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.os.Cmd.NewShell(cmdStr).Run()
|
return self.c.OS().Cmd.NewShell(cmdStr).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesHelper) OpenFile(filename string) error {
|
func (self *FilesHelper) OpenFile(filename string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.OpenFile)
|
self.c.LogAction(self.c.Tr.Actions.OpenFile)
|
||||||
if err := self.os.OpenFile(filename); err != nil {
|
if err := self.c.OS().OpenFile(filename); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,26 +3,17 @@ package helpers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GpgHelper struct {
|
type GpgHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
os *oscommands.OSCommand
|
|
||||||
git *commands.GitCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGpgHelper(
|
func NewGpgHelper(c *HelperCommon) *GpgHelper {
|
||||||
c *HelperCommon,
|
|
||||||
os *oscommands.OSCommand,
|
|
||||||
git *commands.GitCommand,
|
|
||||||
) *GpgHelper {
|
|
||||||
return &GpgHelper{
|
return &GpgHelper{
|
||||||
c: c,
|
c: c,
|
||||||
os: os,
|
|
||||||
git: git,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,9 +23,9 @@ func NewGpgHelper(
|
|||||||
// we don't need to see a loading status if we're in a subprocess.
|
// we don't need to see a loading status if we're in a subprocess.
|
||||||
// TODO: we shouldn't need to use a shell here, but looks like that NewShell function contains some windows specific quoting stuff. We should centralise that.
|
// TODO: we shouldn't need to use a shell here, but looks like that NewShell function contains some windows specific quoting stuff. We should centralise that.
|
||||||
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
||||||
useSubprocess := self.git.Config.UsingGpg()
|
useSubprocess := self.c.Git().Config.UsingGpg()
|
||||||
if useSubprocess {
|
if useSubprocess {
|
||||||
success, err := self.c.RunSubprocess(self.os.Cmd.NewShell(cmdObj.ToString()))
|
success, err := self.c.RunSubprocess(self.c.OS().Cmd.NewShell(cmdObj.ToString()))
|
||||||
if success && onSuccess != nil {
|
if success && onSuccess != nil {
|
||||||
if err := onSuccess(); err != nil {
|
if err := onSuccess(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -51,7 +42,7 @@ func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *GpgHelper) runAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
func (self *GpgHelper) runAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
|
||||||
cmdObj = self.os.Cmd.NewShell(cmdObj.ToString())
|
cmdObj = self.c.OS().Cmd.NewShell(cmdObj.ToString())
|
||||||
|
|
||||||
return self.c.WithWaitingStatus(waitingStatus, func() error {
|
return self.c.WithWaitingStatus(waitingStatus, func() error {
|
||||||
if err := cmdObj.StreamOutput().Run(); err != nil {
|
if err := cmdObj.StreamOutput().Run(); err != nil {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
|
"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,17 +12,14 @@ type IHostHelper interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HostHelper struct {
|
type HostHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHostHelper(
|
func NewHostHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
) *HostHelper {
|
) *HostHelper {
|
||||||
return &HostHelper{
|
return &HostHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +35,7 @@ func (self *HostHelper) GetCommitURL(commitSha string) (string, error) {
|
|||||||
// from one invocation to the next. Note however that we're currently caching config
|
// from one invocation to the next. Note however that we're currently caching config
|
||||||
// results so we might want to invalidate the cache here if it becomes a problem.
|
// results so we might want to invalidate the cache here if it becomes a problem.
|
||||||
func (self *HostHelper) getHostingServiceMgr() *hosting_service.HostingServiceMgr {
|
func (self *HostHelper) getHostingServiceMgr() *hosting_service.HostingServiceMgr {
|
||||||
remoteUrl := self.git.Config.GetRemoteURL()
|
remoteUrl := self.c.Git().Config.GetRemoteURL()
|
||||||
configServices := self.c.UserConfig.Services
|
configServices := self.c.UserConfig.Services
|
||||||
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices)
|
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices)
|
||||||
}
|
}
|
||||||
|
@ -5,31 +5,23 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MergeAndRebaseHelper struct {
|
type MergeAndRebaseHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
contexts *context.ContextTree
|
|
||||||
git *commands.GitCommand
|
|
||||||
refsHelper *RefsHelper
|
refsHelper *RefsHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMergeAndRebaseHelper(
|
func NewMergeAndRebaseHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
contexts *context.ContextTree,
|
|
||||||
git *commands.GitCommand,
|
|
||||||
refsHelper *RefsHelper,
|
refsHelper *RefsHelper,
|
||||||
) *MergeAndRebaseHelper {
|
) *MergeAndRebaseHelper {
|
||||||
return &MergeAndRebaseHelper{
|
return &MergeAndRebaseHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
git: git,
|
|
||||||
refsHelper: refsHelper,
|
refsHelper: refsHelper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +45,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
|
|||||||
{option: REBASE_OPTION_ABORT, key: 'a'},
|
{option: REBASE_OPTION_ABORT, key: 'a'},
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_REBASING {
|
if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING {
|
||||||
options = append(options, optionAndKey{
|
options = append(options, optionAndKey{
|
||||||
option: REBASE_OPTION_SKIP, key: 's',
|
option: REBASE_OPTION_SKIP, key: 's',
|
||||||
})
|
})
|
||||||
@ -70,7 +62,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
var title string
|
var title string
|
||||||
if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_MERGING {
|
if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_MERGING {
|
||||||
title = self.c.Tr.MergeOptionsTitle
|
title = self.c.Tr.MergeOptionsTitle
|
||||||
} else {
|
} else {
|
||||||
title = self.c.Tr.RebaseOptionsTitle
|
title = self.c.Tr.RebaseOptionsTitle
|
||||||
@ -80,7 +72,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
|
func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
|
||||||
status := self.git.Status.WorkingTreeState()
|
status := self.c.Git().Status.WorkingTreeState()
|
||||||
|
|
||||||
if status != enums.REBASE_MODE_MERGING && status != enums.REBASE_MODE_REBASING {
|
if status != enums.REBASE_MODE_MERGING && status != enums.REBASE_MODE_REBASING {
|
||||||
return self.c.ErrorMsg(self.c.Tr.NotMergingOrRebasing)
|
return self.c.ErrorMsg(self.c.Tr.NotMergingOrRebasing)
|
||||||
@ -104,10 +96,10 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error {
|
|||||||
if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig.Git.Merging.ManualCommit {
|
if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig.Git.Merging.ManualCommit {
|
||||||
// TODO: see if we should be calling more of the code from self.Git.Rebase.GenericMergeOrRebaseAction
|
// TODO: see if we should be calling more of the code from self.Git.Rebase.GenericMergeOrRebaseAction
|
||||||
return self.c.RunSubprocessAndRefresh(
|
return self.c.RunSubprocessAndRefresh(
|
||||||
self.git.Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command),
|
self.c.Git().Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
result := self.git.Rebase.GenericMergeOrRebaseAction(commandType, command)
|
result := self.c.Git().Rebase.GenericMergeOrRebaseAction(commandType, command)
|
||||||
if err := self.CheckMergeOrRebase(result); err != nil {
|
if err := self.CheckMergeOrRebase(result); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -150,7 +142,7 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error {
|
|||||||
Title: self.c.Tr.FoundConflictsTitle,
|
Title: self.c.Tr.FoundConflictsTitle,
|
||||||
Prompt: self.c.Tr.FoundConflicts,
|
Prompt: self.c.Tr.FoundConflicts,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
return self.c.PushContext(self.contexts.Files)
|
return self.c.PushContext(self.c.Contexts().Files)
|
||||||
},
|
},
|
||||||
HandleClose: func() error {
|
HandleClose: func() error {
|
||||||
return self.genericMergeCommand(REBASE_OPTION_ABORT)
|
return self.genericMergeCommand(REBASE_OPTION_ABORT)
|
||||||
@ -174,7 +166,7 @@ func (self *MergeAndRebaseHelper) AbortMergeOrRebaseWithConfirm() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeAndRebaseHelper) workingTreeStateNoun() string {
|
func (self *MergeAndRebaseHelper) workingTreeStateNoun() string {
|
||||||
workingTreeState := self.git.Status.WorkingTreeState()
|
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||||
switch workingTreeState {
|
switch workingTreeState {
|
||||||
case enums.REBASE_MODE_NONE:
|
case enums.REBASE_MODE_NONE:
|
||||||
return ""
|
return ""
|
||||||
@ -207,7 +199,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
|||||||
Key: 's',
|
Key: 's',
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
|
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
|
||||||
err := self.git.Rebase.RebaseBranch(ref)
|
err := self.c.Git().Rebase.RebaseBranch(ref)
|
||||||
return self.CheckMergeOrRebase(err)
|
return self.CheckMergeOrRebase(err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -217,11 +209,11 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
|||||||
Tooltip: self.c.Tr.InteractiveRebaseTooltip,
|
Tooltip: self.c.Tr.InteractiveRebaseTooltip,
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
|
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
|
||||||
err := self.git.Rebase.EditRebase(ref)
|
err := self.c.Git().Rebase.EditRebase(ref)
|
||||||
if err = self.CheckMergeOrRebase(err); err != nil {
|
if err = self.CheckMergeOrRebase(err); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return self.c.PushContext(self.contexts.LocalCommits)
|
return self.c.PushContext(self.c.Contexts().LocalCommits)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -241,7 +233,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error {
|
func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error {
|
||||||
if self.git.Branch.IsHeadDetached() {
|
if self.c.Git().Branch.IsHeadDetached() {
|
||||||
return self.c.ErrorMsg("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on")
|
return self.c.ErrorMsg("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on")
|
||||||
}
|
}
|
||||||
checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name
|
checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name
|
||||||
@ -261,7 +253,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
|
|||||||
Prompt: prompt,
|
Prompt: prompt,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.Merge)
|
self.c.LogAction(self.c.Tr.Actions.Merge)
|
||||||
err := self.git.Branch.Merge(refName, git_commands.MergeOpts{})
|
err := self.c.Git().Branch.Merge(refName, git_commands.MergeOpts{})
|
||||||
return self.CheckMergeOrRebase(err)
|
return self.CheckMergeOrRebase(err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,26 +1,19 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MergeConflictsHelper struct {
|
type MergeConflictsHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
contexts *context.ContextTree
|
|
||||||
git *commands.GitCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMergeConflictsHelper(
|
func NewMergeConflictsHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
contexts *context.ContextTree,
|
|
||||||
git *commands.GitCommand,
|
|
||||||
) *MergeConflictsHelper {
|
) *MergeConflictsHelper {
|
||||||
return &MergeConflictsHelper{
|
return &MergeConflictsHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
git: git,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +25,7 @@ func (self *MergeConflictsHelper) SetMergeState(path string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeConflictsHelper) setMergeStateWithoutLock(path string) (bool, error) {
|
func (self *MergeConflictsHelper) setMergeStateWithoutLock(path string) (bool, error) {
|
||||||
content, err := self.git.File.Cat(path)
|
content, err := self.c.Git().File.Cat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -63,7 +56,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error {
|
|||||||
|
|
||||||
// doing this in separate UI thread so that we're not still holding the lock by the time refresh the file
|
// doing this in separate UI thread so that we're not still holding the lock by the time refresh the file
|
||||||
self.c.OnUIThread(func() error {
|
self.c.OnUIThread(func() error {
|
||||||
return self.c.PushContext(self.contexts.Files)
|
return self.c.PushContext(self.c.Contexts().Files)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -92,11 +85,11 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.PushContext(self.contexts.MergeConflicts)
|
return self.c.PushContext(self.c.Contexts().MergeConflicts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {
|
func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {
|
||||||
return self.contexts.MergeConflicts
|
return self.c.Contexts().MergeConflicts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeConflictsHelper) Render(isFocused bool) error {
|
func (self *MergeConflictsHelper) Render(isFocused bool) error {
|
||||||
@ -119,14 +112,14 @@ func (self *MergeConflictsHelper) Render(isFocused bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MergeConflictsHelper) RefreshMergeState() error {
|
func (self *MergeConflictsHelper) RefreshMergeState() error {
|
||||||
self.contexts.MergeConflicts.GetMutex().Lock()
|
self.c.Contexts().MergeConflicts.GetMutex().Lock()
|
||||||
defer self.contexts.MergeConflicts.GetMutex().Unlock()
|
defer self.c.Contexts().MergeConflicts.GetMutex().Unlock()
|
||||||
|
|
||||||
if self.c.CurrentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY {
|
if self.c.CurrentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hasConflicts, err := self.SetConflictsAndRender(self.contexts.MergeConflicts.GetState().GetPath(), true)
|
hasConflicts, err := self.SetConflictsAndRender(self.c.Contexts().MergeConflicts.GetState().GetPath(), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -13,25 +11,19 @@ type IPatchBuildingHelper interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PatchBuildingHelper struct {
|
type PatchBuildingHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPatchBuildingHelper(
|
func NewPatchBuildingHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
) *PatchBuildingHelper {
|
) *PatchBuildingHelper {
|
||||||
return &PatchBuildingHelper{
|
return &PatchBuildingHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) {
|
func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) {
|
||||||
if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE {
|
if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE {
|
||||||
return false, self.c.ErrorMsg(self.c.Tr.CantPatchWhileRebasingError)
|
return false, self.c.ErrorMsg(self.c.Tr.CantPatchWhileRebasingError)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -44,7 +36,7 @@ func (self *PatchBuildingHelper) Escape() error {
|
|||||||
|
|
||||||
// kills the custom patch and returns us back to the commit files panel if needed
|
// kills the custom patch and returns us back to the commit files panel if needed
|
||||||
func (self *PatchBuildingHelper) Reset() error {
|
func (self *PatchBuildingHelper) Reset() error {
|
||||||
self.git.Patch.PatchBuilder.Reset()
|
self.c.Git().Patch.PatchBuilder.Reset()
|
||||||
|
|
||||||
if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT {
|
if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT {
|
||||||
if err := self.Escape(); err != nil {
|
if err := self.Escape(); err != nil {
|
||||||
@ -68,30 +60,30 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
|
|||||||
selectedLineIdx = opts.ClickedViewLineIdx
|
selectedLineIdx = opts.ClickedViewLineIdx
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.git.Patch.PatchBuilder.Active() {
|
if !self.c.Git().Patch.PatchBuilder.Active() {
|
||||||
return self.Escape()
|
return self.Escape()
|
||||||
}
|
}
|
||||||
|
|
||||||
// get diff from commit file that's currently selected
|
// get diff from commit file that's currently selected
|
||||||
path := self.contexts.CommitFiles.GetSelectedPath()
|
path := self.c.Contexts().CommitFiles.GetSelectedPath()
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ref := self.contexts.CommitFiles.CommitFileTreeViewModel.GetRef()
|
ref := self.c.Contexts().CommitFiles.CommitFileTreeViewModel.GetRef()
|
||||||
to := ref.RefName()
|
to := ref.RefName()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
||||||
diff, err := self.git.WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView())
|
diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
secondaryDiff := self.git.Patch.PatchBuilder.RenderPatchForFile(path, false, false)
|
secondaryDiff := self.c.Git().Patch.PatchBuilder.RenderPatchForFile(path, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
context := self.contexts.CustomPatchBuilder
|
context := self.c.Contexts().CustomPatchBuilder
|
||||||
|
|
||||||
oldState := context.GetState()
|
oldState := context.GetState()
|
||||||
|
|
||||||
@ -103,7 +95,7 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
|
|||||||
|
|
||||||
mainContent := context.GetContentToRender(true)
|
mainContent := context.GetContentToRender(true)
|
||||||
|
|
||||||
self.contexts.CustomPatchBuilder.FocusSelection()
|
self.c.Contexts().CustomPatchBuilder.FocusSelection()
|
||||||
|
|
||||||
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
||||||
Pair: self.c.MainViewPairs().PatchBuilding,
|
Pair: self.c.MainViewPairs().PatchBuilding,
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/generics/set"
|
"github.com/jesseduffield/generics/set"
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
@ -22,8 +21,6 @@ import (
|
|||||||
|
|
||||||
type RefreshHelper struct {
|
type RefreshHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
contexts *context.ContextTree
|
|
||||||
git *commands.GitCommand
|
|
||||||
refsHelper *RefsHelper
|
refsHelper *RefsHelper
|
||||||
mergeAndRebaseHelper *MergeAndRebaseHelper
|
mergeAndRebaseHelper *MergeAndRebaseHelper
|
||||||
patchBuildingHelper *PatchBuildingHelper
|
patchBuildingHelper *PatchBuildingHelper
|
||||||
@ -34,8 +31,6 @@ type RefreshHelper struct {
|
|||||||
|
|
||||||
func NewRefreshHelper(
|
func NewRefreshHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
contexts *context.ContextTree,
|
|
||||||
git *commands.GitCommand,
|
|
||||||
refsHelper *RefsHelper,
|
refsHelper *RefsHelper,
|
||||||
mergeAndRebaseHelper *MergeAndRebaseHelper,
|
mergeAndRebaseHelper *MergeAndRebaseHelper,
|
||||||
patchBuildingHelper *PatchBuildingHelper,
|
patchBuildingHelper *PatchBuildingHelper,
|
||||||
@ -45,8 +40,6 @@ func NewRefreshHelper(
|
|||||||
) *RefreshHelper {
|
) *RefreshHelper {
|
||||||
return &RefreshHelper{
|
return &RefreshHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
git: git,
|
|
||||||
refsHelper: refsHelper,
|
refsHelper: refsHelper,
|
||||||
mergeAndRebaseHelper: mergeAndRebaseHelper,
|
mergeAndRebaseHelper: mergeAndRebaseHelper,
|
||||||
patchBuildingHelper: patchBuildingHelper,
|
patchBuildingHelper: patchBuildingHelper,
|
||||||
@ -239,7 +232,7 @@ func (self *RefreshHelper) refreshCommits() {
|
|||||||
|
|
||||||
go utils.Safe(func() {
|
go utils.Safe(func() {
|
||||||
_ = self.refreshCommitsWithLimit()
|
_ = self.refreshCommitsWithLimit()
|
||||||
ctx, ok := self.contexts.CommitFiles.GetParentContext()
|
ctx, ok := self.c.Contexts().CommitFiles.GetParentContext()
|
||||||
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
|
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
|
||||||
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position.
|
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position.
|
||||||
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
|
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
|
||||||
@ -247,10 +240,10 @@ func (self *RefreshHelper) refreshCommits() {
|
|||||||
// Ideally we would know when to refresh the commit files context and when not to,
|
// Ideally we would know when to refresh the commit files context and when not to,
|
||||||
// or perhaps we could just pop that context off the stack whenever cycling windows.
|
// or perhaps we could just pop that context off the stack whenever cycling windows.
|
||||||
// For now the awkwardness remains.
|
// For now the awkwardness remains.
|
||||||
commit := self.contexts.LocalCommits.GetSelected()
|
commit := self.c.Contexts().LocalCommits.GetSelected()
|
||||||
if commit != nil {
|
if commit != nil {
|
||||||
self.contexts.CommitFiles.SetRef(commit)
|
self.c.Contexts().CommitFiles.SetRef(commit)
|
||||||
self.contexts.CommitFiles.SetTitleRef(commit.RefName())
|
self.c.Contexts().CommitFiles.SetTitleRef(commit.RefName())
|
||||||
_ = self.refreshCommitFilesContext()
|
_ = self.refreshCommitFilesContext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,34 +257,34 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
|
|||||||
self.c.Mutexes().LocalCommitsMutex.Lock()
|
self.c.Mutexes().LocalCommitsMutex.Lock()
|
||||||
defer self.c.Mutexes().LocalCommitsMutex.Unlock()
|
defer self.c.Mutexes().LocalCommitsMutex.Unlock()
|
||||||
|
|
||||||
commits, err := self.git.Loaders.CommitLoader.GetCommits(
|
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
|
||||||
git_commands.GetCommitsOptions{
|
git_commands.GetCommitsOptions{
|
||||||
Limit: self.contexts.LocalCommits.GetLimitCommits(),
|
Limit: self.c.Contexts().LocalCommits.GetLimitCommits(),
|
||||||
FilterPath: self.c.Modes().Filtering.GetPath(),
|
FilterPath: self.c.Modes().Filtering.GetPath(),
|
||||||
IncludeRebaseCommits: true,
|
IncludeRebaseCommits: true,
|
||||||
RefName: self.refForLog(),
|
RefName: self.refForLog(),
|
||||||
All: self.contexts.LocalCommits.GetShowWholeGitGraph(),
|
All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
self.c.Model().Commits = commits
|
self.c.Model().Commits = commits
|
||||||
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.git.Status.WorkingTreeState()
|
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState()
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.LocalCommits)
|
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
|
func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
|
||||||
self.c.Mutexes().SubCommitsMutex.Lock()
|
self.c.Mutexes().SubCommitsMutex.Lock()
|
||||||
defer self.c.Mutexes().SubCommitsMutex.Unlock()
|
defer self.c.Mutexes().SubCommitsMutex.Unlock()
|
||||||
|
|
||||||
commits, err := self.git.Loaders.CommitLoader.GetCommits(
|
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
|
||||||
git_commands.GetCommitsOptions{
|
git_commands.GetCommitsOptions{
|
||||||
Limit: self.contexts.SubCommits.GetLimitCommits(),
|
Limit: self.c.Contexts().SubCommits.GetLimitCommits(),
|
||||||
FilterPath: self.c.Modes().Filtering.GetPath(),
|
FilterPath: self.c.Modes().Filtering.GetPath(),
|
||||||
IncludeRebaseCommits: false,
|
IncludeRebaseCommits: false,
|
||||||
RefName: self.contexts.SubCommits.GetRef().FullRefName(),
|
RefName: self.c.Contexts().SubCommits.GetRef().FullRefName(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -299,51 +292,51 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit() error {
|
|||||||
}
|
}
|
||||||
self.c.Model().SubCommits = commits
|
self.c.Model().SubCommits = commits
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.SubCommits)
|
return self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshCommitFilesContext() error {
|
func (self *RefreshHelper) refreshCommitFilesContext() error {
|
||||||
ref := self.contexts.CommitFiles.GetRef()
|
ref := self.c.Contexts().CommitFiles.GetRef()
|
||||||
to := ref.RefName()
|
to := ref.RefName()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
|
||||||
|
|
||||||
files, err := self.git.Loaders.CommitFileLoader.GetFilesInDiff(from, to, reverse)
|
files, err := self.c.Git().Loaders.CommitFileLoader.GetFilesInDiff(from, to, reverse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
self.c.Model().CommitFiles = files
|
self.c.Model().CommitFiles = files
|
||||||
self.contexts.CommitFiles.CommitFileTreeViewModel.SetTree()
|
self.c.Contexts().CommitFiles.CommitFileTreeViewModel.SetTree()
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.CommitFiles)
|
return self.c.PostRefreshUpdate(self.c.Contexts().CommitFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshRebaseCommits() error {
|
func (self *RefreshHelper) refreshRebaseCommits() error {
|
||||||
self.c.Mutexes().LocalCommitsMutex.Lock()
|
self.c.Mutexes().LocalCommitsMutex.Lock()
|
||||||
defer self.c.Mutexes().LocalCommitsMutex.Unlock()
|
defer self.c.Mutexes().LocalCommitsMutex.Unlock()
|
||||||
|
|
||||||
updatedCommits, err := self.git.Loaders.CommitLoader.MergeRebasingCommits(self.c.Model().Commits)
|
updatedCommits, err := self.c.Git().Loaders.CommitLoader.MergeRebasingCommits(self.c.Model().Commits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
self.c.Model().Commits = updatedCommits
|
self.c.Model().Commits = updatedCommits
|
||||||
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.git.Status.WorkingTreeState()
|
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState()
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.LocalCommits)
|
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshTags() error {
|
func (self *RefreshHelper) refreshTags() error {
|
||||||
tags, err := self.git.Loaders.TagLoader.GetTags()
|
tags, err := self.c.Git().Loaders.TagLoader.GetTags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.c.Model().Tags = tags
|
self.c.Model().Tags = tags
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.Tags)
|
return self.c.PostRefreshUpdate(self.c.Contexts().Tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshStateSubmoduleConfigs() error {
|
func (self *RefreshHelper) refreshStateSubmoduleConfigs() error {
|
||||||
configs, err := self.git.Submodule.GetConfigs()
|
configs, err := self.c.Git().Submodule.GetConfigs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -363,20 +356,20 @@ func (self *RefreshHelper) refreshBranches() {
|
|||||||
// which allows us to order them correctly. So if we're filtering we'll just
|
// which allows us to order them correctly. So if we're filtering we'll just
|
||||||
// manually load all the reflog commits here
|
// manually load all the reflog commits here
|
||||||
var err error
|
var err error
|
||||||
reflogCommits, _, err = self.git.Loaders.ReflogCommitLoader.GetReflogCommits(nil, "")
|
reflogCommits, _, err = self.c.Git().Loaders.ReflogCommitLoader.GetReflogCommits(nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
self.c.Log.Error(err)
|
self.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
branches, err := self.git.Loaders.BranchLoader.Load(reflogCommits)
|
branches, err := self.c.Git().Loaders.BranchLoader.Load(reflogCommits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = self.c.Error(err)
|
_ = self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.c.Model().Branches = branches
|
self.c.Model().Branches = branches
|
||||||
|
|
||||||
if err := self.c.PostRefreshUpdate(self.contexts.Branches); err != nil {
|
if err := self.c.PostRefreshUpdate(self.c.Contexts().Branches); err != nil {
|
||||||
self.c.Log.Error(err)
|
self.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,11 +393,11 @@ func (self *RefreshHelper) refreshFilesAndSubmodules() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.c.OnUIThread(func() error {
|
self.c.OnUIThread(func() error {
|
||||||
if err := self.c.PostRefreshUpdate(self.contexts.Submodules); err != nil {
|
if err := self.c.PostRefreshUpdate(self.c.Contexts().Submodules); err != nil {
|
||||||
self.c.Log.Error(err)
|
self.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.c.PostRefreshUpdate(self.contexts.Files); err != nil {
|
if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
|
||||||
self.c.Log.Error(err)
|
self.c.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +408,7 @@ func (self *RefreshHelper) refreshFilesAndSubmodules() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshStateFiles() error {
|
func (self *RefreshHelper) refreshStateFiles() error {
|
||||||
fileTreeViewModel := self.contexts.Files.FileTreeViewModel
|
fileTreeViewModel := self.c.Contexts().Files.FileTreeViewModel
|
||||||
|
|
||||||
// If git thinks any of our files have inline merge conflicts, but they actually don't,
|
// If git thinks any of our files have inline merge conflicts, but they actually don't,
|
||||||
// we stage them.
|
// we stage them.
|
||||||
@ -442,12 +435,12 @@ func (self *RefreshHelper) refreshStateFiles() error {
|
|||||||
|
|
||||||
if len(pathsToStage) > 0 {
|
if len(pathsToStage) > 0 {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageResolvedFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageResolvedFiles)
|
||||||
if err := self.git.WorkingTree.StageFiles(pathsToStage); err != nil {
|
if err := self.c.Git().WorkingTree.StageFiles(pathsToStage); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
files := self.git.Loaders.FileLoader.
|
files := self.c.Git().Loaders.FileLoader.
|
||||||
GetStatusFiles(git_commands.GetStatusFileOptions{})
|
GetStatusFiles(git_commands.GetStatusFileOptions{})
|
||||||
|
|
||||||
conflictFileCount := 0
|
conflictFileCount := 0
|
||||||
@ -457,7 +450,7 @@ func (self *RefreshHelper) refreshStateFiles() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 {
|
if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 {
|
||||||
self.c.OnUIThread(func() error { return self.mergeAndRebaseHelper.PromptToContinueRebase() })
|
self.c.OnUIThread(func() error { return self.mergeAndRebaseHelper.PromptToContinueRebase() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +497,7 @@ func (self *RefreshHelper) refreshReflogCommits() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh := func(stateCommits *[]*models.Commit, filterPath string) error {
|
refresh := func(stateCommits *[]*models.Commit, filterPath string) error {
|
||||||
commits, onlyObtainedNewReflogCommits, err := self.git.Loaders.ReflogCommitLoader.
|
commits, onlyObtainedNewReflogCommits, err := self.c.Git().Loaders.ReflogCommitLoader.
|
||||||
GetReflogCommits(lastReflogCommit, filterPath)
|
GetReflogCommits(lastReflogCommit, filterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
@ -530,13 +523,13 @@ func (self *RefreshHelper) refreshReflogCommits() error {
|
|||||||
model.FilteredReflogCommits = model.ReflogCommits
|
model.FilteredReflogCommits = model.ReflogCommits
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.ReflogCommits)
|
return self.c.PostRefreshUpdate(self.c.Contexts().ReflogCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshRemotes() error {
|
func (self *RefreshHelper) refreshRemotes() error {
|
||||||
prevSelectedRemote := self.contexts.Remotes.GetSelected()
|
prevSelectedRemote := self.c.Contexts().Remotes.GetSelected()
|
||||||
|
|
||||||
remotes, err := self.git.Loaders.RemoteLoader.GetRemotes()
|
remotes, err := self.c.Git().Loaders.RemoteLoader.GetRemotes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
@ -554,11 +547,11 @@ func (self *RefreshHelper) refreshRemotes() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.c.PostRefreshUpdate(self.contexts.Remotes); err != nil {
|
if err := self.c.PostRefreshUpdate(self.c.Contexts().Remotes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.c.PostRefreshUpdate(self.contexts.RemoteBranches); err != nil {
|
if err := self.c.PostRefreshUpdate(self.c.Contexts().RemoteBranches); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,10 +559,10 @@ func (self *RefreshHelper) refreshRemotes() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshStashEntries() error {
|
func (self *RefreshHelper) refreshStashEntries() error {
|
||||||
self.c.Model().StashEntries = self.git.Loaders.StashLoader.
|
self.c.Model().StashEntries = self.c.Git().Loaders.StashLoader.
|
||||||
GetStashEntries(self.c.Modes().Filtering.GetPath())
|
GetStashEntries(self.c.Modes().Filtering.GetPath())
|
||||||
|
|
||||||
return self.c.PostRefreshUpdate(self.contexts.Stash)
|
return self.c.PostRefreshUpdate(self.c.Contexts().Stash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// never call this on its own, it should only be called from within refreshCommits()
|
// never call this on its own, it should only be called from within refreshCommits()
|
||||||
@ -588,7 +581,7 @@ func (self *RefreshHelper) refreshStatus() {
|
|||||||
status += presentation.ColoredBranchStatus(currentBranch, self.c.Tr) + " "
|
status += presentation.ColoredBranchStatus(currentBranch, self.c.Tr) + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
workingTreeState := self.git.Status.WorkingTreeState()
|
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||||
if workingTreeState != enums.REBASE_MODE_NONE {
|
if workingTreeState != enums.REBASE_MODE_NONE {
|
||||||
status += style.FgYellow.Sprintf("(%s) ", presentation.FormatWorkingTreeState(workingTreeState))
|
status += style.FgYellow.Sprintf("(%s) ", presentation.FormatWorkingTreeState(workingTreeState))
|
||||||
}
|
}
|
||||||
@ -601,7 +594,7 @@ func (self *RefreshHelper) refreshStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refForLog() string {
|
func (self *RefreshHelper) refForLog() string {
|
||||||
bisectInfo := self.git.Bisect.GetInfo()
|
bisectInfo := self.c.Git().Bisect.GetInfo()
|
||||||
self.c.Model().BisectInfo = bisectInfo
|
self.c.Model().BisectInfo = bisectInfo
|
||||||
|
|
||||||
if !bisectInfo.Started() {
|
if !bisectInfo.Started() {
|
||||||
@ -609,7 +602,7 @@ func (self *RefreshHelper) refForLog() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// need to see if our bisect's current commit is reachable from our 'new' ref.
|
// need to see if our bisect's current commit is reachable from our 'new' ref.
|
||||||
if bisectInfo.Bisecting() && !self.git.Bisect.ReachableFromStart(bisectInfo) {
|
if bisectInfo.Bisecting() && !self.c.Git().Bisect.ReachableFromStart(bisectInfo) {
|
||||||
return bisectInfo.GetNewSha()
|
return bisectInfo.GetNewSha()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
@ -23,23 +21,14 @@ type IRefsHelper interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RefsHelper struct {
|
type RefsHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
contexts *context.ContextTree
|
|
||||||
model *types.Model
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRefsHelper(
|
func NewRefsHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
model *types.Model,
|
|
||||||
) *RefsHelper {
|
) *RefsHelper {
|
||||||
return &RefsHelper{
|
return &RefsHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
contexts: contexts,
|
|
||||||
model: model,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,15 +43,15 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
|||||||
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
|
||||||
|
|
||||||
onSuccess := func() {
|
onSuccess := func() {
|
||||||
self.contexts.Branches.SetSelectedLineIdx(0)
|
self.c.Contexts().Branches.SetSelectedLineIdx(0)
|
||||||
self.contexts.ReflogCommits.SetSelectedLineIdx(0)
|
self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0)
|
||||||
self.contexts.LocalCommits.SetSelectedLineIdx(0)
|
self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
|
||||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||||
self.contexts.LocalCommits.SetLimitCommits(true)
|
self.c.Contexts().LocalCommits.SetLimitCommits(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.WithWaitingStatus(waitingStatus, func() error {
|
return self.c.WithWaitingStatus(waitingStatus, func() error {
|
||||||
if err := self.git.Branch.Checkout(ref, cmdOptions); err != nil {
|
if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil {
|
||||||
// note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
|
// note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
|
||||||
|
|
||||||
if options.OnRefNotFound != nil && strings.Contains(err.Error(), "did not match any file(s) known to git") {
|
if options.OnRefNotFound != nil && strings.Contains(err.Error(), "did not match any file(s) known to git") {
|
||||||
@ -75,15 +64,15 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
|||||||
Title: self.c.Tr.AutoStashTitle,
|
Title: self.c.Tr.AutoStashTitle,
|
||||||
Prompt: self.c.Tr.AutoStashPrompt,
|
Prompt: self.c.Tr.AutoStashPrompt,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
if err := self.git.Stash.Save(self.c.Tr.StashPrefix + ref); err != nil {
|
if err := self.c.Git().Stash.Save(self.c.Tr.StashPrefix + ref); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
if err := self.git.Branch.Checkout(ref, cmdOptions); err != nil {
|
if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
onSuccess()
|
onSuccess()
|
||||||
if err := self.git.Stash.Pop(0); err != nil {
|
if err := self.c.Git().Stash.Pop(0); err != nil {
|
||||||
if err := self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}); err != nil {
|
if err := self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -105,22 +94,22 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefsHelper) GetCheckedOutRef() *models.Branch {
|
func (self *RefsHelper) GetCheckedOutRef() *models.Branch {
|
||||||
if len(self.model.Branches) == 0 {
|
if len(self.c.Model().Branches) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.model.Branches[0]
|
return self.c.Model().Branches[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string) error {
|
func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string) error {
|
||||||
if err := self.git.Commit.ResetToCommit(ref, strength, envVars); err != nil {
|
if err := self.c.Git().Commit.ResetToCommit(ref, strength, envVars); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.contexts.LocalCommits.SetSelectedLineIdx(0)
|
self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
|
||||||
self.contexts.ReflogCommits.SetSelectedLineIdx(0)
|
self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0)
|
||||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||||
self.contexts.LocalCommits.SetLimitCommits(true)
|
self.c.Contexts().LocalCommits.SetLimitCommits(true)
|
||||||
|
|
||||||
if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.BRANCHES, types.REFLOG, types.COMMITS}}); err != nil {
|
if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.BRANCHES, types.REFLOG, types.COMMITS}}); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -173,18 +162,18 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
|
|||||||
InitialContent: suggestedBranchName,
|
InitialContent: suggestedBranchName,
|
||||||
HandleConfirm: func(response string) error {
|
HandleConfirm: func(response string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.CreateBranch)
|
self.c.LogAction(self.c.Tr.Actions.CreateBranch)
|
||||||
if err := self.git.Branch.New(sanitizedBranchName(response), from); err != nil {
|
if err := self.c.Git().Branch.New(sanitizedBranchName(response), from); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.c.CurrentContext() != self.contexts.Branches {
|
if self.c.CurrentContext() != self.c.Contexts().Branches {
|
||||||
if err := self.c.PushContext(self.contexts.Branches); err != nil {
|
if err := self.c.PushContext(self.c.Contexts().Branches); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.contexts.LocalCommits.SetSelectedLineIdx(0)
|
self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
|
||||||
self.contexts.Branches.SetSelectedLineIdx(0)
|
self.c.Contexts().Branches.SetSelectedLineIdx(0)
|
||||||
|
|
||||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||||
},
|
},
|
||||||
|
@ -1,28 +1,20 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StagingHelper struct {
|
type StagingHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStagingHelper(
|
func NewStagingHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
) *StagingHelper {
|
) *StagingHelper {
|
||||||
return &StagingHelper{
|
return &StagingHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,11 +32,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainContext := self.contexts.Staging
|
mainContext := self.c.Contexts().Staging
|
||||||
secondaryContext := self.contexts.StagingSecondary
|
secondaryContext := self.c.Contexts().StagingSecondary
|
||||||
|
|
||||||
var file *models.File
|
var file *models.File
|
||||||
node := self.contexts.Files.GetSelected()
|
node := self.c.Contexts().Files.GetSelected()
|
||||||
if node != nil {
|
if node != nil {
|
||||||
file = node.File
|
file = node.File
|
||||||
}
|
}
|
||||||
@ -53,8 +45,8 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
|
|||||||
return self.handleStagingEscape()
|
return self.handleStagingEscape()
|
||||||
}
|
}
|
||||||
|
|
||||||
mainDiff := self.git.WorkingTree.WorktreeFileDiff(file, true, false, false)
|
mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, false, false)
|
||||||
secondaryDiff := self.git.WorkingTree.WorktreeFileDiff(file, true, true, false)
|
secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, true, false)
|
||||||
|
|
||||||
// grabbing locks here and releasing before we finish the function
|
// grabbing locks here and releasing before we finish the function
|
||||||
// because pushing say the secondary context could mean entering this function
|
// because pushing say the secondary context could mean entering this function
|
||||||
@ -92,9 +84,9 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if secondaryFocused {
|
if secondaryFocused {
|
||||||
self.contexts.StagingSecondary.FocusSelection()
|
self.c.Contexts().StagingSecondary.FocusSelection()
|
||||||
} else {
|
} else {
|
||||||
self.contexts.Staging.FocusSelection()
|
self.c.Contexts().Staging.FocusSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
||||||
@ -111,9 +103,9 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StagingHelper) handleStagingEscape() error {
|
func (self *StagingHelper) handleStagingEscape() error {
|
||||||
return self.c.PushContext(self.contexts.Files)
|
return self.c.PushContext(self.c.Contexts().Files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StagingHelper) secondaryStagingFocused() bool {
|
func (self *StagingHelper) secondaryStagingFocused() bool {
|
||||||
return self.c.CurrentStaticContext().GetKey() == self.contexts.StagingSecondary.GetKey()
|
return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().StagingSecondary.GetKey()
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
@ -35,27 +34,20 @@ type ISuggestionsHelper interface {
|
|||||||
|
|
||||||
type SuggestionsHelper struct {
|
type SuggestionsHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
|
|
||||||
model *types.Model
|
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ISuggestionsHelper = &SuggestionsHelper{}
|
var _ ISuggestionsHelper = &SuggestionsHelper{}
|
||||||
|
|
||||||
func NewSuggestionsHelper(
|
func NewSuggestionsHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
model *types.Model,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
) *SuggestionsHelper {
|
) *SuggestionsHelper {
|
||||||
return &SuggestionsHelper{
|
return &SuggestionsHelper{
|
||||||
c: c,
|
c: c,
|
||||||
model: model,
|
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SuggestionsHelper) getRemoteNames() []string {
|
func (self *SuggestionsHelper) getRemoteNames() []string {
|
||||||
return slices.Map(self.model.Remotes, func(remote *models.Remote) string {
|
return slices.Map(self.c.Model().Remotes, func(remote *models.Remote) string {
|
||||||
return remote.Name
|
return remote.Name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -76,7 +68,7 @@ func (self *SuggestionsHelper) GetRemoteSuggestionsFunc() func(string) []*types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SuggestionsHelper) getBranchNames() []string {
|
func (self *SuggestionsHelper) getBranchNames() []string {
|
||||||
return slices.Map(self.model.Branches, func(branch *models.Branch) string {
|
return slices.Map(self.c.Model().Branches, func(branch *models.Branch) string {
|
||||||
return branch.Name
|
return branch.Name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -102,8 +94,8 @@ func (self *SuggestionsHelper) GetBranchNameSuggestionsFunc() func(string) []*ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
// here we asynchronously fetch the latest set of paths in the repo and store in
|
// here we asynchronously fetch the latest set of paths in the repo and store in
|
||||||
// self.model.FilesTrie. On the main thread we'll be doing a fuzzy search via
|
// self.c.Model().FilesTrie. On the main thread we'll be doing a fuzzy search via
|
||||||
// self.model.FilesTrie. So if we've looked for a file previously, we'll start with
|
// self.c.Model().FilesTrie. So if we've looked for a file previously, we'll start with
|
||||||
// the old trie and eventually it'll be swapped out for the new one.
|
// the old trie and eventually it'll be swapped out for the new one.
|
||||||
// Notably, unlike other suggestion functions we're not showing all the options
|
// Notably, unlike other suggestion functions we're not showing all the options
|
||||||
// if nothing has been typed because there'll be too much to display efficiently
|
// if nothing has been typed because there'll be too much to display efficiently
|
||||||
@ -126,16 +118,16 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type
|
|||||||
})
|
})
|
||||||
|
|
||||||
// cache the trie for future use
|
// cache the trie for future use
|
||||||
self.model.FilesTrie = trie
|
self.c.Model().FilesTrie = trie
|
||||||
|
|
||||||
self.contexts.Suggestions.RefreshSuggestions()
|
self.c.Contexts().Suggestions.RefreshSuggestions()
|
||||||
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
return func(input string) []*types.Suggestion {
|
return func(input string) []*types.Suggestion {
|
||||||
matchingNames := []string{}
|
matchingNames := []string{}
|
||||||
_ = self.model.FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error {
|
_ = self.c.Model().FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error {
|
||||||
matchingNames = append(matchingNames, item.(string))
|
matchingNames = append(matchingNames, item.(string))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -148,7 +140,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SuggestionsHelper) getRemoteBranchNames(separator string) []string {
|
func (self *SuggestionsHelper) getRemoteBranchNames(separator string) []string {
|
||||||
return slices.FlatMap(self.model.Remotes, func(remote *models.Remote) []string {
|
return slices.FlatMap(self.c.Model().Remotes, func(remote *models.Remote) []string {
|
||||||
return slices.Map(remote.Branches, func(branch *models.RemoteBranch) string {
|
return slices.Map(remote.Branches, func(branch *models.RemoteBranch) string {
|
||||||
return fmt.Sprintf("%s%s%s", remote.Name, separator, branch.Name)
|
return fmt.Sprintf("%s%s%s", remote.Name, separator, branch.Name)
|
||||||
})
|
})
|
||||||
@ -160,7 +152,7 @@ func (self *SuggestionsHelper) GetRemoteBranchesSuggestionsFunc(separator string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SuggestionsHelper) getTagNames() []string {
|
func (self *SuggestionsHelper) getTagNames() []string {
|
||||||
return slices.Map(self.model.Tags, func(tag *models.Tag) string {
|
return slices.Map(self.c.Model().Tags, func(tag *models.Tag) string {
|
||||||
return tag.Name
|
return tag.Name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -177,7 +169,7 @@ func (self *SuggestionsHelper) GetRefsSuggestionsFunc() func(string) []*types.Su
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SuggestionsHelper) GetAuthorsSuggestionsFunc() func(string) []*types.Suggestion {
|
func (self *SuggestionsHelper) GetAuthorsSuggestionsFunc() func(string) []*types.Suggestion {
|
||||||
authors := lo.Uniq(slices.Map(self.model.Commits, func(commit *models.Commit) string {
|
authors := lo.Uniq(slices.Map(self.c.Model().Commits, func(commit *models.Commit) string {
|
||||||
return fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail)
|
return fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -10,14 +9,12 @@ import (
|
|||||||
// and the commits context.
|
// and the commits context.
|
||||||
|
|
||||||
type TagsHelper struct {
|
type TagsHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTagsHelper(c *HelperCommon, git *commands.GitCommand) *TagsHelper {
|
func NewTagsHelper(c *HelperCommon) *TagsHelper {
|
||||||
return &TagsHelper{
|
return &TagsHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +53,7 @@ func (self *TagsHelper) handleCreateAnnotatedTag(ref string, onCreate func()) er
|
|||||||
Title: self.c.Tr.TagMessageTitle,
|
Title: self.c.Tr.TagMessageTitle,
|
||||||
HandleConfirm: func(msg string) error {
|
HandleConfirm: func(msg string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
|
self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag)
|
||||||
if err := self.git.Tag.CreateAnnotated(tagName, ref, msg); err != nil {
|
if err := self.c.Git().Tag.CreateAnnotated(tagName, ref, msg); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
return self.afterTagCreate(onCreate)
|
return self.afterTagCreate(onCreate)
|
||||||
@ -71,7 +68,7 @@ func (self *TagsHelper) handleCreateLightweightTag(ref string, onCreate func())
|
|||||||
Title: self.c.Tr.TagNameTitle,
|
Title: self.c.Tr.TagNameTitle,
|
||||||
HandleConfirm: func(tagName string) error {
|
HandleConfirm: func(tagName string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
|
self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag)
|
||||||
if err := self.git.Tag.CreateLightweight(tagName, ref); err != nil {
|
if err := self.c.Git().Tag.CreateLightweight(tagName, ref); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
return self.afterTagCreate(onCreate)
|
return self.afterTagCreate(onCreate)
|
||||||
|
@ -9,8 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UpstreamHelper struct {
|
type UpstreamHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
model *types.Model
|
|
||||||
|
|
||||||
getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion
|
getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion
|
||||||
}
|
}
|
||||||
@ -26,12 +25,10 @@ var _ IUpstreamHelper = &UpstreamHelper{}
|
|||||||
|
|
||||||
func NewUpstreamHelper(
|
func NewUpstreamHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
model *types.Model,
|
|
||||||
getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion,
|
getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion,
|
||||||
) *UpstreamHelper {
|
) *UpstreamHelper {
|
||||||
return &UpstreamHelper{
|
return &UpstreamHelper{
|
||||||
c: c,
|
c: c,
|
||||||
model: model,
|
|
||||||
getRemoteBranchesSuggestionsFunc: getRemoteBranchesSuggestionsFunc,
|
getRemoteBranchesSuggestionsFunc: getRemoteBranchesSuggestionsFunc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,7 +67,7 @@ func (self *UpstreamHelper) PromptForUpstreamWithoutInitialContent(_ *models.Bra
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *UpstreamHelper) GetSuggestedRemote() string {
|
func (self *UpstreamHelper) GetSuggestedRemote() string {
|
||||||
return getSuggestedRemote(self.model.Remotes)
|
return getSuggestedRemote(self.c.Model().Remotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSuggestedRemote(remotes []*models.Remote) string {
|
func getSuggestedRemote(remotes []*models.Remote) string {
|
||||||
|
@ -6,14 +6,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ViewHelper struct {
|
type ViewHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewViewHelper(c *HelperCommon, contexts *context.ContextTree) *ViewHelper {
|
func NewViewHelper(c *HelperCommon, contexts *context.ContextTree) *ViewHelper {
|
||||||
return &ViewHelper{
|
return &ViewHelper{
|
||||||
c: c,
|
c: c,
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +21,7 @@ func (self *ViewHelper) ContextForView(viewName string) (types.Context, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range self.contexts.Flatten() {
|
for _, context := range self.c.Contexts().Flatten() {
|
||||||
if context.GetViewName() == view.Name() {
|
if context.GetViewName() == view.Name() {
|
||||||
return context, true
|
return context, true
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@ -13,14 +12,12 @@ import (
|
|||||||
type WindowHelper struct {
|
type WindowHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
viewHelper *ViewHelper
|
viewHelper *ViewHelper
|
||||||
contexts *context.ContextTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindowHelper(c *HelperCommon, viewHelper *ViewHelper, contexts *context.ContextTree) *WindowHelper {
|
func NewWindowHelper(c *HelperCommon, viewHelper *ViewHelper) *WindowHelper {
|
||||||
return &WindowHelper{
|
return &WindowHelper{
|
||||||
c: c,
|
c: c,
|
||||||
viewHelper: viewHelper,
|
viewHelper: viewHelper,
|
||||||
contexts: contexts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +72,7 @@ func (self *WindowHelper) resetWindowContext(c types.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if viewName == c.GetViewName() && windowName != c.GetWindowName() {
|
if viewName == c.GetViewName() && windowName != c.GetWindowName() {
|
||||||
for _, context := range self.contexts.Flatten() {
|
for _, context := range self.c.Contexts().Flatten() {
|
||||||
if context.GetKey() != c.GetKey() && context.GetWindowName() == windowName {
|
if context.GetKey() != c.GetKey() && context.GetWindowName() == windowName {
|
||||||
self.windowViewNameMap().Set(windowName, context.GetViewName())
|
self.windowViewNameMap().Set(windowName, context.GetViewName())
|
||||||
}
|
}
|
||||||
@ -119,7 +116,7 @@ func (self *WindowHelper) TopViewInWindow(windowName string) *gocui.View {
|
|||||||
|
|
||||||
func (self *WindowHelper) viewNamesInWindow(windowName string) []string {
|
func (self *WindowHelper) viewNamesInWindow(windowName string) []string {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
for _, context := range self.contexts.Flatten() {
|
for _, context := range self.c.Contexts().Flatten() {
|
||||||
if context.GetWindowName() == windowName {
|
if context.GetWindowName() == windowName {
|
||||||
result = append(result, context.GetViewName())
|
result = append(result, context.GetViewName())
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
@ -21,36 +19,27 @@ type IWorkingTreeHelper interface {
|
|||||||
|
|
||||||
type WorkingTreeHelper struct {
|
type WorkingTreeHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
git *commands.GitCommand
|
|
||||||
contexts *context.ContextTree
|
|
||||||
refHelper *RefsHelper
|
refHelper *RefsHelper
|
||||||
model *types.Model
|
|
||||||
setCommitMessage func(message string)
|
setCommitMessage func(message string)
|
||||||
getSavedCommitMessage func() string
|
getSavedCommitMessage func() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWorkingTreeHelper(
|
func NewWorkingTreeHelper(
|
||||||
c *HelperCommon,
|
c *HelperCommon,
|
||||||
git *commands.GitCommand,
|
|
||||||
contexts *context.ContextTree,
|
|
||||||
refHelper *RefsHelper,
|
refHelper *RefsHelper,
|
||||||
model *types.Model,
|
|
||||||
setCommitMessage func(message string),
|
setCommitMessage func(message string),
|
||||||
getSavedCommitMessage func() string,
|
getSavedCommitMessage func() string,
|
||||||
) *WorkingTreeHelper {
|
) *WorkingTreeHelper {
|
||||||
return &WorkingTreeHelper{
|
return &WorkingTreeHelper{
|
||||||
c: c,
|
c: c,
|
||||||
git: git,
|
|
||||||
contexts: contexts,
|
|
||||||
refHelper: refHelper,
|
refHelper: refHelper,
|
||||||
model: model,
|
|
||||||
setCommitMessage: setCommitMessage,
|
setCommitMessage: setCommitMessage,
|
||||||
getSavedCommitMessage: getSavedCommitMessage,
|
getSavedCommitMessage: getSavedCommitMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
||||||
for _, file := range self.model.Files {
|
for _, file := range self.c.Model().Files {
|
||||||
if file.HasStagedChanges {
|
if file.HasStagedChanges {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -59,7 +48,7 @@ func (self *WorkingTreeHelper) AnyStagedFiles() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
|
func (self *WorkingTreeHelper) AnyTrackedFiles() bool {
|
||||||
for _, file := range self.model.Files {
|
for _, file := range self.c.Model().Files {
|
||||||
if file.Tracked {
|
if file.Tracked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -72,7 +61,7 @@ func (self *WorkingTreeHelper) IsWorkingTreeDirty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
|
func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
|
||||||
for _, file := range self.model.Files {
|
for _, file := range self.c.Model().Files {
|
||||||
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
|
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
@ -88,7 +77,7 @@ func (self *WorkingTreeHelper) OpenMergeTool() error {
|
|||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.OpenMergeTool)
|
self.c.LogAction(self.c.Tr.Actions.OpenMergeTool)
|
||||||
return self.c.RunSubprocessAndRefresh(
|
return self.c.RunSubprocessAndRefresh(
|
||||||
self.git.WorkingTree.OpenMergeToolCmdObj(),
|
self.c.Git().WorkingTree.OpenMergeToolCmdObj(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -99,7 +88,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error {
|
|||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(self.model.Files) == 0 {
|
if len(self.c.Model().Files) == 0 {
|
||||||
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +113,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := self.c.PushContext(self.contexts.CommitMessage); err != nil {
|
if err := self.c.PushContext(self.c.Contexts().CommitMessage); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +123,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error {
|
|||||||
// HandleCommitEditorPress - handle when the user wants to commit changes via
|
// HandleCommitEditorPress - handle when the user wants to commit changes via
|
||||||
// their editor rather than via the popup panel
|
// their editor rather than via the popup panel
|
||||||
func (self *WorkingTreeHelper) HandleCommitEditorPress() error {
|
func (self *WorkingTreeHelper) HandleCommitEditorPress() error {
|
||||||
if len(self.model.Files) == 0 {
|
if len(self.c.Model().Files) == 0 {
|
||||||
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +133,7 @@ func (self *WorkingTreeHelper) HandleCommitEditorPress() error {
|
|||||||
|
|
||||||
self.c.LogAction(self.c.Tr.Actions.Commit)
|
self.c.LogAction(self.c.Tr.Actions.Commit)
|
||||||
return self.c.RunSubprocessAndRefresh(
|
return self.c.RunSubprocessAndRefresh(
|
||||||
self.git.Commit.CommitEditorCmdObj(),
|
self.c.Git().Commit.CommitEditorCmdObj(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +154,7 @@ func (self *WorkingTreeHelper) PromptToStageAllAndRetry(retry func() error) erro
|
|||||||
Prompt: self.c.Tr.NoFilesStagedPrompt,
|
Prompt: self.c.Tr.NoFilesStagedPrompt,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
||||||
if err := self.git.WorkingTree.StageAll(); err != nil {
|
if err := self.c.Git().WorkingTree.StageAll(); err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
if err := self.syncRefresh(); err != nil {
|
if err := self.syncRefresh(); err != nil {
|
||||||
@ -186,7 +175,7 @@ func (self *WorkingTreeHelper) prepareFilesForCommit() error {
|
|||||||
noStagedFiles := !self.AnyStagedFiles()
|
noStagedFiles := !self.AnyStagedFiles()
|
||||||
if noStagedFiles && self.c.UserConfig.Gui.SkipNoStagedFilesWarning {
|
if noStagedFiles && self.c.UserConfig.Gui.SkipNoStagedFilesWarning {
|
||||||
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
self.c.LogAction(self.c.Tr.Actions.StageAllFiles)
|
||||||
err := self.git.WorkingTree.StageAll()
|
err := self.c.Git().WorkingTree.StageAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user