git存储库克隆日志 [英] git repository cloning logging

查看:239
本文介绍了git存储库克隆日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是我的git存储库中的克隆活动,但我找不到任何显示如何设置或如何检索此信息的内容。这甚至有可能吗?如果是的话,如何设置,以及如何检索日志记录信息?

您可以使用 post-checkout hook来更新服务器上的数据库或文件。这个钩子在客户端运行(即,执行克隆的人将执行脚本),因此您需要从该角度设计脚本。另外,通过向 git clone 添加 - no-checkout 选项,可以克隆版本库而不执行此钩子>。

一个简单可靠的方法是让服务器运行一个小的RESTful Web服务,您的钩子可以用 curl 或一些类似的设施。例如:

 #!/ usr / bin / env python 

导入套接字,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。执行()

请参阅 http://www.kernel.org/pub/software/scm/git/docs/githooks.html


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?

解决方案

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.

这篇关于git存储库克隆日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆