Skip to content

Commit 35112af

Browse files
committed
fix windwos path split
1 parent 6f980d7 commit 35112af

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

versionmgr/worktree.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"os"
87
"path/filepath"
98
"strings"
109
"time"
@@ -159,7 +158,7 @@ func (workTree *WorkTree) ReplaceSubTreeEntry(ctx context.Context, treeEntry mod
159158
}
160159

161160
func (workTree *WorkTree) matchPath(ctx context.Context, path string) ([]FullObject, []string, error) {
162-
pathSegs := strings.Split(path, fmt.Sprintf("%c", os.PathSeparator))
161+
pathSegs := strings.Split(path, "/") //path must be unix style
163162
var existNodes []FullObject
164163
var missingPath []string
165164
//a/b/c/d/e
@@ -532,9 +531,10 @@ func (workTree *WorkTree) Diff(ctx context.Context, rootTreeHash hash.Hash) (*Ch
532531
}
533532

534533
// CleanPath clean path
535-
// 1. trim space
536-
// 2. trim first or last /
537-
// 3. to slash
534+
// 1. replace \\ to /
535+
// 2. trim space
536+
// 3. trim first or last /
538537
func CleanPath(fullPath string) string {
539-
return filepath.ToSlash(strings.Trim(strings.TrimSpace(fullPath), "/"))
538+
path := strings.ReplaceAll(fullPath, "\\", "/")
539+
return filepath.ToSlash(strings.Trim(strings.TrimSpace(path), "/\\"))
540540
}

versionmgr/worktree_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@ func TestCleanPath(t *testing.T) {
144144

145145
require.Equal(t, "a/b/c", CleanPath("a/b/c"))
146146
require.Equal(t, "a/b/c", CleanPath("/a/b/c/"))
147+
require.Equal(t, "a/b/c", CleanPath("\\a\\b\\c\\"))
147148
}

0 commit comments

Comments
 (0)