Magit : how to see pre-commit hooks before editing commit log?

放肆的年华 提交于 2019-12-13 15:56:37

问题


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 !


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/11560336/magit-how-to-see-pre-commit-hooks-before-editing-commit-log

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!