Extracting single file from remote hg repository

Gregor Mückl GregorMueckl at gmx.de
Sun Aug 25 23:08:23 UTC 2019


On 8/21/19 10:15 AM, Sietse Brouwer wrote:
> (Apologies to Scott for getting this message twice, I forgot to copy the
> list the first time I sent this.)
> 
> Gregor wrote:
>> I need to extract a single file from a
>> remote repository in an automated process.
>> [...]
>> The solution has to work at least on Windows and Linux.
> 
> On 19/08/2019 20:33, Scott Palmer wrote:
>> I don’t know as I’ve never used it, but if you are using SSH,
>> can’t you just run "hg cat” via SSH?
> 
> I've just tried Scott's suggestion on a virtual machine, and it works.
> Use SSH to run a command on the remote host; in this case, the command
> to retrieve a file is `hg cat -R {path/to/repo} -r {revision}
> {filename}`. That writes the file to stdout on your local machine; to
> create a local copy of the file, redirect stdout to a file.
> 
>     ssh {user at host} \
>         hg -R {path/to/repo} -r {revision} {filename} \
>         > {local_filename}
> 
> This solution assumes an SSH client on both Linux and Windows, and the
> ability to redirect to stdout.
> 
>
> Hope this helps,
> Sietse


Thanks, but what you suggested doesn't quite get me there yet. However,
I can't assume that I can run arbitrary commands just because I can use
the related ssh repo url with hg.

Your suggestion assumes a fully functional shell on the remote host,
which goes against best practices for Mercurial (or git) hosting. People
should really run restrictive pseudo-shells like hg-shell for the ssh
user accounts on the server which basically only allow running the hg
server for the ssh connection. So what you tested shouldn't work in a
properly secured environment.

I guess what I really would like to have is to have an extended version
of hg cat that does roughly the following:

1. If the repository is remote and the URL is an ssh URL, start a remote
hg serve as usual and pass the cat command through to it. The hg wire
protocol itself does support forwarding the cat command to a server.

2. If the repository is remote and the URL is an http URL, download just
enough of the remote repo to reconstruct the requested file.
Potentially, if the http server is detected to be an actual Mercurial
server (i.e. offers the Mercurial wire protocol instead of just serving
plain files), the HTTP equivalent of case 1 could be performed instead.

But... just on a whim based on how the wire protocol works I have tried
running "hg -R [ssh URL] cat [file]". The result is that I get a
password prompt and only afterwards do I get the message (URL censored):

abort: repository 'ssh://xxx@yyy/zzz' is not local

I haven't figured out the nature of this check. Why is it there? I am
assuming that it is there for a good reason.

Gregor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 9663 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20190826/14eaca00/attachment-0002.key>


More information about the Mercurial mailing list