-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.go
More file actions
44 lines (35 loc) · 738 Bytes
/
git.go
File metadata and controls
44 lines (35 loc) · 738 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
package main
import (
"bytes"
"os/exec"
"regexp"
)
type GitClient struct {
repo_path string
}
func (c *GitClient) Init(repo_path string) {
c.repo_path = repo_path
}
func (c *GitClient) Status() ([]string, error) {
cmd := exec.Command("git", "status")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Dir = c.repo_path
err := cmd.Run()
if err != nil {
return nil, err
}
out_str := out.String()
// TODO: Lift to Init
// TODO: Find untracked files as well
re, err := regexp.Compile(`(modified|new file):\s*(.*)`)
if err != nil {
return nil, err
}
results := re.FindAllStringSubmatch(out_str, -1)
var matches = make([]string, len(results))
for i, r := range results {
matches[i] = r[2]
}
return matches, nil
}