Improve Windows git path normalization
Handle both C:/Users/... and /c/Users/... formats from git. Clean paths before calling filepath.Rel to ensure compatibility.
This commit is contained in:
@@ -76,6 +76,10 @@ func checkGitForIssues() (int, string) {
|
|||||||
return 0, ""
|
return 0, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean paths to ensure consistent separators
|
||||||
|
beadsDir = filepath.Clean(beadsDir)
|
||||||
|
gitRoot = filepath.Clean(gitRoot)
|
||||||
|
|
||||||
relBeads, err := filepath.Rel(gitRoot, beadsDir)
|
relBeads, err := filepath.Rel(gitRoot, beadsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, ""
|
return 0, ""
|
||||||
@@ -135,12 +139,17 @@ func findGitRoot() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
root := string(bytes.TrimSpace(output))
|
root := string(bytes.TrimSpace(output))
|
||||||
// On Windows, git returns Unix-style paths (/c/Users/...) but we need
|
|
||||||
// Windows-style paths (C:\Users\...) for filepath.Rel to work correctly
|
// Normalize path for the current OS
|
||||||
if runtime.GOOS == "windows" && len(root) > 0 && root[0] == '/' {
|
// Git on Windows may return paths with forward slashes (C:/Users/...)
|
||||||
// Convert /c/Users/... to C:\Users\...
|
// or Unix-style paths (/c/Users/...), convert to native format
|
||||||
if len(root) >= 3 && root[2] == '/' {
|
if runtime.GOOS == "windows" {
|
||||||
root = string(root[1]) + ":" + filepath.FromSlash(root[2:])
|
if len(root) > 0 && root[0] == '/' && len(root) >= 3 && root[2] == '/' {
|
||||||
|
// Convert /c/Users/... to C:\Users\...
|
||||||
|
root = strings.ToUpper(string(root[1])) + ":" + filepath.FromSlash(root[2:])
|
||||||
|
} else {
|
||||||
|
// Convert C:/Users/... to C:\Users\...
|
||||||
|
root = filepath.FromSlash(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return root
|
return root
|
||||||
|
|||||||
Reference in New Issue
Block a user