Francisco1844
Francisco1844

Reputation: 1208

How to import using mercurial with SSH?

Is it possible to import a module using mercurial with ssh?

I have found very little on using mercurial with go and the little that I found was with http.

Upvotes: 2

Views: 107

Answers (1)

torek
torek

Reputation: 488183

The short answer is yes.

The text displayed by go help importpath, or available here, describes how to set import paths so as to imply a particular version control system. Some sites are known in advance:

A few common code hosting sites have special syntax:
[list snipped, but GitHub implies using Git protocol, Launchpad implies Bazaar, and so on]

For code hosted on other servers, import paths may either be qualified with the version control type, or the go tool can dynamically fetch the import path over https/http and discover where the code resides from a <meta> tag in the HTML.

So if you don't have access to or control over this sort of <meta> tag, you should import with an explicitly-specified VCS:

... an import path of the form

repository.vcs/path

specifies the given repository, with or without the .vcs suffix, using the named version control system, and then the path inside that repository.

That is, to tell go get that it must speak Mercurial protocol to host example.com you might use:

import "example.com/me.hg/repo"

or:

import "example.com/me/repo.hg"

where the .hg is what implies the use of Mercurial.

Once you've chosen a specific VCS, things get a little trickier:

When a version control system supports multiple protocols, each is tried in turn when downloading. For example, a Git download tries https://, then git+ssh://.

The source code for the Go VCS importer has the details. Mercurial repository imports try https first, then ssh.

If you can use the <meta> tag, that can provide more detail, so that you can avoid the relatively clumsy .hg in the import path:

If the import path is not a known code hosting site and also lacks a version control qualifier, the go tool attempts to fetch the import over https/http and looks for a <meta> tag in the document's HTML <head>.

If you're implementing the <meta> response to the request page,read all of the rest of this, because this goes on to say:

When using modules, an additional variant of the go-import meta tag is recognized and is preferred over those listing version control systems. That variant uses "mod" as the vcs in the content value, as in:

<meta name="go-import" content="example.org mod https://code.org/moduleproxy">

This tag means to fetch modules with paths beginning with example.org from the module proxy available at the URL https://code.org/moduleproxy. See 'go help goproxy' for details about the proxy protocol.

Upvotes: 5

Related Questions