问题
I'm currently looking into managing source code from an OpenInsight application using Git. Because OI code is stored in a database table there is a certain amount of manual work to export the source to text and visa-versa.
So far I have managed to automate a lot of this work using Git hooks, but the lack of a 'pre-checkout' hook has given me a problem..
When a user switches branches I have a post-checkout hook to diff the old and new branches and store a list of the changed procedures. When the user next starts OI the changes are pulled in from the text files and compiled.. so far so good.. However, if a user was to switch branches, let say from A to B, and then switch again to C without starting OI then the source in OI will be for branch A but the diff will be between B and C.
To get around this I hoped to be able to use a pre-checkout hook to check for the existence of a file containing a list of un-compiled changes and stop the user switching branches until they were compiled in. Are there any other suggestions of ways of halting a checkout?
回答1:
I was also looking into this recently and found a thread discussing the current (well... 2010) state of githooks
http://git.661346.n2.nabble.com/Why-there-is-no-pre-checkout-hook-td5638042.html
From the thread:
Óscar Fuentes wrote:
...
Because you can use your script in place of "git checkout".
Have you considered writing a script that developers can as part of their development workflow? That way you can check for the existence of the un-compiled changes list. This is basically what we ended up doing and it really helped us to simplify/standardize our workflow.
回答2:
Your problem is you're doing the wrong diffs.
However, if a user was to switch branches, let say from A to B, and then switch again to C without starting OI then the source in OI will be for branch A but the diff will be between B and C.
You're basing your diff revs off git activity when you say yourself you should be basing them off your OI starts.
So hook OI starts, check the head rev, diff between what it was last time and what it is this time.
来源:https://stackoverflow.com/questions/20118178/prevent-a-checkout-in-git