-
Notifications
You must be signed in to change notification settings - Fork 1
/
git.go
47 lines (42 loc) · 1.39 KB
/
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
package main
import (
"bytes"
"fmt"
"os/exec"
)
// Execute git commands
func git(version Version) error {
// Confirm you are in master branch
branch, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
if err != nil {
return fmt.Errorf("[Git] Finding branch error")
} else if string(bytes.TrimRight(branch, "\r\n")) != "master" {
return fmt.Errorf("[Git] You aren't master branch. You need to checkout master branch")
}
// Confirm commit target files
status, err := exec.Command("git", "status", "-s").Output()
if err != nil {
return fmt.Errorf("[Git] Fetch status error")
}
// If commit files isn't only .versions file, abort process
files := bytes.Split(bytes.Trim(status, "\r\n"), []byte("\n"))
if len(files) != 1 {
return fmt.Errorf("[Git] Uncommitted file found. Please stash or remove.\n%s", string(bytes.Join(files, []byte("\n"))))
} else if !bytes.HasSuffix(files[0], []byte(".versions")) {
return fmt.Errorf("[Git] Counldn't find .versions file in commit files")
}
vs := version.VersionString()
// Make commit
commit := exec.Command("git", "commit", "-a", "-m", vs)
if err := commit.Run(); err != nil {
fmt.Println("[Git] Failed to commit version file")
return err
}
// Make tag
tag := exec.Command("git", "tag", "-a", vs, "-m", "")
if err := tag.Run(); err != nil {
fmt.Println("[Git] Failed to create version tag")
return err
}
return nil
}