Debian Codegraph @

tests/test-export.t

raw
1 $ hg init repo
2 $ cd repo
3 $ touch foo
4 $ hg add foo
5 $ for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
6 > echo "foo-$i" >> foo
7 > hg ci -m "foo-$i"
8 > done
9
10 $ for out in "%nof%N" "%%%H" "%b-%R" "%h" "%r" "%m"; do
11 > echo
12 > echo "# foo-$out.patch"
13 > hg export -v -o "foo-$out.patch" 2:tip
14 > done
15
16 # foo-%nof%N.patch
17 exporting patches:
18 foo-01of10.patch
19 foo-02of10.patch
20 foo-03of10.patch
21 foo-04of10.patch
22 foo-05of10.patch
23 foo-06of10.patch
24 foo-07of10.patch
25 foo-08of10.patch
26 foo-09of10.patch
27 foo-10of10.patch
28
29 # foo-%%%H.patch
30 exporting patches:
31 foo-%617188a1c80f869a7b66c85134da88a6fb145f67.patch
32 foo-%dd41a5ff707a5225204105611ba49cc5c229d55f.patch
33 foo-%f95a5410f8664b6e1490a4af654e4b7d41a7b321.patch
34 foo-%4346bcfde53b4d9042489078bcfa9c3e28201db2.patch
35 foo-%afda8c3a009cc99449a05ad8aa4655648c4ecd34.patch
36 foo-%35284ce2b6b99c9d2ac66268fe99e68e1974e1aa.patch
37 foo-%9688c41894e6931305fa7165a37f6568050b4e9b.patch
38 foo-%747d3c68f8ec44bb35816bfcd59aeb50b9654c2f.patch
39 foo-%5f17a83f5fbd9414006a5e563eab4c8a00729efd.patch
40 foo-%f3acbafac161ec68f1598af38f794f28847ca5d3.patch
41
42 # foo-%b-%R.patch
43 exporting patches:
44 foo-repo-2.patch
45 foo-repo-3.patch
46 foo-repo-4.patch
47 foo-repo-5.patch
48 foo-repo-6.patch
49 foo-repo-7.patch
50 foo-repo-8.patch
51 foo-repo-9.patch
52 foo-repo-10.patch
53 foo-repo-11.patch
54
55 # foo-%h.patch
56 exporting patches:
57 foo-617188a1c80f.patch
58 foo-dd41a5ff707a.patch
59 foo-f95a5410f866.patch
60 foo-4346bcfde53b.patch
61 foo-afda8c3a009c.patch
62 foo-35284ce2b6b9.patch
63 foo-9688c41894e6.patch
64 foo-747d3c68f8ec.patch
65 foo-5f17a83f5fbd.patch
66 foo-f3acbafac161.patch
67
68 # foo-%r.patch
69 exporting patches:
70 foo-02.patch
71 foo-03.patch
72 foo-04.patch
73 foo-05.patch
74 foo-06.patch
75 foo-07.patch
76 foo-08.patch
77 foo-09.patch
78 foo-10.patch
79 foo-11.patch
80
81 # foo-%m.patch
82 exporting patches:
83 foo-foo_2.patch
84 foo-foo_3.patch
85 foo-foo_4.patch
86 foo-foo_5.patch
87 foo-foo_6.patch
88 foo-foo_7.patch
89 foo-foo_8.patch
90 foo-foo_9.patch
91 foo-foo_10.patch
92 foo-foo_11.patch
93
94 Doing it again clobbers the files rather than appending:
95 $ hg export -v -o "foo-%m.patch" 2:3
96 exporting patches:
97 foo-foo_2.patch
98 foo-foo_3.patch
99 $ grep HG foo-foo_2.patch | wc -l
100 \s*1 (re)
101 $ grep HG foo-foo_3.patch | wc -l
102 \s*1 (re)
103
104 Using bookmarks:
105
106 $ hg book -f -r 9 @
107 $ hg book -f -r 11 test
108 $ hg export -B test
109 # HG changeset patch
110 # User test
111 # Date 0 0
112 # Thu Jan 01 00:00:00 1970 +0000
113 # Node ID 5f17a83f5fbd9414006a5e563eab4c8a00729efd
114 # Parent 747d3c68f8ec44bb35816bfcd59aeb50b9654c2f
115 foo-10
116
117 diff -r 747d3c68f8ec -r 5f17a83f5fbd foo
118 --- a/foo Thu Jan 01 00:00:00 1970 +0000
119 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
120 @@ -8,3 +8,4 @@
121 foo-7
122 foo-8
123 foo-9
124 +foo-10
125 # HG changeset patch
126 # User test
127 # Date 0 0
128 # Thu Jan 01 00:00:00 1970 +0000
129 # Node ID f3acbafac161ec68f1598af38f794f28847ca5d3
130 # Parent 5f17a83f5fbd9414006a5e563eab4c8a00729efd
131 foo-11
132
133 diff -r 5f17a83f5fbd -r f3acbafac161 foo
134 --- a/foo Thu Jan 01 00:00:00 1970 +0000
135 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
136 @@ -9,3 +9,4 @@
137 foo-8
138 foo-9
139 foo-10
140 +foo-11
141
142 Exporting 4 changesets to a file:
143
144 $ hg export -o export_internal 1 2 3 4
145 $ grep HG export_internal | wc -l
146 \s*4 (re)
147
148 Doing it again clobbers the file rather than appending:
149 $ hg export -o export_internal 1 2 3 4
150 $ grep HG export_internal | wc -l
151 \s*4 (re)
152
153 Exporting 4 changesets to stdout:
154
155 $ hg export 1 2 3 4 | grep HG | wc -l
156 \s*4 (re)
157
158 Exporting revision -2 to a file:
159
160 $ hg export -- -2
161 # HG changeset patch
162 # User test
163 # Date 0 0
164 # Thu Jan 01 00:00:00 1970 +0000
165 # Node ID 5f17a83f5fbd9414006a5e563eab4c8a00729efd
166 # Parent 747d3c68f8ec44bb35816bfcd59aeb50b9654c2f
167 foo-10
168
169 diff -r 747d3c68f8ec -r 5f17a83f5fbd foo
170 --- a/foo Thu Jan 01 00:00:00 1970 +0000
171 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
172 @@ -8,3 +8,4 @@
173 foo-7
174 foo-8
175 foo-9
176 +foo-10
177
178 Exporting wdir revision:
179
180 $ echo "foo-wdir" >> foo
181 $ hg export 'wdir()'
182 # HG changeset patch
183 # User test
184 # Date 0 0
185 # Thu Jan 01 00:00:00 1970 +0000
186 # Node ID ffffffffffffffffffffffffffffffffffffffff
187 # Parent f3acbafac161ec68f1598af38f794f28847ca5d3
188
189
190 diff -r f3acbafac161 foo
191 --- a/foo Thu Jan 01 00:00:00 1970 +0000
192 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
193 @@ -10,3 +10,4 @@
194 foo-9
195 foo-10
196 foo-11
197 +foo-wdir
198 $ hg revert -q foo
199
200 Templated output to stdout:
201
202 $ hg export -Tjson 0
203 [
204 {
205 "branch": "default",
206 "date": [0, 0],
207 "desc": "foo-0",
208 "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n",
209 "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
210 "parents": [],
211 "user": "test"
212 }
213 ]
214
215 Templated output to single file:
216
217 $ hg export -Tjson 0:1 -o out.json
218 $ cat out.json
219 [
220 {
221 "branch": "default",
222 "date": [0, 0],
223 "desc": "foo-0",
224 "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n",
225 "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
226 "parents": [],
227 "user": "test"
228 },
229 {
230 "branch": "default",
231 "date": [0, 0],
232 "desc": "foo-1",
233 "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n",
234 "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266",
235 "parents": ["871558de6af2e8c244222f8eea69b782c94ce3df"],
236 "user": "test"
237 }
238 ]
239
240 Templated output to multiple files:
241
242 $ hg export -Tjson 0:1 -o 'out-{rev}.json'
243 $ cat out-0.json
244 [
245 {
246 "branch": "default",
247 "date": [0, 0],
248 "desc": "foo-0",
249 "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n",
250 "node": "871558de6af2e8c244222f8eea69b782c94ce3df",
251 "parents": [],
252 "user": "test"
253 }
254 ]
255 $ cat out-1.json
256 [
257 {
258 "branch": "default",
259 "date": [0, 0],
260 "desc": "foo-1",
261 "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n",
262 "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266",
263 "parents": ["871558de6af2e8c244222f8eea69b782c94ce3df"],
264 "user": "test"
265 }
266 ]
267
268 Template keywrods:
269
270 $ hg export 0 -T '# {node|shortest}\n\n{diff}'
271 # 8715
272
273 diff -r 000000000000 -r 871558de6af2 foo
274 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
275 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
276 @@ -0,0 +1,1 @@
277 +foo-0
278
279 No filename should be printed if stdout is specified explicitly:
280
281 $ hg export -v 1 -o -
282 exporting patch:
283 # HG changeset patch
284 # User test
285 # Date 0 0
286 # Thu Jan 01 00:00:00 1970 +0000
287 # Node ID d1c9656e973cfb5aebd5499bbd2cb350e3b12266
288 # Parent 871558de6af2e8c244222f8eea69b782c94ce3df
289 foo-1
290
291 diff -r 871558de6af2 -r d1c9656e973c foo
292 --- a/foo Thu Jan 01 00:00:00 1970 +0000
293 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
294 @@ -1,1 +1,2 @@
295 foo-0
296 +foo-1
297
298 Checking if only alphanumeric characters are used in the file name (%m option):
299
300 $ echo "line" >> foo
301 $ hg commit -m " !\"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"'^'"_\`abcdefghijklmnopqrstuvwxyz{|}~"
302 $ hg export -v -o %m.patch tip
303 exporting patch:
304 ___________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz____.patch
305
306 Template fragments in file name:
307
308 $ hg export -v -o '{node|shortest}.patch' tip
309 exporting patch:
310 197e.patch
311
312 Backslash should be preserved because it is a directory separator on Windows:
313
314 $ mkdir out
315 $ hg export -v -o 'out\{node|shortest}.patch' tip
316 exporting patch:
317 out\197e.patch
318
319 Still backslash is taken as an escape character in inner template strings:
320
321 $ hg export -v -o '{"out\{foo}.patch"}' tip
322 exporting patch:
323 out{foo}.patch
324
325 Invalid pattern in file name:
326
327 $ hg export -o '%x.patch' tip
328 abort: invalid format spec '%x' in output filename
329 [255]
330 $ hg export -o '%' tip
331 abort: incomplete format spec in output filename
332 [255]
333 $ hg export -o '%{"foo"}' tip
334 abort: incomplete format spec in output filename
335 [255]
336 $ hg export -o '%m{' tip
337 hg: parse error at 3: unterminated template expansion
338 (%m{
339 ^ here)
340 [10]
341 $ hg export -o '%\' tip
342 abort: invalid format spec '%\' in output filename
343 [255]
344 $ hg export -o '\%' tip
345 abort: incomplete format spec in output filename
346 [255]
347
348 Catch exporting unknown revisions (especially empty revsets, see issue3353)
349
350 $ hg export
351 # HG changeset patch
352 # User test
353 # Date 0 0
354 # Thu Jan 01 00:00:00 1970 +0000
355 # Node ID 197ecd81a57f760b54f34a58817ad5b04991fa47
356 # Parent f3acbafac161ec68f1598af38f794f28847ca5d3
357 !"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
358
359 diff -r f3acbafac161 -r 197ecd81a57f foo
360 --- a/foo Thu Jan 01 00:00:00 1970 +0000
361 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
362 @@ -10,3 +10,4 @@
363 foo-9
364 foo-10
365 foo-11
366 +line
367
368 $ hg export ""
369 hg: parse error: empty query
370 [10]
371 $ hg export 999
372 abort: unknown revision '999'
373 [10]
374 $ hg export "not all()"
375 abort: export requires at least one changeset
376 [10]
377
378 Check for color output
379 $ cat <<EOF >> $HGRCPATH
380 > [color]
381 > mode = ansi
382 > [extensions]
383 > color =
384 > EOF
385
386 $ hg export --color always --nodates tip
387 # HG changeset patch
388 # User test
389 # Date 0 0
390 # Thu Jan 01 00:00:00 1970 +0000
391 # Node ID * (glob)
392 # Parent * (glob)
393 !"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
394
395 \x1b[0;1mdiff -r f3acbafac161 -r 197ecd81a57f foo\x1b[0m (esc)
396 \x1b[0;31;1m--- a/foo\x1b[0m (esc)
397 \x1b[0;32;1m+++ b/foo\x1b[0m (esc)
398 \x1b[0;35m@@ -10,3 +10,4 @@\x1b[0m (esc)
399 foo-9
400 foo-10
401 foo-11
402 \x1b[0;32m+line\x1b[0m (esc)
403
404
405 $ cd ..