I'm developing a build tool which can import dependencies from various other locations. I want to support importing svn, git, and mercurial repositories by specifying the URL for the repository. Ideally, I want to be able to automatically identify what kind of repository an URL refers to by inspecting the response from the server. For instance, with SVN the response over HTTP is an XML document with root element
Is there a similar way that I can identify a repository as either git or mercurial based on the HTTP response? Either by inspecting the headers or the content?
Best How To :
For Git, the server should expose an endpoint at
/info/refs. For the old ("dumb") HTTP protocol, this is simply the list of the server's references. The new ("smart") HTTP protocol will add a query string (
service=git-upload-pack) when fetching to indicate that it wants to begin the negotiation.
Thus, if you request
/info/refs?service=git-upload-pack, you should receive a 200 response.
The dumb HTTP protocol will respond with a text response that contains the 40 character commit ID of the reference, followed by a tab (
\t), followed by the name of the reference. For example:
The smart HTTP protocol will respond with a response of type
application/x-git-upload-pack-advertisement. The format of this response is described in the git HTTP protocol documentation (but if it were me, I would not parse it and simply deduce that a response of type
application/x-git-upload-pack is a Git server.)