简体   繁体   English

测试是否有<repository> `git clone` 可以接受而不实际克隆它

[英]Test whether a <repository> is acceptable to `git clone` without actually cloning it

Given an arbitrary string that might or might not be acceptable to git clone as its <repository> argument, is there a way (presumably using low-level "plumbing" commands) to determine whether this string could be cloned, without actually doing the clone?给定一个任意字符串,它可能会或可能不被git clone接受作为其<repository>参数,有没有办法(大概使用低级“管道”命令)来确定是否可以克隆该字符串,而无需实际进行克隆?

Specifically, I want to reject strings that git clone cannot parse as a <repository> , or that would require use of a "remote helper" that is not installed, but I do not want to do any actual network communication at this stage of the process.具体而言,我要拒绝字符串git clone无法解析作为<repository> ,或者将要求使用未安装“远程辅助”的,但我想要做在这个阶段的任何实际的网络通信过程。 (Therefore, strings that would fail to clone because the remote repository does not exist or isn't willing to communicate with me should be accepted .) (因此,应该接受由于远程存储库不存在或不愿意与我通信而无法克隆的字符串。)

还有其他命令可以与远程通信,并检查存储库是否有效,例如:

git ls-remote <url>

As LeGEC mentioned, it's possible to test this with network connectivity, using git ls-remote , but if you don't want to perform a network operation, there's no way to do this.正如 LeGEC 所提到的,可以使用git ls-remote使用网络连接测试这一点,但如果您不想执行网络操作,则无法执行此操作。 That's because Git can invoke helpers for various kinds of remotes, including HTTPS, and it won't invoke those helpers unless an actual network operation is occurring.这是因为 Git 可以为各种远程设备调用帮助程序,包括 HTTPS,并且除非发生实际的网络操作,否则它不会调用这些帮助程序。

You could try looking for the remote helper with which or command -v (the latter is POSIX; the former is not), but that won't help if it's actually located in $GIT_EXEC_PATH .您可以尝试使用whichcommand -v寻找远程助手(后者是 POSIX;前者不是),但如果它实际上位于$GIT_EXEC_PATH ,那将$GIT_EXEC_PATH Otherwise, you'll have to do the parsing yourself, which, as someone who's done this for Git LFS, I can tell you is not exactly trivial.否则,您将不得不自己进行解析,作为为 Git LFS 完成此操作的人,我可以告诉您这并非微不足道。 The source code is your reference here.源代码是您的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM