在 bash 脚本中,验证 git URL 是否指向有效的 git 存储库以及脚本是否有权从中读取的最简单方法是什么?
应支持的协议(protocol)是git@
、https://
和git://
。 Curl 在 git://
协议(protocol)上失败。
git@github.com:UserName/Example.git
https://UserName@github.com/UserName/Example.git
git://github.com/UserName/Example.git
注意:我不是要检查 URL 在语法上是否正确,我需要验证在从 bash 脚本中输入的 URL 位置是否存在存储库。
最佳答案
如 this issue 所示, 你可以使用 git ls-remote测试您的地址。
If you need to debug the git calls
set GIT_TRACE=1
. eg:
env GIT_PROXY_COMMAND=myproxy.sh GIT_TRACE=1 git ls-remote https://...
"
git ls-remote
" is the quickest way I know to test communications with a remote repository without actually cloning it. Hence its utility as a test for this issue.
您可以在“git ls-remote
returns 128 on any repo”中看到它用于检测地址问题。
关于git - 如何检查远程 git 存储库 URL 的有效性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9610131/