Can we move the pre-receive hook?

Hi,

I need to add a pre-commit hook to our gitlab installation which prevents any branches being created which have upper case letters.

How do we arrange this so our custom hook is called before the mirror so the branch is not created in svn?

We have tried storing the new hook in the global hook directory and in the subdirectory of the project custom hook directory (pre-receive.d) but the badly named directory was still created in svn.

How do we ensure that the new hook is called first?
Can we move the pre-receive hook that subgit uses to the pre-receive.d directory?
Or call our hook from the beginning of the subgit pre-receive one?

Hi Steve,

I wouldn’t recommend moving SubGit hooks anywhere else, but it perfectly OK to add your hook invoke or even you code in SubGit pre-receive hook, just make sure is does not mess with what SubGit’s hook is doing there. Note, that by default SubGit uses fast-* hooks, so if you want to add your functionality, then remove or rename those fast-* ones so that SubGit invokes Java hooks; and also note that subgit install will replace the hooks in the repository, so the hook should be renewed after the install is invoked.

Hi,

Thanks for your quick reply. Just so I can be sure I understand (breaking the mirror is a huge issue at my company, it literally grinds our production to a halt):

I can add the code to do our extra work at the top of pre-receive file, above the line
# computes absolute path from relative and ensure it does not effect the normal hook operation?

I then need to ensure I reapply this patch whenever we reinstall the hook.

Do I also need to remove the fast* hooks? If so I need to do anything other than remove these hooks (e.g. change a reference somewhere in the pre-receive hook etc)?

Hi Steve,

I can add the code to do our extra work at the top of pre-receive file, above the line
# computes absolute path from relative and ensure it does not effect the normal hook operation?

yes, that’s correct.
Besides, you can just add your code in the user-pre-receive hook, there should be a template in the SubGit hooks directory. This hooks is being invoked from inside the main hook, so it won’t be needed to re-configure the hooks after each subgit install.
And it looks like I misguided you about the fast-*hooks, it’s actually not mandatory to remove them to only run you own code, so they may still as they are, sorry for the misguidance.