mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
show file statuses in commit files view
This commit is contained in:
@ -3,10 +3,13 @@ package commands
|
|||||||
// CommitFile : A git commit file
|
// CommitFile : A git commit file
|
||||||
type CommitFile struct {
|
type CommitFile struct {
|
||||||
// Parent is the identifier of the parent object e.g. a commit SHA if this commit file is for a commit, or a stash entry ref like 'stash@{1}'
|
// Parent is the identifier of the parent object e.g. a commit SHA if this commit file is for a commit, or a stash entry ref like 'stash@{1}'
|
||||||
Parent string
|
Parent string
|
||||||
Name string
|
Name string
|
||||||
DisplayString string
|
|
||||||
Status int // one of 'WHOLE' 'PART' 'NONE'
|
// Status tells us whether the file has been wholly or partially added to a patch. We might want to pull this logic up into the gui package and make it a map like we do with cherry picked commits
|
||||||
|
Status int // one of 'WHOLE' 'PART' 'NONE'
|
||||||
|
|
||||||
|
ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *CommitFile) ID() string {
|
func (f *CommitFile) ID() string {
|
||||||
|
@ -1052,7 +1052,7 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchM
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --name-only %s %s %s", reverseFlag, from, to)
|
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --name-status %s %s %s", reverseFlag, from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1064,17 +1064,20 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchM
|
|||||||
func (c *GitCommand) GetCommitFilesFromFilenames(filenames string, parent string, patchManager *patch.PatchManager) []*CommitFile {
|
func (c *GitCommand) GetCommitFilesFromFilenames(filenames string, parent string, patchManager *patch.PatchManager) []*CommitFile {
|
||||||
commitFiles := make([]*CommitFile, 0)
|
commitFiles := make([]*CommitFile, 0)
|
||||||
|
|
||||||
for _, file := range strings.Split(strings.TrimRight(filenames, "\n"), "\n") {
|
for _, line := range strings.Split(strings.TrimRight(filenames, "\n"), "\n") {
|
||||||
|
// typical result looks like 'A my_file' meaning my_file was added
|
||||||
|
changeStatus := line[0:1]
|
||||||
|
name := line[2:]
|
||||||
status := patch.UNSELECTED
|
status := patch.UNSELECTED
|
||||||
if patchManager != nil && patchManager.To == parent {
|
if patchManager != nil && patchManager.To == parent {
|
||||||
status = patchManager.GetFileStatus(file)
|
status = patchManager.GetFileStatus(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
commitFiles = append(commitFiles, &CommitFile{
|
commitFiles = append(commitFiles, &CommitFile{
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
Name: file,
|
Name: name,
|
||||||
DisplayString: file,
|
ChangeStatus: changeStatus,
|
||||||
Status: status,
|
Status: status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCommitFileListDisplayStrings(commitFiles []*commands.CommitFile, diffName string) [][]string {
|
func GetCommitFileListDisplayStrings(commitFiles []*commands.CommitFile, diffName string) [][]string {
|
||||||
@ -37,5 +38,22 @@ func getCommitFileDisplayStrings(f *commands.CommitFile, diffed bool) []string {
|
|||||||
if diffed {
|
if diffed {
|
||||||
colour = diffTerminalColor
|
colour = diffTerminalColor
|
||||||
}
|
}
|
||||||
return []string{colour.Sprint(f.DisplayString)}
|
return []string{utils.ColoredString(f.ChangeStatus, getColorForChangeStatus(f.ChangeStatus)), colour.Sprint(f.Name)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getColorForChangeStatus(changeStatus string) color.Attribute {
|
||||||
|
switch changeStatus {
|
||||||
|
case "A":
|
||||||
|
return color.FgGreen
|
||||||
|
case "M", "R":
|
||||||
|
return color.FgYellow
|
||||||
|
case "D":
|
||||||
|
return color.FgRed
|
||||||
|
case "C":
|
||||||
|
return color.FgCyan
|
||||||
|
case "T":
|
||||||
|
return color.FgMagenta
|
||||||
|
default:
|
||||||
|
return color.FgWhite
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user