'Pre-commit does not allow GPG code-signing?

We sign each commit with GPG2 for security purposes. Usually this involves a full-terminal-window "popup" asking you to enter a password after running git commit (the terminal screen is replaced with just the GPG message). However we have started using python's pre-commit tool run linting prior to committing, and the "pop-up" isn't appearing. Here is the error I get:

$ git commit -m "fix linting issues"
autopep8 wrapper.........................................................Passed
Flake8...................................................................Passed
Check python ast.........................................................Passed
Check for added large files..............................................Passed
Check JSON...............................................................Passed
Check for merge conflicts................................................Passed
Check for case conflicts.................................................Passed
Check Yaml...............................................................Passed
Debug Statements (Python)................................................Passed
Detect Private Key.......................................................Passed
Fix double quoted strings................................................Passed
Fix End of Files.........................................................Passed
Forbid new submodules....................................................Passed
Trim Trailing Whitespace.................................................Passed
Pretty format JSON.......................................................Passed
pylint...................................................................Passed

error: gpg failed to sign the data
fatal: failed to write commit object


Solution 1:[1]

I ran into this issue today. My configuration uses gpg-agent along with an Xorg-based pinentry application

Restoring the pre-pre-commit behavior required adding no-tty to the existing gpg-agent.conf after enabling pre-commit

It's not an issue or bug with pre-commit, but installing pre-commit into an otherwise functional gpgsign enabled repository can effectively "break" signing depending on your configuration

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 adam