-
Notifications
You must be signed in to change notification settings - Fork 3
/
git.go
52 lines (40 loc) · 930 Bytes
/
git.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
49
50
51
52
package main
import (
"log"
"os/exec"
"regexp"
"strings"
)
func BranchHashes(projectDir string) map[string]string {
cmdName := "git"
cmdArgs := []string{
"ls-remote",
"--heads",
}
cmd := exec.Command(cmdName, cmdArgs...)
cmd.Dir = projectDir
output, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
stringOutput := string(output)
var rp = regexp.MustCompile(`(?m:\n)`)
lines := rp.Split(stringOutput, -1)
lines = Filter(lines, func(v string) bool {
return v != ""
})
var branches = map[string]string{}
for _, line := range lines {
lineParts := strings.Split(line, "/")
var branch string
for _, branchSplit := range lineParts[2:] {
branch = branch + branchSplit + "/"
}
branch = strings.TrimRight(branch, "/")
branch = strings.TrimLeft(branch, " ")
branch = strings.TrimRight(branch, " ")
branchHash := MD5(branch)
branches[branchHash] = branch
}
return branches
}