68

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Josh
  • 4,427
  • 5
  • 28
  • 27

6 Answers6

103

You need a double // after hostname i.e.:

hg clone ssh://username@username.webfactional.com//path/to/projectname projectname
anteatersa
  • 1,449
  • 2
  • 12
  • 18
  • add [ui] remotecmd = /path/to/hg as well use above string for connection – rohtakdev Jan 31 '13 at 17:48
  • 4
    Why it works only with double `//` for me? Is this documented? – gavenkoa Oct 30 '13 at 22:10
  • 8
    @gavenkoa: Because the first slash is not part of the path, but just the separator between host and path, so with one slash it's just a path relative to the user's home directory. The second slash makes it an absolute path. – lwho Jan 14 '14 at 19:12
  • hg clone ssh://host://path-to-repo/ ... if you have a configured hostname in ~.ssh/config – Ryu_hayabusa Jul 22 '14 at 19:47
36

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Richard Cook
  • 32,523
  • 5
  • 46
  • 71
  • 1
    I followed these directions and added remotecmd = ~/bin/hg to the hgrc file in my project and in my home folder, however it doesnt seem to find that. Adding --remotecmd to the command given in the question works, however. How can I get it so I don't have to type it in every time – Josh Dec 13 '10 at 18:46
  • Put it in your `.hgrc` configuration file in the `[ui]` section. See comment in answer. – Richard Cook Dec 13 '10 at 19:24
  • You may have conflicts between your system-wide configuration, your user configuration and your project's configuration. Run `hg showconfig --debug` to see what your configuration is and where the values are derived from. – Richard Cook Dec 13 '10 at 19:40
  • Have you tried setting `remotecmd` to the absolute path to `hg` on your remote machine? – Richard Cook Dec 13 '10 at 19:49
  • Hmm. Do you set any default settings in the `[defaults]` section of any of your configuration files? It's possible that these might override/interfere with other configuration settings. Try removing any `[defaults]` that might relate to the `clone` command etc. and see if that makes any difference. However, it will most likely be easiest to change your bash profile on the remote system to ensure that `hg` is on the path. – Richard Cook Dec 13 '10 at 19:52
  • I haven't touched the defaults. I tried to change the path in ~/.bash_profile from PATH=$PATH:$HOME/bin to PATH=$PATH:$HOME/bin:/home/jrs0390/bin and PATH=$PATH:$HOME/bin:/home/jrs0390/bin/hg but neither of those worked – Josh Dec 13 '10 at 22:12
  • 2
    Try setting your path in `.bashrc`. Have you played with the `PermitUserEnvironment` setting in your `sshd_config` file? This article (http://serverfault.com/questions/130834/svnssh-getting-bash-to-load-my-path-over-ssh) discusses various settings and environment variables that might affect your `PATH`. – Richard Cook Dec 14 '10 at 00:00
  • Glad we figured it out eventually! – Richard Cook Dec 14 '10 at 05:57
  • 1
    remotecmd = /usr/local/bin/hg was the line I added to get my 'server' a Mac with mercurial to work with a pull request. Worked like a charm. – CenterOrbit Jan 03 '13 at 04:15
  • 1
    I'm doing the same as CenterOrbit (= HomeBrew's location for hg). Likely the problem with @Josh back in 2010 has been the use of ~. Should use absolute path - it's pointing at a remote machine anyway. – akauppi Mar 31 '13 at 16:51
  • For one-off usage you can also give the remotecmd option on the command line instead of setting it permanently in .hgrc: `hg --config ui.remotecmd=/path/to/hg clone ...` – lwho Jan 14 '14 at 19:20
4

Looks like mercurial isn't in your user's PATH on the remote server.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185
2

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)

Michael Dunn
  • 8,163
  • 4
  • 37
  • 54
kdahlhaus
  • 480
  • 5
  • 8
  • Adding `remotecmd` to a local `.hgrc` fixed the path issue. However, in my particular setup `remotecmd` introduced another error: `remote: conq: invalid command syntax`. Just adding the PATH value to `.bashrc` (on webfaction) was enough and really solved any issue for me. – Paolo Mar 10 '13 at 20:54
1

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.

  1. From the repository, click + in the global sidebar and select Clone this repository under Get to work.
  2. 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.
  3. From a terminal window, change to the local directory where you want to clone your repository.
  4. 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.
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

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.

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102