summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDustin Lactin <dustin.lactin@gmail.com>2024-06-18 13:00:40 -0600
committerGitHub <noreply@github.com>2024-06-18 15:00:40 -0400
commitae73f740d3917e73ce90029f95c79f4b10438654 (patch)
treed92dc4390493ad5b64dc563688f2bd9fedb64b91 /ext
parent43f579e6df7f3936cb0a48f1eb16bf29022094f7 (diff)
feat: Support for signing commits with gpg and ssh (#710)
Signed-off-by: Dustin Lactin <dustin.lactin@gmail.com>
Diffstat (limited to 'ext')
-rw-r--r--ext/git/mocks/Client.go14
-rw-r--r--ext/git/writer.go16
2 files changed, 24 insertions, 6 deletions
diff --git a/ext/git/mocks/Client.go b/ext/git/mocks/Client.go
index 6325228..87bd3b4 100644
--- a/ext/git/mocks/Client.go
+++ b/ext/git/mocks/Client.go
@@ -160,6 +160,20 @@ func (_m *Client) Config(username string, email string) error {
return r0
}
+// SigningConfig provides a mock function with given fields: signingkey
+func (_m *Client) SigningConfig(signingkey string) error {
+ ret := _m.Called(signingkey)
+
+ var r0 error
+ if rf, ok := ret.Get(0).(func(string) error); ok {
+ r0 = rf(signingkey)
+ } else {
+ r0 = ret.Error(0)
+ }
+
+ return r0
+}
+
// Fetch provides a mock function with given fields: revision
func (_m *Client) Fetch(revision string) error {
ret := _m.Called(revision)
diff --git a/ext/git/writer.go b/ext/git/writer.go
index 7b84ff9..94535ae 100644
--- a/ext/git/writer.go
+++ b/ext/git/writer.go
@@ -14,8 +14,10 @@ type CommitOptions struct {
CommitMessageText string
// CommitMessagePath holds the path to a file to be used for the commit message (-F option)
CommitMessagePath string
- // SigningKey holds a GnuPG key ID used to sign the commit with (-S option)
+ // SigningKey holds a GnuPG key ID or path to a Private SSH Key used to sign the commit with (-S option)
SigningKey string
+ // SigningMethod holds the signing method used to sign commits. (git -c gpg.format=ssh option)
+ SigningMethod string
// SignOff specifies whether to sign-off a commit (-s option)
SignOff bool
}
@@ -25,16 +27,18 @@ type CommitOptions struct {
// changes will be commited. If message is not the empty string, it will be
// used as the commit message, otherwise a default commit message will be used.
// If signingKey is not the empty string, commit will be signed with the given
-// GPG key.
+// GPG or SSH key.
func (m *nativeGitClient) Commit(pathSpec string, opts *CommitOptions) error {
defaultCommitMsg := "Update parameters"
- args := []string{"commit"}
+ // Git configuration
+ config := "gpg.format=" + opts.SigningMethod
+ args := []string{"-c", config, "commit"}
if pathSpec == "" || pathSpec == "*" {
args = append(args, "-a")
}
- if opts.SigningKey != "" {
- args = append(args, "-S", opts.SigningKey)
- }
+ // Commit fails with a space between -S flag and path to SSH key
+ // -S/user/test/.ssh/signingKey or -SAAAAAAAA...
+ args = append(args, fmt.Sprintf("-S%s", opts.SigningKey))
if opts.SignOff {
args = append(args, "-s")
}