use git repo url to check whether repository exists

这一生的挚爱 提交于 2020-01-06 17:55:08

问题


I have searched in google, they say "git ls-remote git-url" can say whether git repo exists or not.

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

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?


回答1:


Why not just make an HTTP request, and look for a 404?

For example, you can use the wget command-line utility:

$ wget https://github.com/grant/noexisted.git --no-check-certificate -o /dev/null
$ echo ?

This prints 8, while

$ wget https://github.com/mikeobrien/HidLibrary --no-check-certificate -o /dev/null
$ echo $?

this prints 0 (success).

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).



来源:https://stackoverflow.com/questions/22450620/use-git-repo-url-to-check-whether-repository-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!