Debian Codegraph @

tests/test-cat.t

raw
1 $ hg init repo
2 $ cd repo
3 $ echo 0 > a
4 $ echo 0 > b
5 $ hg ci -A -m m
6 adding a
7 adding b
8 $ hg rm a
9 $ hg cat a
10 0
11 $ hg cat --decode a # more tests in test-encode
12 0
13 $ echo 1 > b
14 $ hg ci -m m
15 $ echo 2 > b
16 $ hg cat -r 0 a
17 0
18 $ hg cat -r 0 b
19 0
20 $ hg cat -r 1 a
21 a: no such file in rev 7040230c159c
22 [1]
23 $ hg cat -r 1 b
24 1
25
26 Test multiple files
27
28 $ echo 3 > c
29 $ hg ci -Am addmore c
30 $ hg cat b c
31 1
32 3
33 $ hg cat .
34 1
35 3
36 $ hg cat . c
37 1
38 3
39
40 Test fileset
41
42 $ hg cat 'set:not(b) or a'
43 3
44 $ hg cat 'set:c or b'
45 1
46 3
47
48 $ mkdir tmp
49 $ hg cat --output tmp/HH_%H c
50 $ hg cat --output tmp/RR_%R c
51 $ hg cat --output tmp/h_%h c
52 $ hg cat --output tmp/r_%r c
53 $ hg cat --output tmp/%s_s c
54 $ hg cat --output tmp/%d%%_d c
55 $ hg cat --output tmp/%p_p c
56 $ hg log -r . --template "{rev}: {node|short}\n"
57 2: 45116003780e
58 $ find tmp -type f | sort
59 tmp/.%_d
60 tmp/HH_45116003780e3678b333fb2c99fa7d559c8457e9
61 tmp/RR_2
62 tmp/c_p
63 tmp/c_s
64 tmp/h_45116003780e
65 tmp/r_2
66
67 Test template output
68
69 $ hg --cwd tmp cat ../b ../c -T '== {path|relpath} ({path}) r{rev} ==\n{data}'
70 == ../b (b) r2 ==
71 1
72 == ../c (c) r2 ==
73 3
74
75 $ hg cat b c -Tjson --output -
76 [
77 {
78 "data": "1\n",
79 "path": "b"
80 },
81 {
82 "data": "3\n",
83 "path": "c"
84 }
85 ]
86
87 $ hg cat b c -Tjson --output 'tmp/%p.json'
88 $ cat tmp/b.json
89 [
90 {
91 "data": "1\n",
92 "path": "b"
93 }
94 ]
95 $ cat tmp/c.json
96 [
97 {
98 "data": "3\n",
99 "path": "c"
100 }
101 ]
102
103 Test working directory
104
105 $ echo b-wdir > b
106 $ hg cat -r 'wdir()' b
107 b-wdir
108
109 Environment variables are not visible by default
110
111 $ PATTERN='t4' hg log -r '.' -T "{ifcontains('PATTERN', envvars, 'yes', 'no')}\n"
112 no
113
114 Environment variable visibility can be explicit
115
116 $ PATTERN='t4' hg log -r '.' -T "{envvars % '{key} -> {value}\n'}" \
117 > --config "experimental.exportableenviron=PATTERN"
118 PATTERN -> t4
119
120 Test behavior of output when directory structure does not already exist
121
122 $ mkdir foo
123 $ echo a > foo/a
124 $ hg add foo/a
125 $ hg commit -qm "add foo/a"
126 $ hg cat --output "output/%p" foo/a
127 $ cat output/foo/a
128 a