是否有可能检测一个http git remote是否聪明或愚蠢? [英] Is it possible to detect whether a http git remote is smart or dumb?

查看:207
本文介绍了是否有可能检测一个http git remote是否聪明或愚蠢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用 - 深度1 来实现git仓库的最小功能克隆,并且我刚刚意识到愚蠢的http传输不支持 - 深度。我想自动检测一个http远程是愚蠢的还是聪明的,所以我可以省略 - 深度选项,当与愚蠢的http repos交谈时。这是否可能?



或者,有没有直接的方法来检查一个git远程是否支持 - depth

解决方案

一种方法是通过直接的HTTP查询。支持git客户端添加一个参数到第一个URL抓取的末尾,[repo] / info / refs?service = git-upload-pack。愚蠢的服务器只会发送info / refs文件作为忽略参数的文本,而智能服务器会在refs列表前返回一些二进制数据,包括文本service = git-upload-pack和一个特性列表(您可以从中找出深度支持)。

您可以使用wget或curl检查MIME类型来编写此智能/哑测试脚本: text / plain(dumb)vs. application / x-git-upload-pack-advertisement(smart)。

  $ curl  - si http://github.com/git/git.git/info/refs?service=git-upload-pack | grep --binary-files = text'^ Content-Type'
Content-Type:application / x-git-upload-pack-advertisement
$ curl -si http://git.kernel.org /pub/scm/git/git.git/info/refs?service=git-upload-pack | grep --binary-files = text'^ Content-Type'
Content-Type:application / x-git-upload-pack-advertisement
$ curl -si http://repo.or.cz /r/git.git/info/refs?service=git-upload-pack | grep --binary-files = text'^ Content-Type'
Content-Type:text / plain

(管道到 grep -q^ Content-Type:application / x-git并使用返回代码进行真/假测试。)


I'm implementing an option in my application to use --depth 1 to make a minimal functional clone of a git repo, and I've just realized that the dumb http transport doesn't support --depth. I'd like to automatically detect whether an http remote is dumb or smart so I can omit the --depth option when talking to dumb http repos. Is this possible?

Alternately, is there a direct way to check whether a git remote supports --depth?

解决方案

One way is by direct HTTP queries.

Smart-supporting git clients add an argument to the end of the first URL grabbed, "[repo]/info/refs?service=git-upload-pack". A dumb server will just send "info/refs" file as text ignoring the argument, while a smart server will return some binary data in front of the refs list, including text "service=git-upload-pack" and a list of features (which you might be able to figure out "depth" support from).

You can script this smart/dumb test by using wget or curl to check the MIME type: text/plain (dumb) vs. application/x-git-upload-pack-advertisement (smart).

$ curl -si http://github.com/git/git.git/info/refs?service=git-upload-pack | grep --binary-files=text '^Content-Type'
Content-Type: application/x-git-upload-pack-advertisement
$ curl -si http://git.kernel.org/pub/scm/git/git.git/info/refs?service=git-upload-pack | grep --binary-files=text '^Content-Type'
Content-Type: application/x-git-upload-pack-advertisement
$ curl -si http://repo.or.cz/r/git.git/info/refs?service=git-upload-pack | grep --binary-files=text '^Content-Type'
Content-Type: text/plain

(Pipe to grep -q "^Content-Type: application/x-git" and use the return code for true/false test.)

这篇关于是否有可能检测一个http git remote是否聪明或愚蠢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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