Prevent a checkout in Git
Asked Answered
C

2

4

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?

Cassock answered 21/11, 2013 at 10:19 Comment(0)
P
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.

Photograph answered 11/12, 2013 at 20:58 Comment(1)
Thanks dnorton. That is an option I considered, but the other developers in the team have not used git before, so I am trying to keep the workflow as simple as possible (I have prevous experiance of devs finding it 'too different' and complicated). Anyway, I've gotten past the need for a pre checkout hook. Its now a post-reset one I want :)Cassock
C
0

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.

Cybernetics answered 12/8, 2019 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.