1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/submodules_panel.go

50 lines
1.2 KiB
Go
Raw Normal View History

2020-09-30 00:27:23 +02:00
package gui
import (
"fmt"
"os"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/style"
2020-09-30 00:27:23 +02:00
)
func (gui *Gui) submodulesRenderToMain() error {
2020-09-30 00:27:23 +02:00
var task updateTask
2022-02-05 08:04:10 +02:00
submodule := gui.State.Contexts.Submodules.GetSelected()
2020-09-30 00:27:23 +02:00
if submodule == nil {
2021-04-04 15:51:59 +02:00
task = NewRenderStringTask("No submodules")
2020-09-30 00:27:23 +02:00
} else {
prefix := fmt.Sprintf(
"Name: %s\nPath: %s\nUrl: %s\n\n",
style.FgGreen.Sprint(submodule.Name),
style.FgYellow.Sprint(submodule.Path),
style.FgCyan.Sprint(submodule.Url),
2020-09-30 00:27:23 +02:00
)
2022-01-31 13:11:34 +02:00
file := gui.helpers.WorkingTree.FileForSubmodule(submodule)
if file == nil {
2021-04-04 15:51:59 +02:00
task = NewRenderStringTask(prefix)
} else {
cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, gui.IgnoreWhitespaceInDiffView)
2021-12-07 12:59:36 +02:00
task = NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
}
2020-09-30 00:27:23 +02:00
}
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
title: "Submodule",
task: task,
},
})
}
func (gui *Gui) enterSubmodule(submodule *models.SubmoduleConfig) error {
wd, err := os.Getwd()
if err != nil {
return err
}
2022-01-28 11:44:36 +02:00
gui.RepoPathStack.Push(wd)
2020-09-30 00:27:23 +02:00
return gui.dispatchSwitchToRepo(submodule.Path, true)
2020-09-30 00:27:23 +02:00
}