forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcygwin_windows.go
More file actions
57 lines (46 loc) · 953 Bytes
/
cygwin_windows.go
File metadata and controls
57 lines (46 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//go:build windows
// +build windows
package tools
import (
"bytes"
"github.com/git-lfs/git-lfs/v3/subprocess"
"github.com/git-lfs/git-lfs/v3/tr"
)
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(tr.Tr.Get("unknown enabled state for %v", c))
}
}
var (
cygwinState cygwinSupport
)
func isCygwin() bool {
if cygwinState != cygwinStateUnknown {
return cygwinState.Enabled()
}
cmd, err := subprocess.ExecCommand("uname")
if err != nil {
return false
}
out, err := cmd.Output()
if err != nil {
return false
}
if bytes.Contains(out, []byte("CYGWIN")) || bytes.Contains(out, []byte("MSYS")) {
cygwinState = cygwinStateEnabled
} else {
cygwinState = cygwinStateDisabled
}
return cygwinState.Enabled()
}