This repository was archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
143 lines (107 loc) · 2.48 KB
/
main.go
File metadata and controls
143 lines (107 loc) · 2.48 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
. "fmt"
"os"
"os/exec"
"regexp"
"time"
)
func main() {
var c []commitBox
app := "git"
arg0 := "log"
arg1 := "--branches"
arg2 := "--not"
arg3 := "--remotes"
cmd := exec.Command(app, arg0, arg1, arg2, arg3)
stdout, err := cmd.Output()
if err != nil {
Println(err.Error())
return
}
//Print()
commitRegexp := regexp.MustCompile(`commit (.*)\nAuthor: (.*)\nDate: (.*)\n\n (.*)`)
commits := commitRegexp.FindAllStringSubmatch(string(stdout), -1)
for _, commit := range commits {
id := commit[1]
//author := commit[2]
date := commit[3]
message := commit[4]
app := "git"
arg0 := "show"
arg1 := id
cmd := exec.Command(app, arg0, arg1)
stdout, err := cmd.Output()
if err != nil {
Println(err.Error())
return
}
diffRegexp := regexp.MustCompile(`diff --git a\/(.*) b\/(.*)`)
diffs := diffRegexp.FindAllStringSubmatch(string(stdout), -1)
var srcs []string
var lastTime time.Time
for _, diff := range diffs {
src := diff[1]
file, err := os.Stat(src)
if err != nil {
fmt.Println(err)
}
//Printf("%s, %s, %s, %s\n", id, src, file.ModTime(), message)
if lastTime.Before(file.ModTime()) {
lastTime = file.ModTime()
}
srcs = append(srcs, src)
}
c = append(c, commitBox{
files: srcs,
message: message,
oldDate: date,
newDate: lastTime.Format("Mon Jan 2 15:04:05 2006 -0700"),
})
}
app = "git"
arg0 = "reset"
arg1 = "origin/master"
cmd = exec.Command(app, arg0, arg1)
stdout, err = cmd.Output()
if err != nil {
Println(err.Error())
return
}
//Println(string(stdout))
for _, v := range c {
app := "git"
argAdd := []string{"add"}
for _, k := range v.files {
argAdd = append(argAdd, k)
}
cmd := exec.Command(app, argAdd...)
_, err := cmd.Output()
if err != nil {
Println(err.Error())
return
}
//Println(string(stdout))
app = "git"
arg0 := "commit"
arg1 := "-m"
arg2 := Sprintf(`%s`, v.message)
arg3 := "--date"
arg4 := Sprintf(`"%s"`, v.newDate)
cmd = exec.Command(app, arg0, arg1, arg2, arg3, arg4)
stdout, err = cmd.Output()
if err != nil {
Println(err.Error())
return
}
//Println(string(stdout))
Printf("%s, %s, %s -> %s\n", v.files, v.message, v.oldDate, v.newDate)
}
}
type commitBox struct {
files []string
message string
oldDate string
newDate string
}