summaryrefslogtreecommitdiffstats
path: root/pkg/commands/loading_files.go
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2021-07-22 12:02:41 +0200
committermjarkk <mkopenga@gmail.com>2021-07-22 22:12:43 +0200
commit9a087d04ebaed311e0bd3d9cbd32dd2973f0406c (patch)
tree7e0fd92807348112b9ac850424d4469711322af3 /pkg/commands/loading_files.go
parent1573a449f84846657b7ac9e07756caa9db548b0e (diff)
Change the way file statuses are loaded
This makes it so file statuses recived from git no longer get joined before spliting them again.
Diffstat (limited to 'pkg/commands/loading_files.go')
-rw-r--r--pkg/commands/loading_files.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/pkg/commands/loading_files.go b/pkg/commands/loading_files.go
index f85329f2f..2b9bfc2be 100644
--- a/pkg/commands/loading_files.go
+++ b/pkg/commands/loading_files.go
@@ -24,11 +24,10 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*models.File {
}
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 {
c.Log.Error(err)
}
- statusStrings := utils.SplitLines(statusOutput)
files := []*models.File{}
for _, statusString := range statusStrings {
@@ -77,7 +76,7 @@ type GitStatusOptions struct {
UntrackedFilesArg string
}
-func (c *GitCommand) GitStatus(opts GitStatusOptions) (string, error) {
+func (c *GitCommand) GitStatus(opts GitStatusOptions) ([]string, error) {
noRenamesFlag := ""
if opts.NoRenames {
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)
if err != nil {
- return "", err
+ return []string{}, err
}
splitLines := strings.Split(statusLines, "\x00")
- // if a line starts with 'R' then the next line is the original file.
- for i := 0; i < len(splitLines)-1; i++ {
+ response := []string{}
+
+ for i := 0; i < len(splitLines); i++ {
original := splitLines[i]
- if strings.HasPrefix(original, "R ") {
- next := splitLines[i+1]
- updated := "R " + next + RENAME_SEPARATOR + strings.TrimPrefix(original, "R ")
- splitLines[i] = updated
- splitLines = append(splitLines[0:i+1], splitLines[i+2:]...)
+ if len(original) < 2 {
+ continue
+ } else if strings.HasPrefix(original, "R ") {
+ // if a line starts with 'R' then the next line is the original file.
+ 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
}