1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-08 04:04:22 +02:00
lazygit/pkg/gui/submodules_panel.go

52 lines
1.3 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"
"github.com/jesseduffield/lazygit/pkg/gui/types"
2020-09-30 00:27:23 +02:00
)
func (gui *Gui) submodulesRenderToMain() error {
var task types.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 {
task = types.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 {
task = types.NewRenderStringTask(prefix)
} else {
cmdObj := gui.git.WorkingTree.WorktreeFileDiffCmdObj(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, gui.IgnoreWhitespaceInDiffView)
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
}
2020-09-30 00:27:23 +02:00
}
return gui.c.RenderToMainViews(types.RefreshMainOpts{
Pair: gui.c.MainViewPairs().Normal,
Main: &types.ViewUpdateOpts{
Title: "Submodule",
Task: task,
2020-09-30 00:27:23 +02:00
},
})
}
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
}