git repository cloning logging

2019-04-25 01:58发布

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?

3条回答
男人必须洒脱
2楼-- · 2019-04-25 02:43

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.

查看更多
Summer. ? 凉城
3楼-- · 2019-04-25 02:46

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.

查看更多
叼着烟拽天下
4楼-- · 2019-04-25 02:53

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.

查看更多
登录 后发表回答