mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
showing changes for directories
This commit is contained in:
parent
9f2d7adb8e
commit
77a7619690
@ -158,23 +158,22 @@ func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *GitCommand) WorktreeFileDiffCmdStr(file *models.File, plain bool, cached bool) string {
|
||||
func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IStatusLine, plain bool, cached bool) string {
|
||||
cachedArg := ""
|
||||
trackedArg := "--"
|
||||
colorArg := c.colorArg()
|
||||
split := strings.Split(file.Name, models.RENAME_SEPARATOR) // in case of a renamed file we get the new filename
|
||||
fileName := c.OSCommand.Quote(split[len(split)-1])
|
||||
path := c.OSCommand.Quote(node.GetPath())
|
||||
if cached {
|
||||
cachedArg = "--cached"
|
||||
}
|
||||
if !file.Tracked && !file.HasStagedChanges && !cached {
|
||||
if !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached {
|
||||
trackedArg = "--no-index -- /dev/null"
|
||||
}
|
||||
if plain {
|
||||
colorArg = "never"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, fileName)
|
||||
return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, path)
|
||||
}
|
||||
|
||||
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
||||
|
@ -59,3 +59,20 @@ func (f *File) SubmoduleConfig(configs []*SubmoduleConfig) *SubmoduleConfig {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) GetHasUnstagedChanges() bool {
|
||||
return f.HasUnstagedChanges
|
||||
}
|
||||
|
||||
func (f *File) GetHasStagedChanges() bool {
|
||||
return f.HasStagedChanges
|
||||
}
|
||||
|
||||
func (f *File) GetIsTracked() bool {
|
||||
return f.Tracked
|
||||
}
|
||||
|
||||
func (f *File) GetPath() string {
|
||||
names := f.Names()
|
||||
return names[len(names)-1]
|
||||
}
|
||||
|
8
pkg/commands/models/status_line.go
Normal file
8
pkg/commands/models/status_line.go
Normal file
@ -0,0 +1,8 @@
|
||||
package models
|
||||
|
||||
type IStatusLine interface {
|
||||
GetHasUnstagedChanges() bool
|
||||
GetHasStagedChanges() bool
|
||||
GetIsTracked() bool
|
||||
GetPath() string
|
||||
}
|
@ -20,23 +20,23 @@ func (s *StatusLineNode) GetShortStatus() string {
|
||||
|
||||
firstChar := " "
|
||||
secondChar := " "
|
||||
if s.HasStagedChanges() {
|
||||
if s.GetHasStagedChanges() {
|
||||
firstChar = "M"
|
||||
}
|
||||
if s.HasUnstagedChanges() {
|
||||
if s.GetHasUnstagedChanges() {
|
||||
secondChar = "M"
|
||||
}
|
||||
|
||||
return firstChar + secondChar
|
||||
}
|
||||
|
||||
func (s *StatusLineNode) HasUnstagedChanges() bool {
|
||||
func (s *StatusLineNode) GetHasUnstagedChanges() bool {
|
||||
if s.IsLeaf() {
|
||||
return s.File.HasUnstagedChanges
|
||||
}
|
||||
|
||||
for _, child := range s.Children {
|
||||
if child.HasUnstagedChanges() {
|
||||
if child.GetHasUnstagedChanges() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -44,13 +44,13 @@ func (s *StatusLineNode) HasUnstagedChanges() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *StatusLineNode) HasStagedChanges() bool {
|
||||
func (s *StatusLineNode) GetHasStagedChanges() bool {
|
||||
if s.IsLeaf() {
|
||||
return s.File.HasStagedChanges
|
||||
}
|
||||
|
||||
for _, child := range s.Children {
|
||||
if child.HasStagedChanges() {
|
||||
if child.GetHasStagedChanges() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -136,3 +136,16 @@ func (s *StatusLineNode) sortChildren() {
|
||||
// TODO: think about making this in-place
|
||||
s.Children = sortedChildren
|
||||
}
|
||||
|
||||
func (s *StatusLineNode) GetIsTracked() bool {
|
||||
if s.File != nil {
|
||||
return s.File.GetIsTracked()
|
||||
}
|
||||
|
||||
// pretty sure I'm allowed to do this
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *StatusLineNode) GetPath() string {
|
||||
return s.Path
|
||||
}
|
||||
|
@ -46,8 +46,9 @@ func (gui *Gui) getSelectedFile() *models.File {
|
||||
func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx)
|
||||
|
||||
file := gui.getSelectedFile()
|
||||
if file == nil {
|
||||
node := gui.getSelectedStatusNode()
|
||||
|
||||
if node == nil {
|
||||
return gui.refreshMainViews(refreshMainOpts{
|
||||
main: &viewUpdateOpts{
|
||||
title: "",
|
||||
@ -66,11 +67,11 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
if file.HasInlineMergeConflicts {
|
||||
if node.File != nil && node.File.HasInlineMergeConflicts {
|
||||
return gui.refreshMergePanel()
|
||||
}
|
||||
|
||||
cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(file, false, !file.HasUnstagedChanges && file.HasStagedChanges)
|
||||
cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, !node.GetHasUnstagedChanges() && node.GetHasStagedChanges())
|
||||
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||
|
||||
refreshOpts := refreshMainOpts{main: &viewUpdateOpts{
|
||||
@ -78,15 +79,17 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
task: gui.createRunPtyTask(cmd),
|
||||
}}
|
||||
|
||||
if file.HasStagedChanges && file.HasUnstagedChanges {
|
||||
cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(file, false, true)
|
||||
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||
if node.GetHasUnstagedChanges() {
|
||||
if node.GetHasStagedChanges() {
|
||||
cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, true)
|
||||
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||
|
||||
refreshOpts.secondary = &viewUpdateOpts{
|
||||
title: gui.Tr.StagedChanges,
|
||||
task: gui.createRunPtyTask(cmd),
|
||||
refreshOpts.secondary = &viewUpdateOpts{
|
||||
title: gui.Tr.StagedChanges,
|
||||
task: gui.createRunPtyTask(cmd),
|
||||
}
|
||||
}
|
||||
} else if !file.HasUnstagedChanges {
|
||||
} else {
|
||||
refreshOpts.main.title = gui.Tr.StagedChanges
|
||||
}
|
||||
|
||||
@ -226,7 +229,7 @@ func (gui *Gui) handleFilePress() error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if node.HasUnstagedChanges() {
|
||||
if node.GetHasUnstagedChanges() {
|
||||
if err := gui.GitCommand.StageFile(node.Path); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (m *StatusLineManager) renderAux(s *models.StatusLineNode, prefix string, d
|
||||
}
|
||||
|
||||
getLine := func() string {
|
||||
return prefix + presentation.GetStatusNodeLine(s.HasUnstagedChanges(), s.GetShortStatus(), s.Name, diffName, submoduleConfigs, s.File)
|
||||
return prefix + presentation.GetStatusNodeLine(s.GetHasUnstagedChanges(), s.GetShortStatus(), s.Name, diffName, submoduleConfigs, s.File)
|
||||
}
|
||||
|
||||
if s.IsLeaf() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user