Debian Codegraph @

tests/test-fix-metadata.t

raw
1 A python hook for "hg fix" that prints out the number of files and revisions
2 that were affected, along with which fixer tools were applied. Also checks how
3 many times it sees a specific key generated by one of the fixer tools defined
4 below.
5
6 $ cat >> $TESTTMP/postfixhook.py <<EOF
7 > import collections
8 > def file(ui, repo, rev=None, path=b'', metadata=None, **kwargs):
9 > ui.status(b'fixed %s in revision %d using %s\n' %
10 > (path, rev, b', '.join(metadata.keys())))
11 > def summarize(ui, repo, replacements=None, wdirwritten=False,
12 > metadata=None, **kwargs):
13 > counts = collections.defaultdict(int)
14 > keys = 0
15 > for fixername, metadatalist in metadata.items():
16 > for metadata in metadatalist:
17 > if metadata is None:
18 > continue
19 > counts[fixername] += 1
20 > if 'key' in metadata:
21 > keys += 1
22 > ui.status(b'saw "key" %d times\n' % (keys,))
23 > for name, count in sorted(counts.items()):
24 > ui.status(b'fixed %d files with %s\n' % (count, name))
25 > if replacements:
26 > ui.status(b'fixed %d revisions\n' % (len(replacements),))
27 > if wdirwritten:
28 > ui.status(b'fixed the working copy\n')
29 > EOF
30
31 Some mock output for fixer tools that demonstrate what could go wrong with
32 expecting the metadata output format.
33
34 $ printf 'new content\n' > $TESTTMP/missing
35 $ printf 'not valid json\0new content\n' > $TESTTMP/invalid
36 $ printf '{"key": "value"}\0new content\n' > $TESTTMP/valid
37
38 Configure some fixer tools based on the output defined above, and enable the
39 hooks defined above. Disable parallelism to make output of the parallel file
40 processing phase stable.
41
42 $ cat >> $HGRCPATH <<EOF
43 > [extensions]
44 > fix =
45 > [fix]
46 > metadatafalse:command=cat $TESTTMP/missing
47 > metadatafalse:pattern=metadatafalse
48 > metadatafalse:metadata=false
49 > missing:command=cat $TESTTMP/missing
50 > missing:pattern=missing
51 > missing:metadata=true
52 > invalid:command=cat $TESTTMP/invalid
53 > invalid:pattern=invalid
54 > invalid:metadata=true
55 > valid:command=cat $TESTTMP/valid
56 > valid:pattern=valid
57 > valid:metadata=true
58 > [hooks]
59 > postfixfile = python:$TESTTMP/postfixhook.py:file
60 > postfix = python:$TESTTMP/postfixhook.py:summarize
61 > [worker]
62 > enabled=false
63 > EOF
64
65 See what happens when we execute each of the fixer tools. Some print warnings,
66 some write back to the file.
67
68 $ hg init repo
69 $ cd repo
70
71 $ printf "old content\n" > metadatafalse
72 $ printf "old content\n" > invalid
73 $ printf "old content\n" > missing
74 $ printf "old content\n" > valid
75 $ hg add -q
76
77 $ hg fix -w
78 ignored invalid output from fixer tool: invalid
79 fixed metadatafalse in revision 2147483647 using metadatafalse
80 ignored invalid output from fixer tool: missing
81 fixed valid in revision 2147483647 using valid
82 saw "key" 1 times
83 fixed 1 files with valid
84 fixed the working copy
85
86 $ cat metadatafalse
87 new content
88 $ cat missing
89 old content
90 $ cat invalid
91 old content
92 $ cat valid
93 new content
94
95 $ cd ..