2020-09-30 00:27:23 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2020-09-30 00:27:23 +02:00
|
|
|
)
|
|
|
|
|
2021-11-21 03:48:49 +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 {
|
2020-10-01 00:18:16 +02:00
|
|
|
prefix := fmt.Sprintf(
|
|
|
|
"Name: %s\nPath: %s\nUrl: %s\n\n",
|
2021-07-27 15:00:37 +02:00
|
|
|
style.FgGreen.Sprint(submodule.Name),
|
|
|
|
style.FgYellow.Sprint(submodule.Path),
|
|
|
|
style.FgCyan.Sprint(submodule.Url),
|
2020-09-30 00:27:23 +02:00
|
|
|
)
|
2020-10-01 00:18:16 +02:00
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
file := gui.helpers.WorkingTree.FileForSubmodule(submodule)
|
2020-10-01 00:18:16 +02:00
|
|
|
if file == nil {
|
2021-04-04 15:51:59 +02:00
|
|
|
task = NewRenderStringTask(prefix)
|
2020-10-01 00:18:16 +02:00
|
|
|
} else {
|
2022-01-16 05:46:53 +02:00
|
|
|
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-10-01 00:18:16 +02:00
|
|
|
}
|
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
|
|
|
|
2021-04-05 05:22:03 +02:00
|
|
|
return gui.dispatchSwitchToRepo(submodule.Path, true)
|
2020-09-30 00:27:23 +02:00
|
|
|
}
|