tags:

views:

24

answers:

1

I'd like my remote repository to refuse any pushes that contains a file that contains a tab, but only if the file belongs in a certain class (based on the filename). Is that possible?
I have looked a bit at the update hook in githooks, and I think that is the correct one.

So in short, a push should be rejected if:

  1. there is a file of the listed types (*.cpp, *.h, CMakeLists.txt)
  2. that contains one or more tab characters.
+1  A: 

You could setup a pre-push hook, but this is not really in the spirit of the git publication mechanism.

I would rather go with:

  • a pre-commit hook, preventing any commit with the wrong content
  • or a filter driver that you can easily associate with the right types of file, and which can fix or report any improper content.
VonC
In this case, it seems more likely the OP wants an update hook than a pre-push hook; if it's about keeping bad content out of the public repo, you probably want to put a roadblock on the central repo, rather than relying on developers always setting up right. I'm with you on the pre-commit hook, though. I'd much rather find out there's an issue with my code when I'm committing than when I publish.
Jefromi
@Jefromi: agreed. I find it better to detect problems earlier in the development lifecycle ;)
VonC
I have already written the pre-commit hook. But that was relatively easy; the update hook seems much more complicated. An example of what might be the right direction would be much appreciated. And yes, I intend to have both: pre-commit to help the devs against them selves and update to help against each other. Devs wanted tab already have a script that he uses to convert back and forth upon checkout/commit.
Esben Mose Hansen