github.com/catandhorse/git-lfs@v2.5.2+incompatible/tools/cygwin_windows.go (about) 1 // +build windows 2 3 package tools 4 5 import ( 6 "bytes" 7 "fmt" 8 9 "github.com/git-lfs/git-lfs/subprocess" 10 ) 11 12 type cygwinSupport byte 13 14 const ( 15 cygwinStateUnknown cygwinSupport = iota 16 cygwinStateEnabled 17 cygwinStateDisabled 18 ) 19 20 func (c cygwinSupport) Enabled() bool { 21 switch c { 22 case cygwinStateEnabled: 23 return true 24 case cygwinStateDisabled: 25 return false 26 default: 27 panic(fmt.Sprintf("unknown enabled state for %v", c)) 28 } 29 } 30 31 var ( 32 cygwinState cygwinSupport 33 ) 34 35 func isCygwin() bool { 36 if cygwinState != cygwinStateUnknown { 37 return cygwinState.Enabled() 38 } 39 40 cmd := subprocess.ExecCommand("uname") 41 out, err := cmd.Output() 42 if err != nil { 43 return false 44 } 45 46 if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) { 47 cygwinState = cygwinStateEnabled 48 } else { 49 cygwinState = cygwinStateDisabled 50 } 51 52 return cygwinState.Enabled() 53 }