You can use a post-checkout
hook to update a database or file on your server. This hook runs on the client-side (that is, the person doing the clone will execute the script), so you need to design your script from that perspective. Also, it is possible to clone the repository without executing this hook by adding the --no-checkout
option to git clone
.
A simple and reliable approach would be to have the server running a small RESTful web service that your hook can call with curl
or some similar facility. For example:
#!/usr/bin/env python
import socket, sys, urllib, pycurl
service_url = "https://my.server.dns/service.php"
data = urllib.urlencode({
'prev': sys.argv[1],
'new': sys.argv[2],
'branch': sys.argv[3],
'host': socket.gethostname()
})
c = pycurl.Curl()
c.setopt(pycurl.URL, service_url)
c.setopt(pycurl.POSTFIELDS, data)
c.perform()
See http://www.kernel.org/pub/software/scm/git/docs/githooks.html.