tests/test-arbitraryfilectx.t
changeset 34835 14c87708f432
child 34936 9645c2a2bc2a
equal deleted inserted replaced
34834:2e8477059d4f 34835:14c87708f432
       
     1 Setup:
       
     2   $ cat > eval.py <<EOF
       
     3   > from __future__ import absolute_import
       
     4   > import filecmp
       
     5   > from mercurial import commands, context, registrar
       
     6   > cmdtable = {}
       
     7   > command = registrar.command(cmdtable)
       
     8   > @command(b'eval', [], 'hg eval CMD')
       
     9   > def eval_(ui, repo, *cmds, **opts):
       
    10   >     cmd = " ".join(cmds)
       
    11   >     res = str(eval(cmd, globals(), locals()))
       
    12   >     ui.warn("%s" % res)
       
    13   > EOF
       
    14 
       
    15   $ echo "[extensions]" >> $HGRCPATH
       
    16   $ echo "eval=`pwd`/eval.py" >> $HGRCPATH
       
    17 
       
    18 Arbitraryfilectx.cmp does not follow symlinks:
       
    19   $ mkdir case1
       
    20   $ cd case1
       
    21   $ hg init
       
    22   $ printf "A" > real_A
       
    23   $ printf "foo" > A
       
    24   $ printf "foo" > B
       
    25   $ ln -s A sym_A
       
    26   $ hg add .
       
    27   adding A
       
    28   adding B
       
    29   adding real_A
       
    30   adding sym_A
       
    31   $ hg commit -m "base"
       
    32 
       
    33 These files are different and should return True (different):
       
    34 (Note that filecmp.cmp's return semantics are inverted from ours, so we invert
       
    35 for simplicity):
       
    36   $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['real_A'])"
       
    37   True (no-eol)
       
    38   $ hg eval "not filecmp.cmp('A', 'real_A')"
       
    39   True (no-eol)
       
    40 
       
    41 These files are identical and should return False (same):
       
    42   $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['A'])"
       
    43   False (no-eol)
       
    44   $ hg eval "context.arbitraryfilectx('A', repo).cmp(repo[None]['B'])"
       
    45   False (no-eol)
       
    46   $ hg eval "not filecmp.cmp('A', 'B')"
       
    47   False (no-eol)
       
    48 
       
    49 This comparison should also return False, since A and sym_A are substantially
       
    50 the same in the eyes of ``filectx.cmp``, which looks at data only.
       
    51   $ hg eval "context.arbitraryfilectx('real_A', repo).cmp(repo[None]['sym_A'])"
       
    52   False (no-eol)
       
    53 
       
    54 A naive use of filecmp on those two would wrongly return True, since it follows
       
    55 the symlink to "A", which has different contents.
       
    56   $ hg eval "not filecmp.cmp('real_A', 'sym_A')"
       
    57   True (no-eol)