-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
57 lines (48 loc) · 1.87 KB
/
log.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
package gitcmd
import (
"github.com/gookit/gcli/v3"
"github.com/gookit/gitw"
"github.com/gookit/goutil"
)
var (
logOpts = struct {
Abbrev bool `flag:"Only display the abbrev commit ID"`
NoColor bool `flag:"Dont use color render git output"`
NoMerges bool `flag:"No contains merge request logs"`
MaxCommit int `flag:"Max display how many commits;;15"`
Format string
RepoDir string `flag:"repo directory for run git log, default is work dir"`
Logfile string `flag:"export changelog message to file"`
Exclude gcli.String `flag:"exclude contains given sub-string. multi by comma split."`
}{}
ShowLogCmd = &gcli.Command{
Name: "log",
Desc: "display recently git commits information by `git log`",
// Aliases: []string{"cl", "clog", "changelog"},
Config: func(c *gcli.Command) {
c.UseSimpleRule()
goutil.PanicErr(c.FromStruct(&logOpts))
c.StrOpt(&logOpts.Format, "format", "", "",
"The git log option '--pretty' value.\n"+
"can be one of oneline, short, medium, full, fuller, reference, email, raw, format:string and tformat:string.",
)
c.AddArg("maxCommit", "Max display how many commits")
},
Func: func(c *gcli.Command, args []string) error {
maxNum := c.Arg("maxCommit").Int()
if maxNum < 1 {
maxNum = logOpts.MaxCommit
}
// git log --color --graph --pretty=format:'%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)' --abbrev-commit -10
gitLog := gitw.New("log", "--graph")
gitLog.OnBeforeExec(gitw.PrintCmdline)
gitLog.Argf("-%d", maxNum)
gitLog.ArgIf("--color", !logOpts.NoColor)
gitLog.ArgIf("--no-merges", logOpts.NoMerges)
gitLog.ArgIf("--abbrev-commit", logOpts.Abbrev)
gitLog.Add(`--pretty=format:%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)`)
// dump.P(logOpts, maxNum)
return gitLog.Run()
},
}
)