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