Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查远程git存储库URL的有效性?_Git_Bash_Url_Curl_Github - Fatal编程技术网

如何检查远程git存储库URL的有效性?

如何检查远程git存储库URL的有效性?,git,bash,url,curl,github,Git,Bash,Url,Curl,Github,在bash脚本中,验证git URL是否指向有效的git repo以及脚本是否有权从中读取的最简单方法是什么 应该支持的协议有git@、https://和git://。Curl在git://协议上失败 git@github.com:UserName/Example.git https://UserName@github.com/UserName/Example.git git://github.com/UserName/Example.git 注意:我不是要求检查URL的语法是否正确,我需要验

在bash脚本中,验证git URL是否指向有效的git repo以及脚本是否有权从中读取的最简单方法是什么

应该支持的协议有
git@
https://
git://
。Curl在
git://
协议上失败

git@github.com:UserName/Example.git
https://UserName@github.com/UserName/Example.git
git://github.com/UserName/Example.git
注意:我不是要求检查URL的语法是否正确,我需要验证从bash脚本中输入的URL位置是否存在repo。

如中所示,您可以使用来测试您的地址

如果需要调试git调用,请设置git_TRACE=1。例如:

git ls remote
”是我所知道的测试与 远程存储库,而不实际克隆它。因此,它可以作为这方面的测试 问题


您可以在“.”中看到它用于检测地址问题。

虽然VonC的答案是正确的,但我最后使用的是:

将返回有关存储库的信息,默认情况下,这是HEAD、所有分支和标记,以及每个条目的提交ID。 e、 g:

要在bash脚本中使用它,以下操作将起作用

git ls remote“$SITE\u REPO\u URL”>/dev/null 2>&1
如果[“$?”-ne 0];然后
echo“[错误]无法从“$SITE\u REPO\u URL”读取”
出口1;
fi

注意:
/dev/null 2>&1
使stderr和stdout静音,因此该命令不会输出任何内容)

我建议不要对可移植脚本使用
&
,因为它似乎是bash扩展。在其他shell中,此语法无法按预期工作。虽然有一个类似的语法(
&-2>&-
),但该功能并不等效——它将关闭文件描述符,而不是静默重定向它们,这会导致许多程序中出现错误。您可以改为使用
/dev/null 2>&1
。我添加了GIT_ASKPASS=true以防止在错误url上提示输入用户名/密码。Google代码链接已断开,msysgit及其问题跟踪程序已移动到GitHub。我没有在GitHub上找到前一个问题,可能是因为我不确定应该搜索什么。@AttilaCsipak谢谢。我已恢复或更新丢失的链接
env GIT_PROXY_COMMAND=myproxy.sh GIT_TRACE=1 git ls-remote https://...
$ git ls-remote git://github.com/user/repo.git
<commit id>    HEAD
<commit id>    refs/heads/example_branch
<commit id>    refs/heads/master
<commit id>    refs/tags/v1.0.2
<commit id>    refs/tags/v1.0.0
fatal: The remote end hung up unexpectedly