diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-05 11:55:04 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-05 19:22:01 +1100 |
commit | f285d80d0ef17860d9180759f756140fb40d967f (patch) | |
tree | b7893b54c5051062f1e0c91f13db5fd411c28961 | |
parent | 0ffccbd3ee952a441575f378ce70b8be94e9f3c5 (diff) |
move PatchManager to GitCommand
-rw-r--r-- | pkg/commands/git.go | 1 | ||||
-rw-r--r-- | pkg/gui/commit_files_panel.go | 18 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 1 | ||||
-rw-r--r-- | pkg/gui/patch_options_panel.go | 14 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 8 |
6 files changed, 23 insertions, 23 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index f9f6e723d..b9b37ab80 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -74,6 +74,7 @@ type GitCommand struct { removeFile func(string) error DotGitDir string onSuccessfulContinue func() error + PatchManager *PatchManager } // NewGitCommand it runs git commands diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 2ee108116..43bc8ee22 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -93,7 +93,7 @@ func (gui *Gui) refreshCommitFilesView() error { 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 { 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 { - if gui.State.PatchManager == nil { + if gui.GitCommand.PatchManager == nil { if err := gui.createPatchManager(); err != nil { return err } } - gui.State.PatchManager.ToggleFileWhole(commitFile.Name) + gui.GitCommand.PatchManager.ToggleFileWhole(commitFile.Name) 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 { - gui.State.PatchManager = nil + gui.GitCommand.PatchManager = nil return toggleTheFile() }, nil) } @@ -160,7 +160,7 @@ func (gui *Gui) createPatchManager() error { 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 } @@ -175,7 +175,7 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { } enterTheFile := func() error { - if gui.State.PatchManager == nil { + if gui.GitCommand.PatchManager == nil { if err := gui.createPatchManager(); err != nil { return err } @@ -190,9 +190,9 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { 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 { - gui.State.PatchManager = nil + gui.GitCommand.PatchManager = nil return enterTheFile() }, nil) } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index b22e6084e..667b6b54f 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -53,14 +53,14 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) refreshPatchPanel() error { - if gui.State.PatchManager != nil { + if gui.GitCommand.PatchManager != nil { gui.State.SplitMainPanel = true secondaryView := gui.getSecondaryView() secondaryView.Highlight = true secondaryView.Wrap = false 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 { gui.State.SplitMainPanel = false diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index ea71d9dca..54c85bfe4 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -151,7 +151,6 @@ type guiState struct { Contexts map[string]string CherryPickedCommits []*commands.Commit SplitMainPanel bool - PatchManager *commands.PatchManager } // for now the split view will always be on diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 5e2329703..41e3056a8 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -17,7 +17,7 @@ func (o *patchMenuOption) GetDisplayStrings(isFocused bool) []string { } func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error { - m := gui.State.PatchManager + m := gui.GitCommand.PatchManager if m == nil { 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) - if selectedCommit != nil && gui.State.PatchManager.CommitSha != selectedCommit.Sha { + if selectedCommit != nil && gui.GitCommand.PatchManager.CommitSha != selectedCommit.Sha { options = append(options, &patchMenuOption{ displayName: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), function: gui.handleMovePatchToSelectedCommit, @@ -46,7 +46,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error func (gui *Gui) getPatchCommitIndex() int { for index, commit := range gui.State.Commits { - if commit.Sha == gui.State.PatchManager.CommitSha { + if commit.Sha == gui.GitCommand.PatchManager.CommitSha { return index } } @@ -60,7 +60,7 @@ func (gui *Gui) handleDeletePatchFromCommit() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { 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) }) } @@ -72,7 +72,7 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { 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) }) } @@ -91,12 +91,12 @@ func (gui *Gui) handlePullPatchIntoWorkingTree() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { 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) }) } func (gui *Gui) handleClearPatch() error { - gui.State.PatchManager = nil + gui.GitCommand.PatchManager = nil return gui.refreshCommitFilesView() } diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 0a47d0a76..13878e2f0 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -68,7 +68,7 @@ func (gui *Gui) refreshStagingPanel() error { return err } - secondaryColorDiff := gui.State.PatchManager.RenderPatchForFile(commitFile.Name, false, false) + secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false) if err != nil { return err } @@ -220,7 +220,7 @@ func (gui *Gui) refreshView() error { 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.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")) } - 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 { 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")) } - 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 { return err |