Skip to content

Commit

Permalink
GPG signed commit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JNLei committed Apr 8, 2024
1 parent a4c37cd commit 2d078bc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion git_wapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func commit(msg commitMsg) error {
return err
}

_, err = git("commit", "-F", f.Name())
gpgSignedCommit := ""
if hasGPGSignedCommit() {
gpgSignedCommit = "-S"
}
_, err = git("commit", gpgSignedCommit, "-F", f.Name())
if err != nil {
return err
}
Expand All @@ -65,6 +69,15 @@ func push() (string, error) {
return msg, err
}

func hasGPGSignedCommit() bool {
msg, err := git("config", "--get", "commit.gpgsign")
if err != nil {
fmt.Println("Cannot verify if GPG sign commit because", err)
return false
}
return msg == "true"
}

func hasStagedFiles() error {
msg, err := git("diff", "--cached", "--name-only")
if err != nil {
Expand Down

0 comments on commit 2d078bc

Please sign in to comment.