Accessing Mercurial repositories over SSH - mercurial

I can successfully access repositories over http:// using hgweb.cgi:
$ hg clone http://mydomain.com/scgi-bin/hgweb.cgi/myrepo
I can also successfully ssh into mydomain.com using a password.
$ ssh myname#mydomain.com
myname#mydomain.com's password: xxxxxx
Last login: Sat Jun 9 .....
myname#mydomain.com [~]# ls public_html/scgi-bin
./ ../ hgweb.cgi*, hgweb.config
However I can't deduce how to serve repositories via SSH. For example, this doesn't work:
$ hg clone ssh://myname#mydomain.com/public_html/scgi-bin/hgweb.cgi/myrepo
myname#mydomain.com's password: xxxxx
remote: stdin: is not a tty
remote: bash: hg: command not found
abort: no suitable response from remote hg!
I'm concluding that unlike http://, ssh:// doesn't know how to run the cgi script, would that be correct? Is there a solution to this?
(btw: this is on shared hosting, where http's root is public_html/, ssh's root is one directory up.)

HTTP is not the same as SSH. HTTP is a stateless, request-based transmission protocol. SSH is a protocol which establishes a permanent, stateful connection between two machines.
Your HTTP URL looks like a full path to a repository, but it goes through a web server, which is executing the hgweb.cgi script, passing it myrepo as an argument. The hgweb.cgi script runs Mercurial on the server against the myrepo repository (it pulls the actual location from a config file on the server). The command chain looks like this:
Local Mercurial -> HTTP -> Web Server -> hgweb.cgi > Server Mercurial
The SSH URL you're using in the second example tells Mercurial to log into the mydomain.com server as myname, and it can find the repository at /public_html/scgi-bin/hgweb.cgi/myrepo. Most likely, that isn't where your repo is at. The command chain looks like this:
Local Mercurial -> SSH -> Server file system
You need to change your SSH URL to use the absolute path to the repo on the server:
hg clone ssh://myname#mydomain.com/path/to/myrepo
It also looks like the server can't find the Mercurial executable.

Upon using hg's 'verbose' option, two problems were revealed:
When called over ssh, hg automatically tries to run the hg server, hence no need to go via hgweb.cgi.
The path for the hg command (which was set in .bash_profile) didn't get used for non-interactive SSH commands. I had to put the path to hg somewhere that was, such as .bashrc.
Fixing all that up, the following command worked as expected:
hg clone ssh://myname#mydomain.com/public_html/myrepo

Related

Cloning a Mercurial repository over SSH

I'm having some difficulty cloning my mercurial repository over ssh.
Here's what I have tried:
hg clone ssh://username#username.webfactional.com/path/to/projectname projectname
It's giving me this error:
remote: bash: hg: command not found
abort: no suitable response from remote hg!
hg is installed on the server, however.
I was trying to follow the instructions on this website.
You need a double // after hostname i.e.:
hg clone ssh://username#username.webfactional.com//path/to/projectname projectname
Sounds like hg is not on your path. The Mercurial FAQ mentions possible fixes for this issue: FAQ/CommonProblems.
Add the remotecmd value to your Mercurial configuration by opening ~/.hgrc (or Mercurial.ini on Windows) on your client machine and adding the following:
[ui]
remotecmd = /path/to/hg
where /path/to/hg is the path to the hg command on the remote server.
If you're having problems with your Mercurial configuration, you can use the hg showconfig --debug command to obtain a full list of your Mercurial settings along with the path and line number of the configuration file that defines each configuration value.
Looks like mercurial isn't in your user's PATH on the remote server.
On webfactional I had to add:
export PATH=$PATH:/home/<user>/bin
to .bashrc to get it to work.
(also followed the remotecmd advice above)
You can use Sourcetree, TortoiseHg, Mercurial from the terminal, or any client you like to clone your Mercurial repository. These instructions show you how to clone your repository using Mercurial from the terminal.
From the repository, click + in the global sidebar and select Clone
this repository under Get to work.
Copy the clone command (either the SSH format or the HTTPS).
If you are using the SSH protocol, ensure your public key is in Bitbucket and loaded on the local system to which you are cloning.
From a terminal window, change to the local directory where you want to clone your repository.
Paste the command you copied from Bitbucket, for example:
CLONE OVER HTTPS:
$ hg clone https://username#bitbucket.org/teamsinspace/hg-documentation-tests
CLONE OVER SSH:
$ hg clone ssh://hg#bitbucket.org/teamsinspace/hg-documentation-tests
If the clone was successful, a new sub-directory appears on your local drive.
This directory has the same name as the Bitbucket repository that you cloned.
The clone contains the files and metadata that Mercurial requires to maintain the changes you make to the source files.
On the server, type: nano ~/.bashrc end edit the file by adding:
# User specific aliases and functions
export PATH=$PATH:$HOME/packages/mercurial
Under the assumption that ~/packages is the folder where mercurial was installed.
After editing, finish off with source ~/.bashrc and try again.
Pretty helpful to me was the following elaborate guide to install mercurial on a Bluehost hosting server.

Remote Mercurial without installing Mercurial

I have a server with ssh, that I want to use as a central repo. However I can not install mercurial on it. Therefore how can clients push to the server over ssh without having mercurial installed on the server.
Thank You
You do not have to install mercurial on that server. if you can mount it then you can create a regular repository by providing the path to "hg init" for creating a repository on this remote server.
Another way is sshfs. This is a filesystem client based on the SSH File Transfer Protocol.
http://fuse.sourceforge.net/sshfs.html
So using this you could do
sshfs hostname: mountpoint # mounts the file system
hg init mountpoint # do your mercurial operation
fusermount -u mountpoint # unmounts the file system
I have not done this but you could give a try.
Be aware that you can probably install mercurial on the server even if you think you can't. If you have a system with a similar architecture you can make local to install mercurial right in its own distribution directory and then just scp that up to the server.
The only difference in this case is that if you can't get the resulting you#there:mercurialCopiedIn/hg into the $PATH then you'll need to use the --remotecmd argument on your pushes and pulls to say what binary to use.
If the local system can mount the remote repository using sshfs then that would work. Otherwise you're out of luck. :-(

create hgrc file to work on all paths on a machine, and for several repos

I want to create a hgrc file to set the username and password for all paths on some machine, e.g no matter in which directory I am in, hg clone some_path will always work without prompting for a username and a password (this is for an auto-deploy script). Also, it should work for several repos, not just one.
I followed the instructions and created a file: /etc/mercurial/hgrc.d/deploy.rc
it's contents:
[auth]
default.prefix= http://myrepo
default.username = myuname
default.password = pwd
But when I do
hg clone some_path I get abort: error: Connection refused.
What Am i doing wrong?
It should work. You can use hg showconfig to verify that it really is reading the config and that you don't just have a connection problem or something.
What version of hg are you using?
Also, it could be that your .hg/hgrc file is taking precedence over your global config.
Could you get the log of the server you try to connecgt to?
It should be listed there if at least the server address is correct.
And perhaps a hg clone -v something

How to clone repository to a remote server/repository with Mercurial

Found myself quite confused today about this.
I create a blank repository locally(hg init), cloned it to working copy, added some code, commited and pushed it(to local repo obviously).
Now I need to share that repository with others. There is a server that has mercurial on it, how do I clone my repository to a remote one such that other developers can access it and pull/push code from/to it?
You'll want to check out the publishing repositories wiki page to get into web interfaces and access controls, but at it's most basic you can do something like this:
hg clone yourlocalrepo ssh://you#server//home/you/repo
That clones your local repo to a remote location of your choosing. Note that there are two double slashes in that URL.
You can't create a remote repo like that using http://, only ssh://. If all you have is http to hgweb.cgi you can 'hg init' an empty repo on the server and then hg push to it.
If your "official" repositories are served up by an HTTP server, and you want to create a repo in the central location based on a local machine's repo, here's one way. You need admin rights on the central server to do this.
e.g. I'm developing on windows, and my central repository is running on linux and served by lighttpd per the official guide. The server's central repo directory is /var/hg/repos/, owned by the user/group www-data. My local machine's IP is 10.1.10.100, and the repository I want to clone is named foo.
On the local machine, open a command prompt into the repository directory and type hg serve. This runs the local hg web server, which will allow the server to pull from it.
ssh into the central repo server, logging in as a user with sudo rights to www-data.
cd /var/hg/repos
sudo -u www-data hg clone http://10.1.10.100 foo
For those that come later and don't want to bother about the hassles of ssh for pushing changes to a server built to host repos, you can just init on the server, and then push as you do every other repo.
# on server:
cd repos/
mkdir myrepo
cd myrepo
hg init
cd ..
chown -R apache:apache myrepo
cd ..
vim hgweb.config
# change [paths]
[paths]
myrepo = /path/to/myrepo
# on your machine
# make sure you've configured hgrc correctly
[paths]
default = http://server/hg/repos/myrepo
hg push
# ???
# profit

Can not clone mercurial (hg) repository via http

I can't clone my repository via http:
abort: 'http://MYREPO' does not appear to be an hg repository!
Firstly, I created a new repo by hg init MYREPO followed by adding some file and commit.
The dir with my repo is password protected but there is no sign of problem because of it, I tried both methods of cloning:
(on my local machine)
hg clone http://MYREPO my_repo
and
hg clone http://user:password#MYREPO my_repo
Permissions of repo dir are: drwxrwxr-x
I can clone this very repository on my remote machine (the same repo is on) without any problems.
What could be possibly wrong?
UPDATE:
Looks like you're getting confusing between repository and hostname
If running "hg serve", "hg clone http://USER#HOST:8000" where host can be you machine's IP or the hostname (type "hostname" on linux or try "ping localhost"). You can change the default port from 8000 by passing a --port #### to hg serve.
If you want to do it over ssh, "hg clone ssh://USER#HOST//PATH/TO/YOUR/REPOSITORY". Suppose you made an repository in your home directory called MYREPO then you would do this: "hg clone ssh://USER#HOST/~/MYREPO"
You can only clone your repo via http is something is serving that repo over http. Mercurial provides a built in http server for you. Run "hg serve" while inside of your repo then attempt to clone it from another location (or another command shell). If you just want a local clone, you don't need to use http ("hg clone ").
Also, try "hg help clone" and "hg help serve" for details.
weirdly, cloning with ssh requires a non-intuitive extra forward slash.
this works for me on a host with ssh running on port 43211
hg clone ssh://example.com:43211//repos/myRepo ./myRepo
the double slash after the port number works, but a single slash there results in the ".hg not found" error
besszero is right, but why don't you clone using SSH if you are gonna use username and password anyway?
hg clone ssh://machine_ip//your/repo/location your_repo
It's also safer if you don't want to open another port for mercurial's http server and you don't need the hgweb features, the traffic is also encrypted. The only con is that you have to log in to checkout, but HTTP doesn't work for pushing back the changes, at least not in my experience.
Argh... One need to be careful with .htaccess configuration. In my case I needed to add 'hgwebdir.cgi' to the path to clone... Thanks for the answers though!
SSH seems logical but somehow I couldn't use it with user other than my local:
hg clone ssh://MY_REMOTE_USER#MYREPO
remote: abort: There is no Mercurial repository here (.hg not found)!