8

A coworker has just set up our main repo to use overcommit. It's lovely, and keeps us from invoking long CI builds which will fail for trivial reasons by warning us about issues using pre-commit hooks. But I don't feel it integrates as well with magit as I would like. Right now, my workflow looks like:

  1. hit c c in magit to commit
  2. quickly hit $ to pop open the process buffer and watch the checks run (and they're a bit ugly too because of escape codes for color)
  3. enter my commit message if successful
  4. move on with my life. Hooray!

What I'd like would be:

  1. hit c c in magit to commit
  2. magit automatically opens a buffer containing the pre-commit output, respecting color codes
  3. magit lets me enter my commit message as usual

Surely there's a way to get here. How would you approach it?


N.B. I have seen "Magit show git hook output" on Emacs StackExchange, but the answer was given in 2015 and doesn't work any more!

2 Answers 2

3

Magit's process buffer does not respect color codes and other control sequences and it won't do so anytime soon. Your best option is check if your githook can be told to not use those.

You could automatically show the process buffer the same way the appropriate diff is automatically shown:

(add-hook 'server-switch-hook 'magit-commit-diff)

Grep Magit's source to learn about complications. One complication will be that the diff buffer will likely replace the process buffer or vice-versa. You might get around that by showing one of them in a new frame.

Ah, I see the answer you linked too boils down to essentially the same approach. That answer isn't obsolete, it just doesn't address the hard problem of preventing the three buffers from stepping on each others toes. Much like this answer doesn't either. You will have to come up with a solution for that yourself.

2

I solved the color issue with:

(with-eval-after-load 'magit
  (setq magit-git-environment 
         (append magit-git-environment 
            (list "OVERCOMMIT_COLOR=0"))))

This sets the OVERCOMMIT_COLOR env variable when running the git command, which instructs Overcommit to not format with color codes that magit-process doesn't understand.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.