Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GITHUB-407: Gracefully handle Cygwin paths on Windows when determining root directory #408

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading