git-lfs/tools/cygwin_windows.go
Dennis Ameling d7a3a090df Update formatting for Go 1.17
From the 1.17 release notes (https://golang.org/doc/go1.17#gofmt): gofmt (and go fmt) now synchronizes //go:build lines with // +build lines.

More info about this change can be found at https://golang.org/design/draft-gobuild
2021-08-17 20:24:58 +02:00

55 lines
926 B
Go

//go:build windows
// +build windows
package tools
import (
"bytes"
"fmt"
"github.com/git-lfs/git-lfs/v2/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()
}