25

As of 0.9.4, when adding a symbolic link Mercurial keeps track of the link itself, and not the file or directories it points to. However, there are cases when it is desirable to keep track of the files pointed to by the symbolic link.

How can I force Mercurial to treat the symbolic link to a directory as a regular directory?

D R
  • 21,936
  • 38
  • 112
  • 149
  • 3
    have you tried hard instead of soft links? – miku Dec 25 '09 at 12:12
  • 1
    I'm on a Mac, and I can't get `ln` to produce hard links. It complains that the the target is a directory. – D R Dec 25 '09 at 15:43
  • 2
    From `ls(1)` on my Linux machine: `-d`, `-F`, `--directory`: allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser). – Martin Geisler Dec 25 '09 at 18:29
  • 4
    @The MYNN: You can't make hardlinks to directories. – Nicolás Dec 26 '09 at 04:39
  • So did you find a solution or did you just stop using hg? I'm using xmapp at home and have some ISP I pay for my actual website. xmapp uses htdocs, the ISP uses public_html. I wanted to manage this with hg and just add a symbolic link from public_html to htdocs on the isp's server only to find that's apparently impossible because of this stupid hg thing. – gman May 09 '10 at 21:11
  • Another possible solution is hard link - http://stackoverflow.com/questions/1432540/creating-directory-hard-links-in-macos-x – Maciek Sawicki Feb 23 '12 at 16:20
  • @Celil: Try http://stackoverflow.com/a/5118678/149482 – Matt Joiner Dec 18 '14 at 03:58

4 Answers4

25

Under linux you can use

mount --bind sourcepath targetpath

instead of symbolic links and mercurial will treat target as usual directory (tested on openSUSE 11.2 with Mercurial 1.3.1, and on RHEL6).

The alternative syntax, amenable for inclusion in /etc/fstab, is

mount -o bind sourcepath targetpath

The fstab entry is, then

sourcepath targetpath none defaults,bind 0 0
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Rage Steel
  • 606
  • 5
  • 4
  • I have confirmed that sudo mount --bind sourcepath targetpath as recommended by Rage Steel works for me on Linux (Ubuntu 10.04 with Mercurial 1.4.3). – pvillela Nov 27 '10 at 01:14
5

I don't think there's a way to do this when you're working with directories.

If you're working with mercurial 1.3 or later you could try using the new subrepo support, that will let you have a repo track stuff ourside of it on the local disk, but it's not as seamless as a link would have been.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
5

I was surprised when I found this too, but it seems to be a feature that the Mercurial team don't want to change for security reasons.

I'm planning to get around it by using rsync to update the local copy of the directory before committing, from my makefile. This isn't a great solution but my directory is quite small so it should be OK.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sparklewhiskers
  • 910
  • 8
  • 19
2

Just a follow up on Rage Steel's excellent answer (mount --bind):

To make your mount ready on boot (since mounts don't survive reboots), in your /etc/fstabs put:

/paht/to/source /path/to/target bind defaults,bind 0 0

Just make sure to put it after your source is mounted.

olafure
  • 3,518
  • 2
  • 33
  • 45