mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-19 21:28:28 +02:00
move PatchManager to GitCommand
This commit is contained in:
parent
0ffccbd3ee
commit
f285d80d0e
@ -74,6 +74,7 @@ type GitCommand struct {
|
|||||||
removeFile func(string) error
|
removeFile func(string) error
|
||||||
DotGitDir string
|
DotGitDir string
|
||||||
onSuccessfulContinue func() error
|
onSuccessfulContinue func() error
|
||||||
|
PatchManager *PatchManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGitCommand it runs git commands
|
// NewGitCommand it runs git commands
|
||||||
|
@ -93,7 +93,7 @@ func (gui *Gui) refreshCommitFilesView() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := gui.GitCommand.GetCommitFiles(commit.Sha, gui.State.PatchManager)
|
files, err := gui.GitCommand.GetCommitFiles(commit.Sha, gui.GitCommand.PatchManager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
}
|
}
|
||||||
@ -124,20 +124,20 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleTheFile := func() error {
|
toggleTheFile := func() error {
|
||||||
if gui.State.PatchManager == nil {
|
if gui.GitCommand.PatchManager == nil {
|
||||||
if err := gui.createPatchManager(); err != nil {
|
if err := gui.createPatchManager(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.PatchManager.ToggleFileWhole(commitFile.Name)
|
gui.GitCommand.PatchManager.ToggleFileWhole(commitFile.Name)
|
||||||
|
|
||||||
return gui.refreshCommitFilesView()
|
return gui.refreshCommitFilesView()
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.State.PatchManager != nil && gui.State.PatchManager.CommitSha != commitFile.Sha {
|
if gui.GitCommand.PatchManager != nil && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha {
|
||||||
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
gui.State.PatchManager = nil
|
gui.GitCommand.PatchManager = nil
|
||||||
return toggleTheFile()
|
return toggleTheFile()
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ func (gui *Gui) createPatchManager() error {
|
|||||||
return errors.New("No commit selected")
|
return errors.New("No commit selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.PatchManager = commands.NewPatchManager(gui.Log, gui.GitCommand.ApplyPatch, commit.Sha, diffMap)
|
gui.GitCommand.PatchManager = commands.NewPatchManager(gui.Log, gui.GitCommand.ApplyPatch, commit.Sha, diffMap)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enterTheFile := func() error {
|
enterTheFile := func() error {
|
||||||
if gui.State.PatchManager == nil {
|
if gui.GitCommand.PatchManager == nil {
|
||||||
if err := gui.createPatchManager(); err != nil {
|
if err := gui.createPatchManager(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -190,9 +190,9 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.refreshStagingPanel()
|
return gui.refreshStagingPanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.State.PatchManager != nil && gui.State.PatchManager.CommitSha != commitFile.Sha {
|
if gui.GitCommand.PatchManager != nil && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha {
|
||||||
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
gui.State.PatchManager = nil
|
gui.GitCommand.PatchManager = nil
|
||||||
return enterTheFile()
|
return enterTheFile()
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,14 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshPatchPanel() error {
|
func (gui *Gui) refreshPatchPanel() error {
|
||||||
if gui.State.PatchManager != nil {
|
if gui.GitCommand.PatchManager != nil {
|
||||||
gui.State.SplitMainPanel = true
|
gui.State.SplitMainPanel = true
|
||||||
secondaryView := gui.getSecondaryView()
|
secondaryView := gui.getSecondaryView()
|
||||||
secondaryView.Highlight = true
|
secondaryView.Highlight = true
|
||||||
secondaryView.Wrap = false
|
secondaryView.Wrap = false
|
||||||
|
|
||||||
gui.g.Update(func(*gocui.Gui) error {
|
gui.g.Update(func(*gocui.Gui) error {
|
||||||
return gui.setViewContent(gui.g, gui.getSecondaryView(), gui.State.PatchManager.RenderAggregatedPatchColored(false))
|
return gui.setViewContent(gui.g, gui.getSecondaryView(), gui.GitCommand.PatchManager.RenderAggregatedPatchColored(false))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
gui.State.SplitMainPanel = false
|
gui.State.SplitMainPanel = false
|
||||||
|
@ -151,7 +151,6 @@ type guiState struct {
|
|||||||
Contexts map[string]string
|
Contexts map[string]string
|
||||||
CherryPickedCommits []*commands.Commit
|
CherryPickedCommits []*commands.Commit
|
||||||
SplitMainPanel bool
|
SplitMainPanel bool
|
||||||
PatchManager *commands.PatchManager
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now the split view will always be on
|
// for now the split view will always be on
|
||||||
|
@ -17,7 +17,7 @@ func (o *patchMenuOption) GetDisplayStrings(isFocused bool) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
m := gui.State.PatchManager
|
m := gui.GitCommand.PatchManager
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedCommit := gui.getSelectedCommit(gui.g)
|
selectedCommit := gui.getSelectedCommit(gui.g)
|
||||||
if selectedCommit != nil && gui.State.PatchManager.CommitSha != selectedCommit.Sha {
|
if selectedCommit != nil && gui.GitCommand.PatchManager.CommitSha != selectedCommit.Sha {
|
||||||
options = append(options, &patchMenuOption{
|
options = append(options, &patchMenuOption{
|
||||||
displayName: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
|
displayName: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
|
||||||
function: gui.handleMovePatchToSelectedCommit,
|
function: gui.handleMovePatchToSelectedCommit,
|
||||||
@ -46,7 +46,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error
|
|||||||
|
|
||||||
func (gui *Gui) getPatchCommitIndex() int {
|
func (gui *Gui) getPatchCommitIndex() int {
|
||||||
for index, commit := range gui.State.Commits {
|
for index, commit := range gui.State.Commits {
|
||||||
if commit.Sha == gui.State.PatchManager.CommitSha {
|
if commit.Sha == gui.GitCommand.PatchManager.CommitSha {
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func (gui *Gui) handleDeletePatchFromCommit() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
commitIndex := gui.getPatchCommitIndex()
|
||||||
err := gui.GitCommand.DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.State.PatchManager)
|
err := gui.GitCommand.DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
|
||||||
return gui.handleGenericMergeCommandResult(err)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
commitIndex := gui.getPatchCommitIndex()
|
||||||
err := gui.GitCommand.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLine, gui.State.PatchManager)
|
err := gui.GitCommand.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLine, gui.GitCommand.PatchManager)
|
||||||
return gui.handleGenericMergeCommandResult(err)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -91,12 +91,12 @@ func (gui *Gui) handlePullPatchIntoWorkingTree() error {
|
|||||||
|
|
||||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
|
||||||
commitIndex := gui.getPatchCommitIndex()
|
commitIndex := gui.getPatchCommitIndex()
|
||||||
err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.State.PatchManager)
|
err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
|
||||||
return gui.handleGenericMergeCommandResult(err)
|
return gui.handleGenericMergeCommandResult(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleClearPatch() error {
|
func (gui *Gui) handleClearPatch() error {
|
||||||
gui.State.PatchManager = nil
|
gui.GitCommand.PatchManager = nil
|
||||||
return gui.refreshCommitFilesView()
|
return gui.refreshCommitFilesView()
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (gui *Gui) refreshStagingPanel() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
secondaryColorDiff := gui.State.PatchManager.RenderPatchForFile(commitFile.Name, false, false)
|
secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ func (gui *Gui) refreshView() error {
|
|||||||
|
|
||||||
filename := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name
|
filename := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name
|
||||||
|
|
||||||
colorDiff := state.PatchParser.Render(state.FirstLineIdx, state.LastLineIdx, gui.State.PatchManager.GetFileIncLineIndices(filename))
|
colorDiff := state.PatchParser.Render(state.FirstLineIdx, state.LastLineIdx, gui.GitCommand.PatchManager.GetFileIncLineIndices(filename))
|
||||||
|
|
||||||
mainView := gui.getMainView()
|
mainView := gui.getMainView()
|
||||||
mainView.Highlight = true
|
mainView.Highlight = true
|
||||||
@ -283,7 +283,7 @@ func (gui *Gui) handleStageSelection(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.PatchManager.AddFileLineRange(commitFile.Name, state.FirstLineIdx, state.LastLineIdx)
|
gui.GitCommand.PatchManager.AddFileLineRange(commitFile.Name, state.FirstLineIdx, state.LastLineIdx)
|
||||||
|
|
||||||
if err := gui.refreshCommitFilesView(); err != nil {
|
if err := gui.refreshCommitFilesView(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -307,7 +307,7 @@ func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.PatchManager.RemoveFileLineRange(commitFile.Name, state.FirstLineIdx, state.LastLineIdx)
|
gui.GitCommand.PatchManager.RemoveFileLineRange(commitFile.Name, state.FirstLineIdx, state.LastLineIdx)
|
||||||
|
|
||||||
if err := gui.refreshCommitFilesView(); err != nil {
|
if err := gui.refreshCommitFilesView(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user