-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_windwos.go
48 lines (38 loc) · 883 Bytes
/
git_windwos.go
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
package shadow_go
import (
"bytes"
"io/ioutil"
"os/exec"
"strings"
)
func gitStatusFiles(args []string, grep string) []string {
gitCmd := exec.Command("git", args...)
grpCmd := exec.Command("findstr", grep)
outPutPip, _ := gitCmd.StdoutPipe()
grepInPutPip, _ := grpCmd.StdinPipe()
if err := gitCmd.Start(); err != nil {
return nil
}
data, _ := ioutil.ReadAll(outPutPip)
if err := gitCmd.Wait(); err != nil {
return nil
}
var grepOutBuffer bytes.Buffer
grpCmd.Stdout = &grepOutBuffer
if err := grpCmd.Start(); err != nil {
return nil
}
_, _ = grepInPutPip.Write(data)
_ = grepInPutPip.Close()
if err := grpCmd.Wait(); err != nil {
return nil
}
var ret []string
for _, str := range strings.Split(grepOutBuffer.String(), "\n") {
tmps := strings.Split(str, " ")
if len(tmps) > 1 {
ret = append(ret, tmps[len(tmps)-1])
}
}
return ret
}