Skip to content

Commit d33de79

Browse files
Vladislav Ponomarevejoffe
Vladislav Ponomarev
authored andcommitted
GITHUB-407: Gracefully handle Cygwin paths on Windows when determining root directory.
1 parent e0b0a5a commit d33de79

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

git/realgit/realcmd.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@ func NewGitCmd(cfg *config.Config) *gitcmd {
2121
fmt.Println(err)
2222
os.Exit(-1)
2323
}
24-
rootdir = strings.TrimSpace(rootdir)
24+
rootdir = strings.TrimSpace(maybeAdjustPathPerPlatform(rootdir))
2525

2626
return &gitcmd{
2727
config: cfg,
2828
rootdir: rootdir,
2929
}
3030
}
3131

32+
func maybeAdjustPathPerPlatform(rawRootDir string) string {
33+
if strings.HasPrefix(rawRootDir, "/cygdrive") {
34+
// This is safe to run also on "proper" Windows paths
35+
cmd := exec.Command("cygpath", []string{"-w", rawRootDir}...)
36+
out, err := cmd.CombinedOutput()
37+
if err != nil {
38+
panic(err)
39+
}
40+
return string(out)
41+
}
42+
43+
return rawRootDir
44+
}
45+
3246
type gitcmd struct {
3347
config *config.Config
3448
rootdir string

0 commit comments

Comments
 (0)