git-lfs/tools/cygwin_windows.go

54 lines
864 B
Go
Raw Normal View History

// +build windows
package tools
import (
"bytes"
2017-02-28 21:42:31 +00:00
"fmt"
"github.com/git-lfs/git-lfs/subprocess"
)
2017-02-28 21:42:31 +00:00
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 {
2017-02-28 21:54:01 +00:00
if cygwinState != cygwinStateUnknown {
2017-02-28 21:42:31 +00:00
return cygwinState.Enabled()
}
cmd := subprocess.ExecCommand("uname")
out, err := cmd.Output()
if err != nil {
return false
}
2017-02-28 21:42:31 +00:00
if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) {
2017-02-28 21:42:31 +00:00
cygwinState = cygwinStateEnabled
} else {
cygwinState = cygwinStateDisabled
}
return cygwinState.Enabled()
}