From 36dcaa56a5d38adf093776fe3a621be10ae10e50 Mon Sep 17 00:00:00 2001 From: David Mokel Date: Thu, 23 Feb 2023 21:40:18 +0800 Subject: [PATCH] feat(all): add support for signing commit (#2) --- README.md | 22 +++++++++++++++++----- gitcz.go | 8 ++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 26dde78..1e378f5 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,38 @@ # gitcz -Golang版本Git Commitizen,commit规范工具 + +Golang 版本 Git Commitizen,commit 规范工具 + # 快速安装 + go install github.com/xiaoqidun/gitcz@latest + # 编译安装 + ``` git clone https://github.com/xiaoqidun/gitcz.git cd gitcz go build gitcz.go ``` + # 手动安装 + 1. 根据系统架构下载为你编译好的[二进制文件](https://aite.xyz/product/gitcz/) -2. 将下载好的二进制文件重命名为gitcz并保留后缀 -3. 把gitcz文件移动到系统PATH环境变量中的目录下 -4. windows外的系统需使用chmod命令赋予可执行权限 +2. 将下载好的二进制文件重命名为 gitcz 并保留后缀 +3. 把 gitcz 文件移动到系统 PATH 环境变量中的目录下 +4. windows 外的系统需使用 chmod 命令赋予可执行权限 + # 使用说明 + ```shell script # 添加文件到本地仓库 git add . # 使用-amend参数可覆盖最近一次提交信息,等同于git commit --amend +# 使用-S参数可进行签署commit操作,等同于git commit -S gitcz # 推送文件到远程仓库 git push ``` + # 规范文档 -gitcz使用:[angular git commit规范](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) \ No newline at end of file + +gitcz 使用:[angular git commit 规范](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) diff --git a/gitcz.go b/gitcz.go index a36b4e0..8ceb3ff 100644 --- a/gitcz.go +++ b/gitcz.go @@ -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()