我正在我的应用程序中实现一个选项来使用--depth 1
制作 git repo 的最小功能克隆,我刚刚意识到愚蠢的 http 传输不支持--depth
。我想自动检测 http 远程是愚蠢的还是聪明的,这样我就可以省略--depth
与哑 http 存储库对话时的选项。这可能吗?
或者,有没有直接的方法来检查 git 远程是否支持--depth
?
一种方法是直接 HTTP 查询。
支持智能的 git 客户端会在第一个抓取的 URL 末尾添加一个参数,“[repo]/info/refs?service=git-upload-pack”。哑服务器只会将“info/refs”文件作为文本发送,忽略参数,而智能服务器将在 refs 列表前面返回一些二进制数据,包括文本“service=git-upload-pack”和功能列表(您也许能够从中找到“深度”支持)。
您可以使用 wget 或curl 编写此智能/哑测试脚本来检查 MIME 类型:text/plain(哑)与 application/x-git-upload-pack-advertisement(智能)。
$ 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"
并使用返回码进行真/假测试。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)