-1

Added a gpg key to sign commits.

After all the configuration is done, I am able to sign via git cli.

But when I commit using vscode it opens a terminal window so I can enter my key password. The window appears a little buggy and does not accept the password and returns the error in vscode:

error: gpg failed to sign the data

When I restart gpg-agent and manage to commit via cli.

When I type the password through the cli, it is stored in that section of the terminal and I manage to commit through vscode. When you close the section, the error returns.

I'm using wsl2 with linux Ubuntu 20

LeGEC
  • 46,477
  • 5
  • 57
  • 104
IsraelCena
  • 29
  • 1
  • 6

2 Answers2

0

I guess your issue is :

  • you started VSCode from an environment where the gpg-agent wasn't started, and hence VSCode doesn't have access to the environment variables that indicate how to access the gpg-agent
  • when you start the gpg-agent from a terminal opened in VSCode, it updates the environment for that terminal (each terminal is a separate process) but not for the IDE or other terminals

To confirm that having the correct environment works, you can try the following :

  • close all running instances of VSCode
  • open a fresh terminal (whatever shell you use: bash, powershell, cmd.exe ...)
  • from that terminal, start your gpg-agent
  • from that same terminal, launch VSCode from the command line
  • check if you still have issues committing from that instance of VSCode

You can check the environment before and after starting your gpg-agent to confirm that variables do get updated (in bash, this simply means running env or env | sort from the command line).

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

I found a solution...

Steps required:

Install GPG4Win from https://www.gpg4win.org. Nothing other than the default gnupg is required, but I installed Kleopatra too in case it came in handy elsewhere.

Edit ~/.gnupg/gpg-agent.conf and change the pinentry

pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"

IsraelCena
  • 29
  • 1
  • 6