Skip to content

Commit

Permalink
GITHUB-407: Gracefully handle Cygwin paths on Windows when determinin…
Browse files Browse the repository at this point in the history
…g root directory.
  • Loading branch information
Vladislav Ponomarev authored and ejoffe committed Aug 23, 2024
1 parent e0b0a5a commit d33de79
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion git/realgit/realcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ 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,
rootdir: rootdir,
}
}

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
Expand Down

0 comments on commit d33de79

Please sign in to comment.