1
0
mirror of synced 2026-02-07 03:05:56 +00:00

Add check for empty path and better error messaging

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
Somtochi Onyekwere
2021-10-08 17:51:27 +01:00
committed by Hidde Beydals
parent e926321094
commit 25283d357e
2 changed files with 10 additions and 5 deletions

View File

@@ -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