I had three public keys in my key ring. They are named:
Test Other
TestKeyPub MRG App Key 2015
TestKeyPub MRG App Key 2017
I ran this command:
gpg --homedir /home/test/.gnupg --trust-model always -r "TestKeyPub MRG App Key 2017" --encrypt -o
/home/private/ksfile.pgp /home/private/ksfile.txt
and GPG used TestKeyPub MRG App Key 2015, when I expected it would use TestKeyPub MRG App Key 2017 to encrypt the
file.
I figured I could fix the problem by deleting TestKeyPub MRG App Key 2015, which worked. However, I noticed a
similar problem. When I ran:
gpg --delete-key TestKeyPub MRG App Key 2015
gpg asked me interactively if I wanted to delete TestKeyPub MRG App Key 2015, and then it asked me if I wanted to
delete TestKeyPub MRG App Key 2017. It seems that whatever code is doing the selection of keys has a bug in it. I
see in the documentation that there is a request to use the fingerprint for this command, but still, I believe that
a key would best match on the full name given for the key, not just the beginning of the specified key.