mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
Change the way file statuses are loaded
This makes it so file statuses recived from git no longer get joined before spliting them again.
This commit is contained in:
parent
1573a449f8
commit
9a087d04eb
3 changed files with 57 additions and 14 deletions
|
@ -24,11 +24,10 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*models.File {
|
||||||
}
|
}
|
||||||
untrackedFilesArg := fmt.Sprintf("--untracked-files=%s", untrackedFilesSetting)
|
untrackedFilesArg := fmt.Sprintf("--untracked-files=%s", untrackedFilesSetting)
|
||||||
|
|
||||||
statusOutput, err := c.GitStatus(GitStatusOptions{NoRenames: opts.NoRenames, UntrackedFilesArg: untrackedFilesArg})
|
statusStrings, err := c.GitStatus(GitStatusOptions{NoRenames: opts.NoRenames, UntrackedFilesArg: untrackedFilesArg})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err)
|
c.Log.Error(err)
|
||||||
}
|
}
|
||||||
statusStrings := utils.SplitLines(statusOutput)
|
|
||||||
files := []*models.File{}
|
files := []*models.File{}
|
||||||
|
|
||||||
for _, statusString := range statusStrings {
|
for _, statusString := range statusStrings {
|
||||||
|
@ -77,7 +76,7 @@ type GitStatusOptions struct {
|
||||||
UntrackedFilesArg string
|
UntrackedFilesArg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GitStatus(opts GitStatusOptions) (string, error) {
|
func (c *GitCommand) GitStatus(opts GitStatusOptions) ([]string, error) {
|
||||||
noRenamesFlag := ""
|
noRenamesFlag := ""
|
||||||
if opts.NoRenames {
|
if opts.NoRenames {
|
||||||
noRenamesFlag = "--no-renames"
|
noRenamesFlag = "--no-renames"
|
||||||
|
@ -85,20 +84,24 @@ func (c *GitCommand) GitStatus(opts GitStatusOptions) (string, error) {
|
||||||
|
|
||||||
statusLines, err := c.RunCommandWithOutput("git status %s --porcelain -z %s", opts.UntrackedFilesArg, noRenamesFlag)
|
statusLines, err := c.RunCommandWithOutput("git status %s --porcelain -z %s", opts.UntrackedFilesArg, noRenamesFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
splitLines := strings.Split(statusLines, "\x00")
|
splitLines := strings.Split(statusLines, "\x00")
|
||||||
// if a line starts with 'R' then the next line is the original file.
|
response := []string{}
|
||||||
for i := 0; i < len(splitLines)-1; i++ {
|
|
||||||
|
for i := 0; i < len(splitLines); i++ {
|
||||||
original := splitLines[i]
|
original := splitLines[i]
|
||||||
if strings.HasPrefix(original, "R ") {
|
if len(original) < 2 {
|
||||||
next := splitLines[i+1]
|
continue
|
||||||
updated := "R " + next + RENAME_SEPARATOR + strings.TrimPrefix(original, "R ")
|
} else if strings.HasPrefix(original, "R ") {
|
||||||
splitLines[i] = updated
|
// if a line starts with 'R' then the next line is the original file.
|
||||||
splitLines = append(splitLines[0:i+1], splitLines[i+2:]...)
|
next := strings.TrimSpace(splitLines[i+1])
|
||||||
|
original = "R " + next + RENAME_SEPARATOR + strings.TrimPrefix(original, "R ")
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
|
response = append(response, original)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(splitLines, "\n"), nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
||||||
"Several files found",
|
"Several files found",
|
||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
return secureexec.Command(
|
return secureexec.Command(
|
||||||
"echo",
|
"printf",
|
||||||
"MM file1.txt\nA file3.txt\nAM file2.txt\n?? file4.txt\nUU file5.txt",
|
`MM file1.txt\0A file3.txt\0AM file2.txt\0?? file4.txt\0UU file5.txt`,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
func(files []*models.File) {
|
func(files []*models.File) {
|
||||||
|
@ -106,6 +106,36 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.EqualValues(t, expected, files)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"File with new line char",
|
||||||
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
return secureexec.Command(
|
||||||
|
"printf",
|
||||||
|
`MM a\nb.txt`,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
func(files []*models.File) {
|
||||||
|
assert.Len(t, files, 1)
|
||||||
|
|
||||||
|
expected := []*models.File{
|
||||||
|
{
|
||||||
|
Name: "a\nb.txt",
|
||||||
|
HasStagedChanges: true,
|
||||||
|
HasUnstagedChanges: true,
|
||||||
|
Tracked: true,
|
||||||
|
Added: false,
|
||||||
|
Deleted: false,
|
||||||
|
HasMergeConflicts: false,
|
||||||
|
HasInlineMergeConflicts: false,
|
||||||
|
DisplayString: "MM a\nb.txt",
|
||||||
|
Type: "other",
|
||||||
|
ShortStatus: "MM",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
assert.EqualValues(t, expected, files)
|
assert.EqualValues(t, expected, files)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package presentation
|
package presentation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
|
@ -48,6 +50,14 @@ func GetFileLine(hasUnstagedChanges bool, hasStagedChanges bool, name string, di
|
||||||
output += restColor.Sprint(" ")
|
output += restColor.Sprint(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name = strings.NewReplacer(
|
||||||
|
"\n", "\\n",
|
||||||
|
"\r", "\\r",
|
||||||
|
"\t", "\\t",
|
||||||
|
"\b", "\\b",
|
||||||
|
"\f", "\\f",
|
||||||
|
"\v", "\\v",
|
||||||
|
).Replace(name)
|
||||||
output += restColor.Sprint(name)
|
output += restColor.Sprint(name)
|
||||||
|
|
||||||
if file != nil && file.IsSubmodule(submoduleConfigs) {
|
if file != nil && file.IsSubmodule(submoduleConfigs) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue