diff --git a/pkg/commands/models/commit_file.go b/pkg/commands/models/commit_file.go index b6028e221..5f68e45b3 100644 --- a/pkg/commands/models/commit_file.go +++ b/pkg/commands/models/commit_file.go @@ -2,6 +2,7 @@ package models // CommitFile : A git commit file type CommitFile struct { + // TODO: rename this to Path Name string ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status diff --git a/pkg/gui/filetree/commit_file_change_manager.go b/pkg/gui/filetree/commit_file_change_manager.go index 48754e5de..ee05ca3b9 100644 --- a/pkg/gui/filetree/commit_file_change_manager.go +++ b/pkg/gui/filetree/commit_file_change_manager.go @@ -91,6 +91,24 @@ func (m *CommitFileChangeManager) ToggleCollapsed(path string) { func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string { return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string { castN := n.(*CommitFileChangeNode) - return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File, patchManager, m.parent) + + // This is a little convoluted because we're dealing with either a leaf or a non-leaf. + // But this code actually applies to both. If it's a leaf, the status will just + // be whatever status it is, but if it's a non-leaf it will determine its status + // based on the leaves of that subtree + var status patch.PatchStatus + if castN.EveryFile(func(file *models.CommitFile) bool { + return patchManager.GetFileStatus(file.Name, m.parent) == patch.WHOLE + }) { + status = patch.WHOLE + } else if castN.EveryFile(func(file *models.CommitFile) bool { + return patchManager.GetFileStatus(file.Name, m.parent) == patch.UNSELECTED + }) { + status = patch.UNSELECTED + } else { + status = patch.PART + } + + return presentation.GetCommitFileLine(castN.NameAtDepth(depth), diffName, castN.File, status) }) } diff --git a/pkg/gui/presentation/commit_files.go b/pkg/gui/presentation/commit_files.go index 4980f6c50..94116066a 100644 --- a/pkg/gui/presentation/commit_files.go +++ b/pkg/gui/presentation/commit_files.go @@ -8,21 +8,16 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) -func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, patchManager *patch.PatchManager, parent string) string { +func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFile, status patch.PatchStatus) string { yellow := color.New(color.FgYellow) green := color.New(color.FgGreen) defaultColor := color.New(theme.DefaultTextColor) diffTerminalColor := color.New(theme.DiffTerminalColor) - if commitFile == nil { - return name - } - colour := defaultColor if diffName == name { colour = diffTerminalColor - } else if commitFile != nil { - status := patchManager.GetFileStatus(commitFile.Name, parent) + } else { switch status { case patch.UNSELECTED: colour = defaultColor @@ -33,6 +28,10 @@ func GetCommitFileLine(name string, diffName string, commitFile *models.CommitFi } } + if commitFile == nil { + return colour.Sprint(name) + } + return utils.ColoredString(commitFile.ChangeStatus, getColorForChangeStatus(commitFile.ChangeStatus)) + " " + colour.Sprint(name) }