【问题标题】:use git repo url to check whether repository exists使用 git repo url 检查存储库是否存在
【发布时间】:2014-04-22 10:29:30
【问题描述】:

我在google上搜索过,他们说“git ls-remote git-url”可以判断git repo是否存在。

但是当我使用这个命令来检查 github 不存在的 https git url 时我遇到了问题。

例如,当我运行下面的命令时,它需要输入用户名和密码。

$ git ls-remote https://github.com/grant/noexisted.git

我只想检查repo是否存在,我在里面调用“git ls-remote”命令 ruby 代码,那么如何跳过这个自动 shell 提示符?

【问题讨论】:

    标签: git bash ls-remote


    【解决方案1】:

    为什么不直接发出 HTTP 请求,然后查找 404?

    例如,您可以使用wget 命令行实用程序:

    $ 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(成功)会很简单。

    【讨论】:

    • 谢谢。是的,它可以工作。由于此 repo url 是由用户输入的,因此可以是任何值。如果只使用 git ls-remote 一个命令来检查会更好。如果使用您的建议,我需要检查 url 是 http repo url 还是其他 url(ssh 或 git)。如果没有更好的方法,我会使用你的建议。
    猜你喜欢
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 2011-01-11
    • 1970-01-01
    • 2020-08-30
    • 2019-03-10
    相关资源
    最近更新 更多