2020-09-30 08:27:23 +10: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 08:27:23 +10:00
|
|
|
)
|
|
|
|
|
2021-11-21 12:48:49 +11:00
|
|
|
func (gui *Gui) submodulesRenderToMain() error {
|
2020-09-30 08:27:23 +10:00
|
|
|
var task updateTask
|
2022-02-05 17:04:10 +11:00
|
|
|
submodule := gui.State.Contexts.Submodules.GetSelected()
|
2020-09-30 08:27:23 +10:00
|
|
|
if submodule == nil {
|
2021-04-04 23:51:59 +10:00
|
|
|
task = NewRenderStringTask("No submodules")
|
2020-09-30 08:27:23 +10:00
|
|
|
} else {
|
2020-10-01 08:18:16 +10: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 08:27:23 +10:00
|
|
|
)
|
2020-10-01 08:18:16 +10:00
|
|
|
|
2022-01-31 22:11:34 +11:00
|
|
|
file := gui.helpers.WorkingTree.FileForSubmodule(submodule)
|
2020-10-01 08:18:16 +10:00
|
|
|
if file == nil {
|
2021-04-04 23:51:59 +10:00
|
|
|
task = NewRenderStringTask(prefix)
|
2020-10-01 08:18:16 +10:00
|
|
|
} else {
|
2022-01-16 14:46:53 +11:00
|
|
|
cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, gui.IgnoreWhitespaceInDiffView)
|
2021-12-07 21:59:36 +11:00
|
|
|
task = NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
|
2020-10-01 08:18:16 +10:00
|
|
|
}
|
2020-09-30 08:27:23 +10: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 20:44:36 +11:00
|
|
|
gui.RepoPathStack.Push(wd)
|
2020-09-30 08:27:23 +10:00
|
|
|
|
2021-04-05 13:22:03 +10:00
|
|
|
return gui.dispatchSwitchToRepo(submodule.Path, true)
|
2020-09-30 08:27:23 +10:00
|
|
|
}
|