Gpg-agent is not requested in git calls

gitgnupg

In git commits (gpg), git command always asks for passphrase while gpg-agent is running.

I launch gpg-agent with

$ eval `gpg-agent -s --enable-ssh-support --daemon --write-env-file $HOME/.gpg-agent-info`

Then I open another terminal and check it's running:

$ cat ~/.gpg-agent-info
GPG_AGENT_INFO=/tmp/gpg-w2HH4r/S.gpg-agent:28539:1
SSH_AUTH_SOCK=/tmp/gpg-QQTJCD/S.gpg-agent.ssh
SSH_AGENT_PID=28539
$ ps -u $USER | grep gpg-agent
28539 ?        00:00:00 gpg-agent
$ echo $GPG_AGENT_INFO $SSH_AUTH_SOCK $SSH_AGENT_PID
/tmp/gpg-w2HH4r/S.gpg-agent:28539:1 /tmp/gpg-QQTJCD/S.gpg-agent.ssh 28539
$ echo test | gpg-aes -t D2FA51BD --use-agent | gpg --use-agent
....
test
....

The first '….' says that it's needed a passphrase and gpg-agent launchs pinentry-gtk-2. The last '….' says that gpg is signing with the key ID.

Running again the same command don't asks for passphrase

.

But when running git, gpg asks for the passphrase in the command line, not gpg-agent with pinentry:

$ echo test >> test.txt ; git add test.txt ; git commit -S -m "test"
....
(intro passphrase)
....

Running again (and again…) the same command always asks for
passphrase (to the same key ID).

My .gitconfig only has set the user name and email. Both commands (gpg and git) asks for the same key ID. Calling gpg with –use-agent works fine (without it not), but git has no options to pass to gpg (only user config values in .gitconfig); and the environment is correct.

Logging gpg-agent with debug-level 8 only shows activity with gpg command, but nothing with git.

I'm using gnupg 1.4.12 and gpg-agent 2.0.19 (Debian Wheezy stable, official repos).
I've cloned git from github repo, compiled and installed locally the current versiĆ³n (2.3.0.rc1.30.g76afe74) with the same results.

I've checked my configs but I've no idea what kind of problem is this. Any suggestion?

Thanks

Best Answer

Silly me... Setting option use-agent in gpg.conf solves the issue.

Git doesn't check if gpg-agent is running and gpg needs to be called with the option --use-agent.

I must change my default GPG behavior (options)... and use --no-use-agent in other scenarios.

Related Question