-1

I followed the instructions on Github to setup Git signing, but I get the following error when I try to sign and commit. I searched online but I fail to the reason why --help is being included in the command to sign. I am on a Mac (M2) and Git version is 2.40.1

╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
╰─➤  GIT_TRACE=1 git commit -m "Initial commit"

13:02:32.970213 git.c:439               trace: built-in: git commit -m 'Initial commit'
13:02:32.991133 run-command.c:655       trace: run_command: --help --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
error: cannot run --help: No such file or directory
error: gpg failed to sign the data:
(no gpg output)
fatal: failed to write commit object

To help debug the issue here are the requested information:

  1. Content of ~/.gitconfig

    ╭─rishabh@WKW305277K ~
    ╰─➤  cat ~/.gitconfig
    
    [filter "lfs"]
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
    [user]
        name = Rishabh
        email = rishabh@example.com
        signingkey = 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
    [init]
        defaultBranch = master
    [pull]
        rebase = false
    [commit]
        template = /Users/rishabh/.gitmessage
        gpgsign = true
    [core]
        excludesfile = /Users/rishabh/.gitignore_global
    [difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
    [mergetool "sourcetree"]
        cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
        trustExitCode = true
    [gpg]
        program = /opt/homebrew/opt/gnupg@2.2/bin/gpg
    
  2. Output of gpg --status-fd=2 -bsau <key>

    ╭─rishabh@WKW305277K ~
    ╰─➤  gpg --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
    
    [GNUPG:] KEY_CONSIDERED 6C3C23C559AA013D352F8790061E0F7BCE5EABB8 2
    [GNUPG:] BEGIN_SIGNING H8
    ^C
    gpg: signal Interrupt caught ... exiting
    
Rishabh
  • 380
  • 4
  • 14
  • 4
    What do you have for `git config --global --get gpg.program`? – Jim Redmond May 05 '23 at 17:03
  • 1
    Do you have `gpg` installed? – knittl May 05 '23 at 17:33
  • 2
    Have you looked at your `~/.gitconfig`? If `gpg.program` is set to `--help`, you'll see it in there. Without your active configuration, the question doesn't contain enough information to be solvable. – Charles Duffy May 05 '23 at 17:54
  • @knittl Yes, I have GPG installed. – Rishabh May 08 '23 at 12:06
  • @JimRedmond I have updated the question with more information to help debug. – Rishabh May 08 '23 at 12:07
  • @charles-duffy I have updated the question with more information to help debug. – Rishabh May 08 '23 at 12:07
  • If instead of passing a full path you just have `gpg.program` set to `gpg`, that would be more similar to your use of `gpg` (not `/opt/homebrew/opt/gnupg@2.2/bin/gpg`) when testing at the command line. – Charles Duffy May 08 '23 at 14:40
  • 1
    (without investigating any wrapper created by the Homebrew formula, we don't know that the homebrew gpg is _really_ gpg without extra gunk added on). – Charles Duffy May 08 '23 at 14:44
  • 3
    Also, is there any chance your _individual project_ could have `git.program` overridden, even though your global `git.program` is fine? (The easy way to test this: Do you have the same problem in a completely new repository?) – Charles Duffy May 08 '23 at 14:46
  • 1
    @CharlesDuffy the `git.program` was overriden for my individual projects! Thank you for the directions! On creating a new repository I did not face that problem. I am guessing, maybe my IDE would have added it (because of a bug). – Rishabh May 09 '23 at 08:51

1 Answers1

2

The solution required that I check the output of git config --global gpg.program and git config gpg.program on individual repositories, and then I noticed that on individual repositories I had the following:

╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
╰─➤  git config gpg.program
--help

which I corrected by setting the value as below and it corrected my problem.

git config gpg.program gpg
Rishabh
  • 380
  • 4
  • 14