tags:

views:

61

answers:

2

Is there a way to change the file that is being pushed to the server using a server-side pre-receive hook?

Say I want to add something to the end of a file like:

//End of Org

each time someone pushes to my repo.

Is there a way you can change the file coming in using git hooks?

+2  A: 

I would rather use a filter driver which can operate on the content of each file in order to check if your line is there and add it if not, during the checkout step.

alt text

That would be:

  • a smudge script
  • able to be replicated when your repo is cloned (as opposed to hooks which are not copied over when cloning a repo unless you use a template directory)
VonC
How do I get the filter driver copied to each repo when a clone/pull is done?
beast
@beast: a filter driver is a `.gitattributes` file, managed like any other files, and pushed/pulled like any other file. The smudge script it references can also be versioned.
VonC
@VonC right so I have the .gitattributes file setup and in the repo.I have a *.c filter=test in the .gitattributes file.How do I get so that[filter "test"] clean = cat smudge = catis copied to each repo clone/pull so that I don't have to do git config filter.test.smudge cat each time I clone the repo?If you cannot tell I am fairly new to git and trying to get the same config across multiple computers.
beast
@beast: You need to replay the setup for your config (unless you are cloning on the same server, in which case a `git config --global` is enough). I usually keep the config commands in a version file, for me to replay after a clone.
VonC
A: 

Just for completeness sake: it should be rather obvious from the name that what you are asking for, is simply impossible. The pre-receive hook cannot change any files, because it hasn't received any yet!

Jörg W Mittag