summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-08 21:24:49 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-08 21:33:17 +1000
commit21049be2337c3ea8c5c30761eb9b8f5f9569950a (patch)
tree2269982164487c9f4a615581fefd6ad8bd16e9bf
parentf89c47b83d71f8faeed398448283d1542de7d45a (diff)
support file tree mode on windows
-rw-r--r--pkg/gui/filetree/build_tree.go27
-rw-r--r--pkg/gui/filetree/collapsed_paths.go11
-rw-r--r--pkg/gui/filetree/commit_file_node.go8
-rw-r--r--pkg/gui/filetree/file_node.go13
-rw-r--r--pkg/gui/gui_test.go2
5 files changed, 28 insertions, 33 deletions
diff --git a/pkg/gui/filetree/build_tree.go b/pkg/gui/filetree/build_tree.go
index ab7ac40a4..128ec075c 100644
--- a/pkg/gui/filetree/build_tree.go
+++ b/pkg/gui/filetree/build_tree.go
@@ -1,8 +1,6 @@
package filetree
import (
- "os"
- "path/filepath"
"sort"
"strings"
@@ -14,18 +12,17 @@ func BuildTreeFromFiles(files []*models.File) *FileNode {
var curr *FileNode
for _, file := range files {
- split := strings.Split(file.Name, string(os.PathSeparator))
+ splitPath := split(file.Name)
curr = root
outer:
- for i := range split {
+ for i := range splitPath {
var setFile *models.File
- isFile := i == len(split)-1
+ isFile := i == len(splitPath)-1
if isFile {
setFile = file
}
- path := filepath.Join(split[:i+1]...)
-
+ path := join(splitPath[:i+1])
for _, existingChild := range curr.Children {
if existingChild.Path == path {
curr = existingChild
@@ -61,17 +58,17 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *CommitFileNode {
var curr *CommitFileNode
for _, file := range files {
- split := strings.Split(file.Name, string(os.PathSeparator))
+ splitPath := split(file.Name)
curr = root
outer:
- for i := range split {
+ for i := range splitPath {
var setFile *models.CommitFile
- isFile := i == len(split)-1
+ isFile := i == len(splitPath)-1
if isFile {
setFile = file
}
- path := filepath.Join(split[:i+1]...)
+ path := join(splitPath[:i+1])
for _, existingChild := range curr.Children {
if existingChild.Path == path {
@@ -108,3 +105,11 @@ func BuildFlatTreeFromFiles(files []*models.File) *FileNode {
return &FileNode{Children: sortedFiles}
}
+
+func split(str string) []string {
+ return strings.Split(str, "/")
+}
+
+func join(strs []string) string {
+ return strings.Join(strs, "/")
+}
diff --git a/pkg/gui/filetree/collapsed_paths.go b/pkg/gui/filetree/collapsed_paths.go
index 60860414f..02c0b4303 100644
--- a/pkg/gui/filetree/collapsed_paths.go
+++ b/pkg/gui/filetree/collapsed_paths.go
@@ -1,17 +1,12 @@
package filetree
-import (
- "os"
- "strings"
-)
-
type CollapsedPaths map[string]bool
func (cp CollapsedPaths) ExpandToPath(path string) {
// need every directory along the way
- split := strings.Split(path, string(os.PathSeparator))
- for i := range split {
- dir := strings.Join(split[0:i+1], string(os.PathSeparator))
+ splitPath := split(path)
+ for i := range splitPath {
+ dir := join(splitPath[0 : i+1])
cp[dir] = false
}
}
diff --git a/pkg/gui/filetree/commit_file_node.go b/pkg/gui/filetree/commit_file_node.go
index 0edaf9c8e..173281035 100644
--- a/pkg/gui/filetree/commit_file_node.go
+++ b/pkg/gui/filetree/commit_file_node.go
@@ -1,10 +1,6 @@
package filetree
import (
- "os"
- "path/filepath"
- "strings"
-
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
@@ -169,8 +165,8 @@ func (s *CommitFileNode) AnyFile(test func(file *models.CommitFile) bool) bool {
}
func (s *CommitFileNode) NameAtDepth(depth int) string {
- splitName := strings.Split(s.Path, string(os.PathSeparator))
- name := filepath.Join(splitName[depth:]...)
+ splitName := split(s.Path)
+ name := join(splitName[depth:])
return name
}
diff --git a/pkg/gui/filetree/file_node.go b/pkg/gui/filetree/file_node.go
index 802ff1ddf..4df8bf5bf 100644
--- a/pkg/gui/filetree/file_node.go
+++ b/pkg/gui/filetree/file_node.go
@@ -2,9 +2,6 @@ package filetree
import (
"fmt"
- "os"
- "path/filepath"
- "strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
@@ -171,18 +168,18 @@ func (s *FileNode) AnyFile(test func(file *models.File) bool) bool {
}
func (s *FileNode) NameAtDepth(depth int) string {
- splitName := strings.Split(s.Path, string(os.PathSeparator))
- name := filepath.Join(splitName[depth:]...)
+ splitName := split(s.Path)
+ name := join(splitName[depth:])
if s.File != nil && s.File.IsRename() {
- splitPrevName := strings.Split(s.File.PreviousName, string(os.PathSeparator))
+ splitPrevName := split(s.File.PreviousName)
prevName := s.File.PreviousName
// if the file has just been renamed inside the same directory, we can shave off
// the prefix for the previous path too. Otherwise we'll keep it unchanged
- sameParentDir := len(splitName) == len(splitPrevName) && filepath.Join(splitName[0:depth]...) == filepath.Join(splitPrevName[0:depth]...)
+ sameParentDir := len(splitName) == len(splitPrevName) && join(splitName[0:depth]) == join(splitPrevName[0:depth])
if sameParentDir {
- prevName = filepath.Join(splitPrevName[depth:]...)
+ prevName = join(splitPrevName[depth:])
}
return fmt.Sprintf("%s%s%s", prevName, " → ", name)
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go
index a54968849..8e37cecfe 100644
--- a/pkg/gui/gui_test.go
+++ b/pkg/gui/gui_test.go
@@ -1,3 +1,5 @@
+// +build !windows
+
package gui
import (