2020-08-22 00:49:02 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2021-12-30 04:35:10 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2020-08-22 00:49:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// list panel functions
|
|
|
|
|
2020-09-29 10:36:54 +02:00
|
|
|
func (gui *Gui) getSelectedSubCommit() *models.Commit {
|
2020-08-22 00:49:02 +02:00
|
|
|
selectedLine := gui.State.Panels.SubCommits.SelectedLineIdx
|
2022-01-31 13:11:34 +02:00
|
|
|
commits := gui.State.Model.SubCommits
|
2020-08-22 00:49:02 +02:00
|
|
|
if selectedLine == -1 || len(commits) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return commits[selectedLine]
|
|
|
|
}
|
|
|
|
|
2021-11-21 03:48:49 +02:00
|
|
|
func (gui *Gui) subCommitsRenderToMain() error {
|
2020-08-22 00:49:02 +02:00
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
var task updateTask
|
|
|
|
if commit == nil {
|
2021-04-04 15:51:59 +02:00
|
|
|
task = NewRenderStringTask("No commits")
|
2020-08-22 00:49:02 +02:00
|
|
|
} else {
|
2022-01-16 05:46:53 +02:00
|
|
|
cmdObj := gui.git.Commit.ShowCmdObj(commit.Sha, gui.State.Modes.Filtering.GetPath())
|
2020-08-22 00:49:02 +02:00
|
|
|
|
2021-12-07 12:59:36 +02:00
|
|
|
task = NewRunPtyTask(cmdObj.GetCmd())
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
|
|
|
|
2020-08-23 01:46:28 +02:00
|
|
|
return gui.refreshMainViews(refreshMainOpts{
|
2020-08-22 00:49:02 +02:00
|
|
|
main: &viewUpdateOpts{
|
|
|
|
title: "Commit",
|
|
|
|
task: task,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCheckoutSubCommit() error {
|
2020-08-22 00:49:02 +02:00
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
err := gui.c.Ask(types.AskOpts{
|
2022-01-16 05:46:53 +02:00
|
|
|
Title: gui.c.Tr.LcCheckoutCommit,
|
|
|
|
Prompt: gui.c.Tr.SureCheckoutThisCommit,
|
2022-01-28 11:44:36 +02:00
|
|
|
HandleConfirm: func() error {
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.CheckoutCommit)
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.helpers.Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{})
|
2020-08-22 00:49:02 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.State.Contexts.SubCommits.GetPanelState().SetSelectedLineIdx(0)
|
2020-08-22 00:49:02 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCreateSubCommitResetMenu() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.helpers.Refs.CreateGitResetMenu(commit.Sha)
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleViewSubCommitFiles() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.SwitchToCommitFilesContext(controllers.SwitchToCommitFilesContextOpts{
|
|
|
|
RefName: commit.Sha,
|
|
|
|
CanRebase: false,
|
|
|
|
Context: gui.State.Contexts.SubCommits,
|
|
|
|
WindowName: "branches",
|
|
|
|
})
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) switchToSubCommitsContext(refName string) error {
|
|
|
|
// need to populate my sub commits
|
2022-01-16 05:46:53 +02:00
|
|
|
commits, err := gui.git.Loaders.Commits.GetCommits(
|
2021-12-30 04:35:10 +02:00
|
|
|
loaders.GetCommitsOptions{
|
2020-08-22 00:49:02 +02:00
|
|
|
Limit: gui.State.Panels.Commits.LimitCommits,
|
2021-04-03 02:32:14 +02:00
|
|
|
FilterPath: gui.State.Modes.Filtering.GetPath(),
|
2020-08-22 00:49:02 +02:00
|
|
|
IncludeRebaseCommits: false,
|
|
|
|
RefName: refName,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.State.Model.SubCommits = commits
|
2020-08-22 00:49:02 +02:00
|
|
|
gui.State.Panels.SubCommits.refName = refName
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.State.Contexts.SubCommits.GetPanelState().SetSelectedLineIdx(0)
|
2021-04-04 15:51:59 +02:00
|
|
|
gui.State.Contexts.SubCommits.SetParentContext(gui.currentSideListContext())
|
2020-08-22 00:49:02 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.PushContext(gui.State.Contexts.SubCommits)
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
2022-01-30 11:03:08 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleNewBranchOffSubCommit() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.helpers.Refs.NewBranch(commit.RefName(), commit.Description(), "")
|
2022-01-30 11:03:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCopySubCommit() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.helpers.CherryPick.Copy(commit, gui.State.Model.SubCommits, gui.State.Contexts.SubCommits)
|
2022-01-30 11:03:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCopySubCommitRange() error {
|
|
|
|
// just doing this to ensure something is selected
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.helpers.CherryPick.CopyRange(gui.State.Contexts.SubCommits.GetPanelState().GetSelectedLineIdx(), gui.State.Model.SubCommits, gui.State.Contexts.SubCommits)
|
2022-01-30 11:03:08 +02:00
|
|
|
}
|