-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit_commands.go
50 lines (44 loc) · 1.28 KB
/
git_commands.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
package main
import (
"fmt"
"os/exec"
"strings"
"time"
)
func commit(date time.Time, localDummyRepo string, config *Config) error {
dateStr := date.Format("Mon Jan 2 15:04:05 2006")
var commitStr strings.Builder
for i := 0; i < config.Intensity; i++ {
commitStr.WriteString("git commit --allow-empty -m 'Generated commit';")
}
cmd := exec.Command("bash", "-c", commitStr.String())
cmd.Dir = localDummyRepo
cmd.Env = append(cmd.Env,
fmt.Sprintf("GIT_AUTHOR_DATE=%s", dateStr),
fmt.Sprintf("GIT_AUTHOR_EMAIL=%s", config.GitUserEmail),
fmt.Sprintf("GIT_COMMITTER_DATE=%s", dateStr),
fmt.Sprintf("GIT_COMMITTER_EMAIL=%s", config.GitUserEmail),
)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Failed to commit: %s: %v", out, err)
}
return nil
}
func getGitConfigValue(key string) (string, error) {
cmd := exec.Command("git", "config", "--get", key)
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("Failed to get git config value of key %s: %v", key, err)
}
return strings.TrimSpace(string(output)), nil
}
func push(localRepoPath string) error {
cmd := exec.Command("git", "push")
cmd.Dir = localRepoPath
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Failed to push: %s: %v", out, err)
}
return nil
}