git-lfs/tools/cygwin_windows.go
brian m. carlson baa79b1684
tools: detect MINGW as Cygwin
There are several cases in which we can pass in Unix-style paths in the
Git Bash environment, which is MINGW64-based, including in file URLs. To
make such paths work, let's accept such URLs with the Unix-style paths
and then translate them to Windows-style paths automatically. Note that
passing Windows-style paths to "cygpath -W", which is what we use in
this case, works fine, so there's no regression in the Git Bash case.
2019-08-02 17:23:46 +00:00

54 lines
904 B
Go

// +build windows
package tools
import (
"bytes"
"fmt"
"github.com/git-lfs/git-lfs/subprocess"
)
type cygwinSupport byte
const (
cygwinStateUnknown cygwinSupport = iota
cygwinStateEnabled
cygwinStateDisabled
)
func (c cygwinSupport) Enabled() bool {
switch c {
case cygwinStateEnabled:
return true
case cygwinStateDisabled:
return false
default:
panic(fmt.Sprintf("unknown enabled state for %v", c))
}
}
var (
cygwinState cygwinSupport
)
func isCygwin() bool {
if cygwinState != cygwinStateUnknown {
return cygwinState.Enabled()
}
cmd := subprocess.ExecCommand("uname")
out, err := cmd.Output()
if err != nil {
return false
}
if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) || bytes.Contains(out, []byte("MINGW")) {
cygwinState = cygwinStateEnabled
} else {
cygwinState = cygwinStateDisabled
}
return cygwinState.Enabled()
}