如何检查远程Git仓库URL的有效性? [英] How to check the validity of a remote git repository URL?
问题描述
在bash脚本,这将是验证最简单的方法,一个git的URL指向有效的git回购和脚本访问从中读取数据?
这是应该得到支持的协议是 git的@
,的https://
和混帐://
。卷曲的 git的失败://
协议
git@github.com:用户名/ Example.git
HTTPS://UserName@github.com/UserName/Example.git
混帐://github.com/UserName/Example.git
请注意:我不要求检查,看是否有URL语法正确,我需要验证回购存在于从bash脚本中输入的URL位置
。作为的这个问题,则可以使用 git的LS-远程来测试你的地址。
如果您需要调试的git电话
设置GIT_TRACE = 1
。例如:
块引用>ENV GIT_PROXY_COMMADN = myproxy.sh GIT_TRACE = 1 git的LS-远程https://开头...
git的LS-远程
是我知道的测试与通信的最快方法
远程仓库没有实际克隆。因此,它作为这个测试工具
问题。
块引用>您可以看到它用于检测地址问题<任何回购code> git的LS-远程返回128。
Within a bash script, what would be the simplest way to verify that a git URL points to a valid git repo and that the script has access to read from it?
Protocols that should be supported are
git@
,https://
, andgit://
. Curl fails on thegit://
protocol.git@github.com:UserName/Example.git https://UserName@github.com/UserName/Example.git git://github.com/UserName/Example.git
Note: I'm not asking to check to see if a URL is syntactically correct, I need to verify that a repo exists at the URL location entered from within a bash script.
解决方案As seen in this issue, you can use git ls-remote to test your address.
If you need to debug the git calls
set GIT_TRACE=1
. eg:
env GIT_PROXY_COMMADN=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.You can see it used for detecting an address issue in "
git ls-remote
returns 128 on any repo".这篇关于如何检查远程Git仓库URL的有效性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!