Jakob Malm
Jakob Malm

Reputation: 83

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

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?

Upvotes: 8

Views: 1795

Answers (2)

Martin Geisler
Martin Geisler

Reputation: 73788

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.

Upvotes: 8

Lazy Badger
Lazy Badger

Reputation: 97292

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

Upvotes: 0

Related Questions