Git, post-receive hooks and remote coding
Oh hi blog, how are you? No really, how are you? It’s really been too long. We must have lunch.
Recently i’ve been doing some web design stuff. Things for my in department “Help Sina eat while he writes a Thesis” fund, some for a pylons project for Thor, and
another pylons project for John.
I’ve also been playing with git, trying to make working on a remote server and on various machines as seemless as possible.
I was trying to make it so i could develp something locally, and make it appear on the live server as mindlessly as possible.
Therefore, i’ve done this.
First the python:
import glob,os,stat,time,sys
def checkSum():
""" Return a long which can be used to know if any .py files have changed.
Only looks in the current directory."""
val = 0
for (d,blah,blah) in os.walk("."):
for f in glob.glob ('%s/*.php'%d): # YOU MUST CHANGE THIS TO MAKE SENSE FOR YOUR PROJECT!!
stats = os.stat (f)
val += stats [stat.ST_SIZE] + stats [stat.ST_MTIME]
return val
if __name__ == '__main__':
val=0
os.chdir(sys.argv[1])
while (True):
if checkSum() != val:
val=checkSum()
os.system ("""git commit -m "Its a commitNpush." -a """)
os.system ("""git push %s %s"""%(sys.argv[2],sys.argv[3]))
print "Commited and pushed!"
time.sleep(1)
you run this program like this:
python thefile.py gitprojectdir remote branch
And now you’ll need to set up a git post-receive hook. Go to the git repo dir on your server and do a:
chmod +x .git/hooks/post-receive
And now in that file write something along these lines:
#!/bin/sh cd .. env -i git reset --hard # you can write more code here if you like
So what happens now? while that python program is running, whenever you save something on the local machine, it will commit and push it to the server, update the server and run that script
Given a fast enough network, this is basically like having the server on your machine.
Word
Oh yeah i’m almost a Doctor. Wish me luck

Great walk-through to a working readline, thanks!
thanks for the write up…
i have my CTL+A working again
Nice fix. Thanks. This was causing me all sorts of grief.
It worked, thank you. Note that snow leopard doesn’t come with wget installed by default, but one can just download the readline tar manually. In the build.sh file, the < signs don’t show up properly in your post, breaking copy-paste. To make this work I also had to delete a previously installed copy of pyreadline (just in case someone has the same problem).
@Maxime yes or you can use curl, whatever is easiest. Ah yes just sorted the ‘< sign’ in the build.sh bit. I didn’t have an old copy of pyreadline in my copy of python 2.6 which i also upgraded to after upgrading to snow leopard, but yes that may need to be removed.
Thanks for the corrections
Thanks for the fix. You no longer need to install readline manually, easy_install installs readline 2.6.4 which works beautifully.
Use pip, quit using easy_install
pip install readline
oh ok! didn’t know about pip, just installed it. It promises to be better than easy_install… sounds good to me