From d33de79d8c05366692cb828b8fe394e591644804 Mon Sep 17 00:00:00 2001 From: Vladislav Ponomarev Date: Tue, 21 May 2024 15:55:18 +0200 Subject: [PATCH] GITHUB-407: Gracefully handle Cygwin paths on Windows when determining root directory. --- git/realgit/realcmd.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/git/realgit/realcmd.go b/git/realgit/realcmd.go index 7d6f96b..fe63f56 100644 --- a/git/realgit/realcmd.go +++ b/git/realgit/realcmd.go @@ -21,7 +21,7 @@ func NewGitCmd(cfg *config.Config) *gitcmd { fmt.Println(err) os.Exit(-1) } - rootdir = strings.TrimSpace(rootdir) + rootdir = strings.TrimSpace(maybeAdjustPathPerPlatform(rootdir)) return &gitcmd{ config: cfg, @@ -29,6 +29,20 @@ func NewGitCmd(cfg *config.Config) *gitcmd { } } +func maybeAdjustPathPerPlatform(rawRootDir string) string { + if strings.HasPrefix(rawRootDir, "/cygdrive") { + // This is safe to run also on "proper" Windows paths + cmd := exec.Command("cygpath", []string{"-w", rawRootDir}...) + out, err := cmd.CombinedOutput() + if err != nil { + panic(err) + } + return string(out) + } + + return rawRootDir +} + type gitcmd struct { config *config.Config rootdir string