With git on the command line, you see the result of your pre-commit hooks before entering the commit's log message. If your pre-commit hook makes the commit fail, you are warnt and don't write anything.

But with magit, you are asked to enter your log comment and then it evaluates your hook, and if it fails you don't see why. You just read :

git exited abnormally with code 1. I understand this is normal because it is when you are finished editing the log message that magit runs the git command.

So, how would you make magit to evaluate your hook before asking for the log ? How can you make magit display the result of the hook ?

And a related question would be, how do you give arguments to you pre-commit hook in order to run it for the stashed files only, instead of all the files in the repository ?

I use pre-commit hooks mainly to check if I didn't forget debugging stuff, like a remaining 'ipdb', and some personal traces.

Thanks !

有帮助吗?

解决方案

I've wrote code for running the hook before opening the log-message buffer:

https://github.com/vanicat/magit/commit/87ec17c46b156c8508a47aa6c9ba982ef8a61b4c

You could test it, it miss the possibility to ignore the hook, and don't run others hook than pre-commit for now.

其他提示

After git failed when called by magit, you should be able to see why by using $

For evaluating pre-commit hook, there is nothing for now in magit. You could try to put something in magit-log-edit-mode-hook for this:

(add-hook 'magit-log-edit-mode-hook
          '(lambda ()
                (shell-command "shell command to run git's hook")))

Of course, the shell command is lacking here...

For the related question in your pre-commit you will need to use git to know file that will be commited. Something like

git diff --name-only --cached
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top