I have a pre-commit hook in git that returns nonzero on some "fatal" QA checks.

When using git commit on the command line, git bails out. However, when trying the very same commit in Magit, Magit continues on presenting the commit message buffer.

I would like Magit to bail like git does.

I don't have anything related to Magit in my init file beyond (use-package magit).

Magit version: Magit 20201110.1643, Git 2.26.2, Emacs 27.1, gnu/linux

Magit process buffer ($):

  1 git … commit --signoff
pre-commit running in /home/titan/repos/gentoo
Running repoman for: app-office/gnucash
      digest.unused                 3
    Non-Fatal QA errors found
pre-commit done in /home/titan/repos/gentoo
hint: Waiting for your editor to close the file...
Waiting for Emacs...

I've programmed the script to consider unused digest items to be an error. So, the script returns 1.

  • @phils, I've updated the question to include that information. – titanofold Nov 21 at 19:33
  • 1
    If your pre-commit script is exiting with a non-zero status then normally Magit would not get to the point of asking you to edit a commit message, and I think that's a consequence of git not trying to start the user's editor at all in that situation. To me this looks like either git trying to get a commit message from you despite the pre-commit failure, or else the pre-commit script not actually returning non-zero. I've no idea whether the --signoff option is a factor, but you could try it without that. – phils Nov 21 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.