简体   繁体   English

git存储库克隆日志

[英]git repository cloning logging

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. 我正在监视git存储库中的克隆活动,但是找不到任何显示如何设置或如何检索此信息的内容。

Is this even possible? 这有可能吗? If so how can this be setup and also how do you retrieve the logging information? 如果是这样,如何设置它以及如何检索日志记录信息?

You can use a post-checkout hook to update a database or file on your server. 您可以使用post-checkout挂钩来更新服务器上的数据库或文件。 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 . 另外,可以通过在git clone添加--no-checkout选项来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. 一种简单可靠的方法是让服务器运行一个小的RESTful Web服务,您的钩子可以使用curl或类似的功能调用该服务。 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 . 参见http://www.kernel.org/pub/software/scm/git/docs/githooks.html

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. git可能只是使用指定的协议(ssh,http,...)并获取适当的文件。 You could try to monitor that activity somehow. 您可以尝试以某种方式监视该活动。

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. 我能找到的更好的办法是包装git-upload-pack命令来记录调用。 This will only work over ssh though see: pre-fetch hook functionality in git 这只能在ssh上运行,但请参阅: git中的预取钩子功能

But only root will be able to do this. 但是只有root才能执行此操作。 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 ). 您可能总是会安装“ git服务器”来控制访问,例如gitolite( http://sitaramc.github.com/gitolite/master-toc.html )。 Either you can log it directly or you can extend it's functionality. 您可以直接将其记录下来,也可以扩展它的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM