tags:

views:

203

answers:

3

Is there a way to hook when a git pull happens on the remote (similar to a pre-receive or post-receive). Basically I'd like to be able to cause the remote to commit whatever it has when there is a pull.

In my situation, whatever is live on the remote is an authoritative source which may get modified without a git commit. I want to make sure when I pull I'm always able to get the latest of whatever is live.

A: 

I have no direct experience with git hooks, and this page may help, but it doesn't look like you're going to be able to do it.

The easier (and better IMO) solution would be to use a repo other than the production environment as the authoritative source. Can you do this? A production environment is very rarely used as the authoritative source because latest and most stable are two very different things...

FYI, I only ever perform a git pull or git status when in a production environment. Any changes are made on my local repo, tested, committed, pushed to github, then pulled down to the production environment.

UPDATE
I should point out that one of the great strengths and features of git is that it is a distributed source control system. As such, there isn't really any such thing as an authoritative source.

MatW
Maybe authoritative wasn't the proper term, more like it's a "peer" source which is exactly what git promotes. The only problem is that the peer can't commit for itself so I was trying to figure out if git hooks can help it.
Danny
A: 

I think you can't do this with hooks, for what I understand reading the hooks' doc there's no hook that fits into your requirement.

If I need something like what you want I'd create a script on 'remote' that runs every hour and checks if any file was changes (git status) and commit all (git commit -a -m "Auto commit").

Felipe Cypriano
Not really possible since the remote is just a file share stored on cloud storage. Thanks though, I'm realizing that this doesn't seem to exist. I have the hooks for when i do a push just not a pull. I guess I'll have to do some kind of empty commit+push.
Danny
Try to find a way to locally mount this file storage so you could use your local computer git's command. I'm guessing if could access the cloud storage as a local storage you could do everything directly from your computer.If the cloud storage is just a simple storage that contains your files and happens to have .git directory inside but no Git running it'll be impossible to hook something there.
Felipe Cypriano
A: 

It's not something I've ever done before, but you can run bash scripts from inside php:

http://www.devx.com/opensource/Article/40785
http://us2.php.net/function.exec

Which should allow you to commit and push a set of changes via a PHP script. Chuck an interface over it or integrate it into your current editing process and you should be good to go.

MatW