-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.go
69 lines (54 loc) · 1.09 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"strings"
"time"
"github.com/pkg/errors"
)
func add(filename string) error {
_, err := execute("git", "add", filename)
if err != nil {
return err
}
return nil
}
func commitInDate(date time.Time, allowEmpty bool) error {
dateStr := date.Format(time.RFC3339)
args := []string{
"commit", "--date", dateStr, "-am", "this is a stub commit",
}
if allowEmpty {
args = append(args, "--allow-empty")
}
extra, err := execute("git", args...)
if err != nil {
return errors.Wrapf(err, "extra: %s", extra)
}
return nil
}
func rebaseDates() error {
_, err := execute("git", "rebase", "--committer-date-is-author-date", "anchor-tag")
if err != nil {
return err
}
return nil
}
func pushCurrent(shouldForce bool) error {
args := []string{
"push",
}
if shouldForce {
args = append(args, "-f")
}
_, err := execute("git", args...)
if err != nil {
return err
}
return nil
}
func currentBranch() (string, error) {
result, err := execute("git", "branch", "--show-current")
if err != nil {
return "", err
}
return strings.Trim(result, "\n\t "), nil
}