使用git repo url检查存储库是否存在 [英] use git repo url to check whether repository exists
问题描述
我在Google中搜索过,他们说"git ls-remote git-url"可以说出git repo是否存在.
I have searched in google, they say "git ls-remote git-url" can say whether git repo exists or not.
但是使用此命令检查github不存在的https git url时出现问题.
But i have a problem when use this command to check github unexisting https git url.
例如,当我运行以下命令时,将需要输入用户名和密码.
for example, when I run below command, it will require input username and password.
$ git ls-remote https://github.com/grant/noexisted.git
我只想检查存储库是否存在,我在其中调用"git ls-remote"命令 红宝石代码,那么如何跳过此自动shell提示?
I only want to check whether the repo exists or not, and I call "git ls-remote" command in ruby code, so how to skip this auto shell prompt?
推荐答案
为什么不仅仅发出HTTP请求并寻找404?
Why not just make an HTTP request, and look for a 404?
例如,您可以使用wget
命令行实用程序:
For example, you can use the wget
command-line utility:
$ wget https://github.com/grant/noexisted.git --no-check-certificate -o /dev/null
$ echo ?
这将打印8,而
$ wget https://github.com/mikeobrien/HidLibrary --no-check-certificate -o /dev/null
$ echo $?
这将显示0(成功).
我不熟悉Ruby,但是我敢肯定,发出HTTP请求并检查404(未找到)或200(成功)会很简单.
I'm not familiar with Ruby, but I'm sure it would be trivial to make the HTTP request and check for a 404 (not found) or 200 (success).
这篇关于使用git repo url检查存储库是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!