9

I am looking to monitor the cloning activity within my git repository however I cannot find anything that shows how to set this up or how to retrieve this information.

Is this even possible? If so how can this be setup and also how do you retrieve the logging information?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
user1562690
  • 91
  • 1
  • 1
  • 3

3 Answers3

2

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.

Justin ᚅᚔᚈᚄᚒᚔ
  • 15,081
  • 7
  • 52
  • 64
1

I was going to post the same question but find this one out. The better that I could find is wrapping the git-upload-pack command to log the call. This will only work over ssh though see: pre-fetch hook functionality in git

But only root will be able to do this. It doesn't work for me, but perhaps it's a solution for others.

You may always install a "git server" for controlling access like gitolite (http://sitaramc.github.com/gitolite/master-toc.html). Either you can log it directly or you can extend it's functionality.

Community
  • 1
  • 1
estani
  • 24,254
  • 2
  • 93
  • 76
0

I don't think that there is any hook or something similar that runs in the server side of the repository on a clone. git probably just uses the specified protocol (ssh,http,...) and fetches the appropriate files. You could try to monitor that activity somehow.

abresas
  • 835
  • 6
  • 7