Add check for empty path and better error messaging
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
committed by
Hidde Beydals
parent
e926321094
commit
25283d357e
@@ -27,6 +27,11 @@ func (w GpgSigningOption) ApplyToCommit(in *CommitOptions) {
|
||||
}
|
||||
|
||||
func WithGpgSigningOption(path, passphrase, keyID string) Option {
|
||||
// return nil info if no path is set
|
||||
if path == "" {
|
||||
return GpgSigningOption{}
|
||||
}
|
||||
|
||||
return GpgSigningOption{
|
||||
GPGSigningInfo: &GPGSigningInfo{
|
||||
PrivateKeyPath: path,
|
||||
|
||||
@@ -194,7 +194,7 @@ func (g *GoGit) Commit(message git.Commit, opts ...git.Option) (string, error) {
|
||||
},
|
||||
}
|
||||
|
||||
if options.GPGSigningInfo != nil && options.GPGSigningInfo.PrivateKeyPath != "" {
|
||||
if options.GPGSigningInfo != nil {
|
||||
entity, err := getOpenPgpEntity(*options.GPGSigningInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -260,7 +260,7 @@ func isRemoteBranchNotFoundErr(err error, ref string) bool {
|
||||
func getOpenPgpEntity(info git.GPGSigningInfo) (*openpgp.Entity, error) {
|
||||
r, err := os.Open(info.PrivateKeyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to open gpg private key %s", err)
|
||||
}
|
||||
|
||||
entityList, err := openpgp.ReadKeyRing(r)
|
||||
@@ -269,7 +269,7 @@ func getOpenPgpEntity(info git.GPGSigningInfo) (*openpgp.Entity, error) {
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
return nil, fmt.Errorf("no entity formed")
|
||||
return nil, fmt.Errorf("no GPP entity formed")
|
||||
}
|
||||
|
||||
var entity *openpgp.Entity
|
||||
@@ -281,7 +281,7 @@ func getOpenPgpEntity(info git.GPGSigningInfo) (*openpgp.Entity, error) {
|
||||
}
|
||||
|
||||
if entity == nil {
|
||||
return nil, fmt.Errorf("no key matching the key id was found")
|
||||
return nil, fmt.Errorf("no gpg private key matching the key id was found")
|
||||
}
|
||||
} else {
|
||||
entity = entityList[0]
|
||||
@@ -289,7 +289,7 @@ func getOpenPgpEntity(info git.GPGSigningInfo) (*openpgp.Entity, error) {
|
||||
|
||||
err = entity.PrivateKey.Decrypt([]byte(info.Passphrase))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to decrypt private key: %s", err)
|
||||
}
|
||||
|
||||
return entity, nil
|
||||
|
||||
Reference in New Issue
Block a user