git repository cloning logging

﹥>﹥吖頭↗ 提交于 2019-12-10 03:28:40

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/11719936/git-repository-cloning-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!