feat(all): add support for signing commit (#2)

This commit is contained in:
David Mokel
2023-02-23 21:40:18 +08:00
committed by GitHub
parent 8e203b7689
commit 36dcaa56a5
2 changed files with 23 additions and 7 deletions

View File

@@ -78,6 +78,7 @@ func main() {
false,
"覆盖上次提交信息",
)
sign := flag.Bool("S", false, "对commit进行签名")
author := flag.Bool(
"author",
false,
@@ -96,7 +97,7 @@ func main() {
czCommit.BreakingChange = InputBreakingChange()
czCommit.Closes = InputCloses()
commit := GenerateCommit(czCommit)
if err := GitCommit(commit, *amend); err != nil {
if err := GitCommit(commit, *amend, *sign); err != nil {
fmt.Println(err)
}
}
@@ -114,7 +115,7 @@ func NewLine() {
fmt.Println()
}
func GitCommit(commit string, amend bool) (err error) {
func GitCommit(commit string, amend bool, sign bool) (err error) {
tempFile, err := ioutil.TempFile("", "git_commit_")
if err != nil {
return
@@ -130,6 +131,9 @@ func GitCommit(commit string, amend bool) (err error) {
if amend {
args = append(args, "--amend")
}
if sign {
args = append(args, "-S")
}
args = append(args, "-F", tempFile.Name())
cmd := exec.Command("git", args...)
result, err := cmd.CombinedOutput()