2020-08-22 00:49:02 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
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
|
|
|
|
commits := gui.State.SubCommits
|
|
|
|
if selectedLine == -1 || len(commits) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return commits[selectedLine]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleSubCommitSelect() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
var task updateTask
|
|
|
|
if commit == nil {
|
|
|
|
task = gui.createRenderStringTask("No commits")
|
|
|
|
} else {
|
|
|
|
cmd := gui.OSCommand.ExecutableFromString(
|
2021-04-03 02:32:14 +02:00
|
|
|
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()),
|
2020-08-22 00:49:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
task = gui.createRunPtyTask(cmd)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
err := gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.LcCheckoutCommit,
|
|
|
|
prompt: gui.Tr.SureCheckoutThisCommit,
|
2020-08-22 00:49:02 +02:00
|
|
|
handleConfirm: func() error {
|
|
|
|
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.State.Panels.SubCommits.SelectedLineIdx = 0
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCreateSubCommitResetMenu() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
|
|
|
|
return gui.createResetMenu(commit.Sha)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleViewSubCommitFiles() error {
|
|
|
|
commit := gui.getSelectedSubCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-03 02:32:14 +02:00
|
|
|
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.SubCommits, "branches")
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) switchToSubCommitsContext(refName string) error {
|
|
|
|
// need to populate my sub commits
|
2020-08-27 12:50:30 +02:00
|
|
|
builder := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr)
|
2020-08-22 00:49:02 +02:00
|
|
|
|
|
|
|
commits, err := builder.GetCommits(
|
|
|
|
commands.GetCommitsOptions{
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.State.SubCommits = commits
|
|
|
|
gui.State.Panels.SubCommits.refName = refName
|
|
|
|
gui.State.Panels.SubCommits.SelectedLineIdx = 0
|
2021-04-03 02:32:14 +02:00
|
|
|
gui.Contexts.SubCommits.SetParentContext(gui.currentSideContext())
|
2020-08-22 00:49:02 +02:00
|
|
|
|
2021-04-03 02:32:14 +02:00
|
|
|
return gui.pushContext(gui.Contexts.SubCommits)
|
2020-08-22 00:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleSwitchToSubCommits() error {
|
|
|
|
currentContext := gui.currentSideContext()
|
|
|
|
if currentContext == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return gui.switchToSubCommitsContext(currentContext.GetSelectedItemId())
|
|
|
|
}
|