Source

hg-importfs / test-importfs-symlinks.t

These tests only work with Operating Systems which support symlinks!

  $ "$TESTDIR/hghave" symlink || exit 80

Load the extension:

  $ echo "[extensions]" >> $HGRCPATH
  $ echo "importfs = $TESTDIR/importfs.py" >> $HGRCPATH

Create a simple filesystem structure for import containing symlinks:

  $ mkdir d1
  $ echo "c1" > d1/f1
  $ echo "c2" > d1/f2
  $ mkdir d1/d2
  $ echo "c3" > d1/d2/f3
  $ echo "c4" > d1/d2/f4
  $ mkdir d1/d3
  $ cd d1
  $ ln -s d2 d4
  $ cd d3
  $ ln -s ../f1 f5
  $ cd ../..

Perform an import:

  $ hg importfs r1 d1
  created repository $TESTTMP/r1
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  adding d2/f3
  adding d2/f4
  adding d3/f5
  adding d4
  adding f1
  adding f2

Take a look a the repository and see if the symlinks were not dereferenced:

  $ hg manifest -v -R r1
  644   d2/f3
  644   d2/f4
  644 @ d3/f5
  644 @ d4
  644   f1
  644   f2

Remove the symlink's target:

  $ rm -rf d1/d2

Perform another import:

  $ hg importfs r2 d1
  created repository $TESTTMP/r2
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  adding d3/f5
  adding d4
  adding f1
  adding f2

The symlink has been imported even with the target missing:

  $ hg manifest -v -R r2
  644 @ d3/f5
  644 @ d4
  644   f1
  644   f2

  $ ls -la r2/d4/
  ls: r2/d4/: No such file or directory
  [1]

Clean up:

  $ rm -f d1/d4

Create symlinks with backslashes:

  $ mkdir d1/d2
  $ echo c3 > d1/d2/f3
  $ cd d1/d2
  $ ln -s "..\f1" f4
  $ ln -s "..\d3" d4
  $ cd ../..
  $ cat d1/d2/f4
  cat: d1/d2/f4: No such file or directory
  [1]
  $ ls d1/d2/d4/
  ls: d1/d2/d4/: No such file or directory
  [1]
  $ ln -s "d2\f3" d1/f6
  $ cat d1/f6
  cat: d1/f6: No such file or directory
  [1]

Now run the import:

  $ hg importfs --debug r3 d1
  created repository $TESTTMP/r3
  resolving manifests
   overwrite: True, partial: False
   ancestor: 000000000000+, local: 000000000000+, remote: 000000000000
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  creating directory $TESTTMP/r3/d2
  dereferenced d1/d2/d4 to d1/d2/../d3
  creating directory $TESTTMP/r3/d2/d4
  copying d1/d2/../d3/f5 to $TESTTMP/r3/d2/d4/f5
  copying d1/d2/f3 to $TESTTMP/r3/d2/f3
  dereferenced d1/d2/f4 to d1/d2/../f1
  copying d1/d2/../f1 to $TESTTMP/r3/d2/f4
  creating directory $TESTTMP/r3/d3
  creating symlink $TESTTMP/r3/d3/f5 -> ../f1
  copying d1/f1 to $TESTTMP/r3/f1
  copying d1/f2 to $TESTTMP/r3/f2
  dereferenced d1/f6 to d1/d2/f3
  copying d1/d2/f3 to $TESTTMP/r3/f6
  adding d2/d4/f5
  adding d2/f3
  adding d2/f4
  adding d3/f5
  adding f1
  adding f2
  adding f6
  searching for exact renames: 0/7 (0.00%)
  searching for exact renames: 1/7 (14.29%)
  searching for exact renames: 2/7 (28.57%)
  searching for exact renames: 3/7 (42.86%)
  searching for exact renames: 4/7 (57.14%)
  searching for exact renames: 5/7 (71.43%)
  searching for exact renames: 6/7 (85.71%)
  d2/d4/f5
  d2/f3
  d2/f4
  d3/f5
  f1
  f2
  f6
  committed changeset 0:???????????????????????????????????????? (glob)

The backslashes are replaced and the symlinks containing them before are dereferenced:

  $ hg manifest -v -R r3
  644   d2/d4/f5
  644   d2/f3
  644   d2/f4
  644 @ d3/f5
  644   f1
  644   f2
  644   f6
  $ cat r3/d2/f4
  c1
  $ cat r3/f6
  c3