tests/test-symlink-placeholder.t
author Matt Mackall <mpm@selenic.com>
Sun, 23 Oct 2011 16:32:27 -0500
branchstable
changeset 15348 c681e478c429
child 15441 e0348815e806
permissions -rw-r--r--
windows: sanity-check symlink placeholders On Windows, we store symlinks as plain files with the link contents. Via user error or NFS/Samba assistance, these files often end up with 'normal' file contents. Committing these changes thus gives an invalid symlink that can't be checked out on Unix. Here we filter out any modified symlink placeholders that look suspicious when computing status: - more than 1K (looks more like a normal file) - contain NULs (not allowed on Unix, probably a binary) - contains \n (filenames can't contain \n, very unusual for symlinks, very common for files)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15348
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
Create extension that can disable symlink support:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
  $ cat > nolink.py <<EOF
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
  > from mercurial import extensions, util
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
  > def setflags(orig, f, l, x):
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
  >     pass
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
  > def checklink(orig, path):
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
  >     return False
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
  > def extsetup(ui):
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
  >     extensions.wrapfunction(util, 'setflags', setflags)
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
  >     extensions.wrapfunction(util, 'checklink', checklink)
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
  > EOF
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
  $ hg init unix-repo
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
  $ cd unix-repo
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
  $ echo foo > a
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
  $ ln -s a b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
  $ hg ci -Am0
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
  adding a
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
  adding b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
  $ cd ..
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
Simulate a checkout shared on NFS/Samba:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
  $ hg clone -q unix-repo shared
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
  $ cd shared
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
  $ rm b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
  $ echo foo > b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
  $ hg --config extensions.n=$TESTTMP/nolink.py status --debug
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
  ignoring suspect symlink placeholder "b"
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
Make a clone using placeholders:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
  $ hg --config extensions.n=$TESTTMP/nolink.py clone . ../win-repo
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
  updating to branch default
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
  $ cd ../win-repo
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    38
  $ cat b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
  a (no-eol)
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    40
  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
Write binary data to the placeholder:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    43
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    44
  >>> open('b', 'w').write('this is a binary\0')
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    45
  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
  ignoring suspect symlink placeholder "b"
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    47
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    48
Write a long string to the placeholder:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    49
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    50
  >>> open('b', 'w').write('this' * 1000)
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    51
  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    52
  ignoring suspect symlink placeholder "b"
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    53
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    54
Commit shouldn't succeed:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    55
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    56
  $ hg --config extensions.n=$TESTTMP/nolink.py ci -m1
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    57
  nothing changed
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    58
  [1]
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    59
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    60
Write a valid string to the placeholder:
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    61
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    62
  >>> open('b', 'w').write('this')
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    64
  M b
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    65
  $ hg --config extensions.n=$TESTTMP/nolink.py ci -m1
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    66
  $ hg manifest tip --verbose
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    67
  644   a
c681e478c429 windows: sanity-check symlink placeholders
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    68
  644 @ b