2021-08-17 12:46:50 +00:00
|
|
|
//go:build windows
|
2017-02-20 22:22:00 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package tools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-02-28 21:42:31 +00:00
|
|
|
"fmt"
|
2017-02-20 22:22:00 +00:00
|
|
|
|
2021-08-10 06:18:38 +00:00
|
|
|
"github.com/git-lfs/git-lfs/v2/subprocess"
|
2017-02-20 22:22:00 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2017-02-20 22:22:00 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2017-02-20 22:22:00 +00:00
|
|
|
cmd := subprocess.ExecCommand("uname")
|
|
|
|
out, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2017-02-28 21:42:31 +00:00
|
|
|
|
2019-08-01 20:23:11 +00:00
|
|
|
if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) || bytes.Contains(out, []byte("MINGW")) {
|
2017-02-28 21:42:31 +00:00
|
|
|
cygwinState = cygwinStateEnabled
|
|
|
|
} else {
|
|
|
|
cygwinState = cygwinStateDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
return cygwinState.Enabled()
|
2017-02-20 22:22:00 +00:00
|
|
|
}
|