mbaitoff
mbaitoff

Reputation: 9091

How to make Mercurial detect changes made to the target of a symlink

I have a project version-controlled by the Mercurial (project main). The project references (uses) some files from another project (sub) by a symbolic link in the main pointing to a file in sub. The symbolic link is added to the main's repository.

The problem is that Mercurial doesn't detect changes made to the target file at sub, not marking the symlink as 'M' (modified).

The situation is shown in the following example:

Create, init and commit initial repos:

$ mkdir crap
$ cd crap
$ mkdir main sub
$ cd sub
$ nano sub.txt
$ hg init
$ hg add sub.txt 
$ cd ../main/
$ nano main.txt
$ ln -s ../sub/sub.txt ./sub.txt
$ ls -la
total 24
drwxrwxr-x 2 ruslan ruslan 4096 Jan 15 12:51 .
drwxrwxr-x 4 ruslan ruslan 4096 Jan 15 12:48 ..
-rw-rw-r-- 1 ruslan ruslan   20 Jan 15 12:51 main.txt
lrwxrwxrwx 1 ruslan ruslan   14 Jan 15 12:51 sub.txt -> ../sub/sub.txt
$ hg init
$ hg add main.txt sub.txt 
$ hg commit -m "First"
$ cd ../sub
$ hg commit -m "Sub First"
$ hg status ./sub -A
C sub/sub.txt
$ hg status ./main -A
C main/main.txt
C main/sub.txt

now modify and commit the target in sub:

$ nano ./sub/sub.txt 
$ hg status ./sub -A
M sub/sub.txt
$ hg commit ./sub -m "Modified"
$ hg status ./sub -A
C sub/sub.txt

now status of the main shows that the symlink that references the target is not marked as 'M':

$ hg status ./main -A
C main/main.txt
C main/sub.txt

modifying the sub again without the commit shows 'M' in sub but not in main:

$ nano ./sub/sub.txt 
$ hg status ./sub
M sub/sub.txt
$ hg status ./main -A
C main/main.txt
C main/sub.txt

How can I properly make Mercurial detect changes in symlinks' targets?

Upvotes: 1

Views: 312

Answers (2)

Daniel Sokolowski
Daniel Sokolowski

Reputation: 12478

You can use a hard link instead by omitting -s parameter when creating with ln.

I recommend appending .hardlink to be explicit and modifying your ls to highlight hardlinks.

On a windows machine I have used same approach using Link Shell Extension utility; I donated to the author and you should do the same :).

enter image description here

Upvotes: 0

Mathiasdm
Mathiasdm

Reputation: 1831

You can't. For security reasons, Mercurial never traverses symbolic links.

Upvotes: 3

Related Questions