Check if a url is a mercurial repository (like git ls-remote)

扶醉桌前 提交于 2019-12-10 12:49:01

问题


How can I check whether a URL points to a mercurial repository? With git, I would use git ls-remote $url and check the return value. Is there something similar for hg?


回答1:


You can use hg identify for this: it can be run against a remote repository and Mercurial will abort with an exit code of 255 if the path given isn't a repository. This repository exists:

$ hg identify https://bitbucket.org/mg/mercurial-talk; echo $?
7788b512c5bd
0

This one doesn't:

$ hg identify https://bitbucket.org/mg/git-talk; echo $?
abort: HTTP Error 404: Not Found
255

You'll probably want to redirect both stdout and stderr to /dev/null.




回答2:


AFAIK, ls-remote (used inside repo) with Git-URL show references into this URL from local, yes?

If you want to know for Mercurial, which remote repositories it know (not used for push|pull, only know), you can use hg paths

If you want for some random URL define, is it Mercurial repo or not, you can at least to try clone from this URL



来源:https://stackoverflow.com/questions/16145854/check-if-a-url-is-a-mercurial-repository-like-git-ls-remote

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!