I am unable to use signed commits within Visual Studio Code when committing code in WSL2 from Windows 10.
THE ISSUE
No passphrase prompt is shown within Windows 10 resulting in git failing with error: gpg failed to sign the data
SETUP
Windows Setup
Latest version of Windows 10 with WSL2 and Windows Terminal.
Visual Studio Code is installed within Windows 10 and is the latest version (1.48.0) and includes the latest Remote WSL Extension (v0.44.4).
My code is within WSL2 running Ubuntu 20.04 with all packages updated.
Visual Studio Code is opened via the command line using the code .
command from within WSL2.
Git Setup
Git (2.25.1) is installed within WSL2 with the following global config:
[user]
name = My Name
email = my.email@example.com
signingkey = A1B2C3D4E5F67890
[commit]
gpgsign = true
The git repository is initiated using the command line within WSL2.
GPG Setup
gnupg (2.2.19) is installed within WSL2.
I have ~/.gnupg/gpg.conf
settings
use-agent
default-key A1B2C3D4E5F67890
And ~/.gnupg/gpg-agent.conf
default-cache-ttl 34560000
max-cache-ttl 34560000
pinentry-program /usr/bin/pinentry-curses
And my ~/.zprofile
export GPG_TTY=$(tty)
export GPG_AGENT_INFO=${HOME}/.gnupg/S.gpg-agent:0:1
WHAT WORKS
If I run a git commit
from within WSL2 in Windows Terminal it prompts me for my passphrase.
┌────────────────────────────────────────────────────────────────┐
│ Please enter the passphrase to unlock the OpenPGP secret key: │
│ "My Name <my.email@example.com>" │
│ 4096-bit RSA key, ID A1B2C3D4E5F67890, │
│ created 2020-08-10. │
│ │
│ │
│ Passphrase: __________________________________________________ │
│ │
│ <OK> <Cancel> │
└────────────────────────────────────────────────────────────────┘
This passphrase is then cached for the rest of my Windows session until I restart my laptop. Any commit after this no longer prompts for the passphrase.
I am now able to use the Visual Studio Code git UI and VSCode's built-in terminal to commit changes.
The Question
If I restart my laptop then commits from Visual Studio Code do not work until I first cache the GPG passphrase within WSL2.
Maybe worth noting, but if I haven't cached the passphrase and open the code within Visual Studio Code and try to do a commit from the built-in VSCode terminal it also fails. It only works if the passphrase is first entered within WSL2 via Windows Terminal.
I appreciate that Windows 10 and WSL2 are really two different systems but is there any way to get Windows to display a prompt for the GPG passphrase for git running in WSL2?
Or do I need to set things up completely differently? I've used MacOS for development for a long time now so not sure what the best route may be on Windows 10.
Edit: 2020-08-17 I found https://github.com/diablodale/pinentry-wsl-ps1 and used the script as the pinentry. This works and shows a GUI in Windows 10 when the passphrase isn't cached. But I'd like to find a solution that doesn't rely on a script that may stop functioning.