Debian Codegraph @

tests/test-extdiff.t

raw
1 $ echo "[extensions]" >> $HGRCPATH
2 $ echo "extdiff=" >> $HGRCPATH
3
4 $ hg init a
5 $ cd a
6 $ echo a > a
7 $ echo b > b
8 $ hg add
9 adding a
10 adding b
11
12 Should diff cloned directories:
13
14 $ hg extdiff -o -r
15 Only in a: a
16 Only in a: b
17 [1]
18
19 $ cat <<EOF >> $HGRCPATH
20 > [extdiff]
21 > cmd.falabala = echo
22 > opts.falabala = diffing
23 > cmd.edspace = echo
24 > opts.edspace = "name <[email protected]>"
25 > alabalaf =
26 > [merge-tools]
27 > alabalaf.executable = echo
28 > alabalaf.diffargs = diffing
29 > EOF
30
31 $ hg falabala
32 diffing a.000000000000 a
33 [1]
34
35 $ hg help falabala
36 hg falabala [OPTION]... [FILE]...
37
38 use external program to diff repository (or selected files)
39
40 Show differences between revisions for the specified files, using the
41 following program:
42
43 'echo'
44
45 When two revision arguments are given, then changes are shown between those
46 revisions. If only one revision is specified then that revision is compared to
47 the working directory, and, when no revisions are specified, the working
48 directory files are compared to its parent.
49
50 options ([+] can be repeated):
51
52 -o --option OPT [+] pass option to comparison program
53 --from REV1 revision to diff from
54 --to REV2 revision to diff to
55 -c --change REV change made by revision
56 --per-file compare each file instead of revision snapshots
57 --confirm prompt user before each external program invocation
58 --patch compare patches for two revisions
59 -I --include PATTERN [+] include names matching the given patterns
60 -X --exclude PATTERN [+] exclude names matching the given patterns
61 -S --subrepos recurse into subrepositories
62
63 (some details hidden, use --verbose to show complete help)
64
65 $ hg ci -d '0 0' -mtest1
66
67 $ echo b >> a
68 $ hg ci -d '1 0' -mtest2
69
70 Should diff cloned files directly:
71
72 $ hg falabala --from 0 --to 1
73 diffing "*\\extdiff.*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
74 diffing */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
75 [1]
76
77 Can show diff from working copy:
78 $ echo c >> a
79 $ hg falabala --to 1
80 diffing "*\\extdiff.*\\a" "a.34eed99112ab\\a" (glob) (windows !)
81 diffing */extdiff.*/a a.34eed99112ab/a (glob) (no-windows !)
82 [1]
83 $ hg revert a
84 $ rm a.orig
85
86 Specifying an empty revision should abort.
87
88 $ hg extdiff -p diff --patch --rev 'ancestor()' --rev 1
89 abort: empty revision on one side of range
90 [10]
91
92 Test diff during merge:
93
94 $ hg update -C 0
95 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
96 $ echo c >> c
97 $ hg add c
98 $ hg ci -m "new branch" -d '1 0'
99 created new head
100 $ hg merge 1
101 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
102 (branch merge, don't forget to commit)
103
104 Should diff cloned file against wc file:
105
106 $ hg falabala
107 diffing "*\\extdiff.*\\a.2a13a4d2da36\\a" "*\\a\\a" (glob) (windows !)
108 diffing */extdiff.*/a.2a13a4d2da36/a */a/a (glob) (no-windows !)
109 [1]
110
111
112 Test --change option:
113
114 $ hg ci -d '2 0' -mtest3
115
116 $ hg falabala -c 1
117 diffing "*\\extdiff.*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
118 diffing */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
119 [1]
120
121 Check diff are made from the first parent:
122
123 $ hg falabala -c 3 || echo "diff-like tools yield a non-zero exit code"
124 diffing "*\\extdiff.*\\a.2a13a4d2da36\\a" "a.46c0e4daeb72\\a" (glob) (windows !)
125 diffing */extdiff.*/a.2a13a4d2da36/a a.46c0e4daeb72/a (glob) (no-windows !)
126 diff-like tools yield a non-zero exit code
127
128 issue3153: ensure using extdiff with removed subrepos doesn't crash:
129
130 $ hg init suba
131 $ cd suba
132 $ echo suba > suba
133 $ hg add
134 adding suba
135 $ hg ci -m "adding suba file"
136 $ cd ..
137 $ echo suba=suba > .hgsub
138 $ hg add
139 adding .hgsub
140 $ hg ci -Sm "adding subrepo"
141 $ echo > .hgsub
142 $ hg ci -m "removing subrepo"
143 $ hg falabala --from 4 --to 5 -S
144 diffing a.398e36faf9c6 a.5ab95fb166c4
145 [1]
146
147 Test --per-file option:
148
149 $ hg up -q -C 3
150 $ echo a2 > a
151 $ echo b2 > b
152 $ hg ci -d '3 0' -mtestmode1
153 created new head
154 $ hg falabala -c 6 --per-file
155 diffing "*\\extdiff.*\\a.46c0e4daeb72\\a" "a.81906f2b98ac\\a" (glob) (windows !)
156 diffing */extdiff.*/a.46c0e4daeb72/a a.81906f2b98ac/a (glob) (no-windows !)
157 diffing "*\\extdiff.*\\a.46c0e4daeb72\\b" "a.81906f2b98ac\\b" (glob) (windows !)
158 diffing */extdiff.*/a.46c0e4daeb72/b a.81906f2b98ac/b (glob) (no-windows !)
159 [1]
160
161 #if no-gui
162 Test gui tool error:
163
164 $ hg --config extdiff.gui.alabalaf=True alabalaf
165 abort: tool 'alabalaf' requires a GUI
166 (to override, use: --config diff-tools.alabalaf.gui=False)
167 [255]
168 #endif
169
170 #if gui
171 Test --per-file option for gui tool:
172
173 $ DISPLAY=fake hg --config extdiff.gui.alabalaf=True alabalaf -c 6 --per-file --debug
174 diffing */extdiff.*/a.46c0e4daeb72/* a.81906f2b98ac/* (glob)
175 diffing */extdiff.*/a.46c0e4daeb72/* a.81906f2b98ac/* (glob)
176 making snapshot of 2 files from rev 46c0e4daeb72
177 a
178 b
179 making snapshot of 2 files from rev 81906f2b98ac
180 a
181 b
182 running '* diffing * *' in * (backgrounded) (glob)
183 running '* diffing * *' in * (backgrounded) (glob)
184 cleaning up temp directory
185 [1]
186
187 Test --per-file option for gui tool again:
188
189 $ DISPLAY=fake hg --config merge-tools.alabalaf.gui=True alabalaf -c 6 --per-file --debug
190 diffing */extdiff.*/a.46c0e4daeb72/* a.81906f2b98ac/* (glob)
191 diffing */extdiff.*/a.46c0e4daeb72/* a.81906f2b98ac/* (glob)
192 making snapshot of 2 files from rev 46c0e4daeb72
193 a
194 b
195 making snapshot of 2 files from rev 81906f2b98ac
196 a
197 b
198 running '* diffing * *' in * (backgrounded) (glob)
199 running '* diffing * *' in * (backgrounded) (glob)
200 cleaning up temp directory
201 [1]
202 #endif
203
204 Test --per-file and --confirm options:
205
206 $ hg --config ui.interactive=True falabala -c 6 --per-file --confirm <<EOF
207 > n
208 > y
209 > EOF
210 diff a (1 of 2) [Yns?] n
211 diff b (2 of 2) [Yns?] y
212 diffing "*\\extdiff.*\\a.46c0e4daeb72\\b" "a.81906f2b98ac\\b" (glob) (windows !)
213 diffing */extdiff.*/a.46c0e4daeb72/b a.81906f2b98ac/b (glob) (no-windows !)
214 [1]
215
216 Test --per-file and --confirm options with skipping:
217
218 $ hg --config ui.interactive=True falabala -c 6 --per-file --confirm <<EOF
219 > s
220 > EOF
221 diff a (1 of 2) [Yns?] s
222 [1]
223
224 issue4463: usage of command line configuration without additional quoting
225
226 $ cat <<EOF >> $HGRCPATH
227 > [extdiff]
228 > cmd.4463a = echo
229 > opts.4463a = a-naked 'single quoted' "double quoted"
230 > 4463b = echo b-naked 'single quoted' "double quoted"
231 > echo =
232 > EOF
233 $ hg update -q -C 0
234 $ echo a >> a
235
236 $ hg --debug 4463a | grep '^running'
237 running 'echo a-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
238 running 'echo a-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
239 $ hg --debug 4463b | grep '^running'
240 running 'echo b-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
241 running 'echo b-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
242 $ hg --debug echo | grep '^running'
243 running '*echo* "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
244 running '*echo */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
245
246 (getting options from other than extdiff section)
247
248 $ cat <<EOF >> $HGRCPATH
249 > [extdiff]
250 > # using diff-tools diffargs
251 > 4463b2 = echo
252 > # using merge-tools diffargs
253 > 4463b3 = echo
254 > # no diffargs
255 > 4463b4 = echo
256 > [diff-tools]
257 > 4463b2.diffargs = b2-naked 'single quoted' "double quoted"
258 > [merge-tools]
259 > 4463b3.diffargs = b3-naked 'single quoted' "double quoted"
260 > EOF
261
262 $ hg --debug 4463b2 | grep '^running'
263 running 'echo b2-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
264 running 'echo b2-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
265 $ hg --debug 4463b3 | grep '^running'
266 running 'echo b3-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
267 running 'echo b3-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
268 $ hg --debug 4463b4 | grep '^running'
269 running 'echo "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
270 running 'echo */a $TESTTMP/a/a' in */extdiff.* (glob) (no-windows !)
271 $ hg --debug 4463b4 --option b4-naked --option 'being quoted' | grep '^running'
272 running 'echo b4-naked "being quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
273 running "echo b4-naked 'being quoted' */a $TESTTMP/a/a" in */extdiff.* (glob) (no-windows !)
274 $ hg --debug extdiff -p echo --option echo-naked --option 'being quoted' | grep '^running'
275 running 'echo echo-naked "being quoted" "*\\a" "*\\a"' in */extdiff.* (glob) (windows !)
276 running "echo echo-naked 'being quoted' */a $TESTTMP/a/a" in */extdiff.* (glob) (no-windows !)
277
278 $ touch 'sp ace'
279 $ hg add 'sp ace'
280 $ hg ci -m 'sp ace'
281 created new head
282 $ echo > 'sp ace'
283
284 Test pre-72a89cf86fcd backward compatibility with half-baked manual quoting
285
286 $ cat <<EOF >> $HGRCPATH
287 > [extdiff]
288 > odd =
289 > [merge-tools]
290 > odd.diffargs = --foo='\$clabel' '\$clabel' "--bar=\$clabel" "\$clabel"
291 > odd.executable = echo
292 > EOF
293
294 $ hg --debug odd | grep '^running'
295 running '"*\\echo.exe" --foo="sp ace" "sp ace" --bar="sp ace" "sp ace"' in * (glob) (windows !)
296 running "*/echo --foo='sp ace' 'sp ace' --bar='sp ace' 'sp ace'" in * (glob) (no-windows !)
297
298 Empty argument must be quoted
299
300 $ cat <<EOF >> $HGRCPATH
301 > [extdiff]
302 > kdiff3 = echo
303 > [merge-tools]
304 > kdiff3.diffargs=--L1 \$plabel1 --L2 \$clabel \$parent \$child
305 > EOF
306
307 $ hg --debug kdiff3 --from 0 | grep '^running'
308 running 'echo --L1 "@0" --L2 "" a.8a5febb7f867 a' in * (glob) (windows !)
309 running "echo --L1 '@0' --L2 '' a.8a5febb7f867 a" in * (glob) (no-windows !)
310
311
312 Test extdiff of multiple files in tmp dir:
313
314 $ hg update -C 0 > /dev/null
315 $ echo changed > a
316 $ echo changed > b
317 #if execbit
318 $ chmod +x b
319 #endif
320
321 Diff in working directory, before:
322
323 $ hg diff --git
324 diff --git a/a b/a
325 --- a/a
326 +++ b/a
327 @@ -1,1 +1,1 @@
328 -a
329 +changed
330 diff --git a/b b/b
331 old mode 100644 (execbit !)
332 new mode 100755 (execbit !)
333 --- a/b
334 +++ b/b
335 @@ -1,1 +1,1 @@
336 -b
337 +changed
338
339
340 Edit with extdiff -p:
341
342 Prepare custom diff/edit tool:
343
344 $ cat > 'diff tool.py' << EOT
345 > #!$PYTHON
346 > import time
347 > time.sleep(1) # avoid unchanged-timestamp problems
348 > open('a/a', 'ab').write(b'edited\n')
349 > open('a/b', 'ab').write(b'edited\n')
350 > EOT
351
352 #if execbit
353 $ chmod +x 'diff tool.py'
354 #endif
355
356 will change to /tmp/extdiff.TMP and populate directories a.TMP and a
357 and start tool
358
359 #if windows
360 $ cat > 'diff tool.bat' << EOF
361 > @"$PYTHON" "`pwd`/diff tool.py"
362 > EOF
363 $ hg extdiff -p "`pwd`/diff tool.bat"
364 [1]
365 #else
366 $ hg extdiff -p "`pwd`/diff tool.py"
367 [1]
368 #endif
369
370 Diff in working directory, after:
371
372 $ hg diff --git
373 diff --git a/a b/a
374 --- a/a
375 +++ b/a
376 @@ -1,1 +1,2 @@
377 -a
378 +changed
379 +edited
380 diff --git a/b b/b
381 old mode 100644 (execbit !)
382 new mode 100755 (execbit !)
383 --- a/b
384 +++ b/b
385 @@ -1,1 +1,2 @@
386 -b
387 +changed
388 +edited
389
390 Test extdiff with --option:
391
392 $ hg extdiff -p echo -o this -c 1
393 this "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
394 this */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
395 [1]
396
397 $ hg falabala -o this -c 1
398 diffing this "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
399 diffing this */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
400 [1]
401
402 Test extdiff's handling of options with spaces in them:
403
404 $ hg edspace -c 1
405 "name <[email protected]>" "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
406 name <[email protected]> */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
407 [1]
408
409 $ hg extdiff -p echo -o "name <[email protected]>" -c 1
410 "name <[email protected]>" "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
411 name <[email protected]> */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
412 [1]
413
414 Test with revsets:
415
416 $ hg extdif -p echo -c "rev(1)"
417 "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
418 */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
419 [1]
420
421 $ hg extdif -p echo -r "0::1"
422 "*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
423 */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
424 [1]
425
426 Fallback to merge-tools.tool.executable|regkey
427 $ mkdir dir
428 $ cat > 'dir/tool.sh' << 'EOF'
429 > #!/bin/sh
430 > # Mimic a tool that syncs all attrs, including mtime
431 > cp $1/a $2/a
432 > touch -r $1/a $2/a
433 > chmod +x $2/a
434 > echo "** custom diff **"
435 > EOF
436 #if execbit
437 $ chmod +x dir/tool.sh
438 #endif
439
440 Windows can't run *.sh directly, so create a shim executable that can be.
441 Without something executable, the next hg command will try to run `tl` instead
442 of $tool (and fail).
443 #if windows
444 $ cat > dir/tool.bat <<EOF
445 > @sh -c "`pwd`/dir/tool.sh %1 %2"
446 > EOF
447 $ tool=`pwd`/dir/tool.bat
448 #else
449 $ tool=`pwd`/dir/tool.sh
450 #endif
451
452 $ cat a
453 changed
454 edited
455 $ hg --debug tl --config extdiff.tl= --config merge-tools.tl.executable=$tool
456 making snapshot of 2 files from rev * (glob)
457 a
458 b
459 making snapshot of 2 files from working directory
460 a
461 b
462 running '$TESTTMP/a/dir/tool.bat a.* a' in */extdiff.* (glob) (windows !)
463 running '$TESTTMP/a/dir/tool.sh a.* a' in */extdiff.* (glob) (no-windows !)
464 ** custom diff **
465 file changed while diffing. Overwriting: $TESTTMP/a/a (src: */extdiff.*/a/a) (glob)
466 cleaning up temp directory
467 [1]
468 $ cat a
469 a
470
471 #if execbit
472 $ [ -x a ]
473
474 $ cat > 'dir/tool.sh' << 'EOF'
475 > #!/bin/sh
476 > chmod -x $2/a
477 > echo "** custom diff **"
478 > EOF
479
480 $ hg --debug tl --config extdiff.tl= --config merge-tools.tl.executable=$tool
481 making snapshot of 2 files from rev * (glob)
482 a
483 b
484 making snapshot of 2 files from working directory
485 a
486 b
487 running '$TESTTMP/a/dir/tool.sh a.* a' in */extdiff.* (glob)
488 ** custom diff **
489 file changed while diffing. Overwriting: $TESTTMP/a/a (src: */extdiff.*/a/a) (glob)
490 cleaning up temp directory
491 [1]
492
493 $ [ -x a ]
494 [1]
495 #endif
496
497 $ cd ..
498
499 #if symlink
500
501 Test symlinks handling (issue1909)
502
503 $ hg init testsymlinks
504 $ cd testsymlinks
505 $ echo a > a
506 $ hg ci -Am adda
507 adding a
508 $ echo a >> a
509 $ ln -s missing linka
510 $ hg add linka
511 $ hg falabala --from 0 --traceback
512 diffing testsymlinks.07f494440405 testsymlinks
513 [1]
514 $ cd ..
515
516 #endif
517
518 Test handling of non-ASCII paths in generated docstrings (issue5301)
519
520 >>> with open("u", "wb") as f:
521 ... n = f.write(b"\xa5\xa5")
522 $ U=`cat u`
523
524 $ HGPLAIN=1 hg --config hgext.extdiff= --config extdiff.cmd.td=hi help -k xyzzy
525 abort: no matches
526 (try 'hg help' for a list of topics)
527 [10]
528
529 $ HGPLAIN=1 hg --config hgext.extdiff= --config extdiff.cmd.td=hi help td > /dev/null
530
531 $ LC_MESSAGES=ja_JP.UTF-8 hg --config hgext.extdiff= --config extdiff.cmd.td=$U help -k xyzzy
532 abort: no matches
533 (try 'hg help' for a list of topics)
534 [10]
535
536 $ LC_MESSAGES=ja_JP.UTF-8 hg --config hgext.extdiff= --config extdiff.cmd.td=$U help td \
537 > | grep "^ '"
538 '\xa5\xa5'
539
540 $ cd $TESTTMP
541
542 Test that diffing a single file works, even if that file is new
543
544 $ hg init testsinglefile
545 $ cd testsinglefile
546 $ echo a > a
547 $ hg add a
548 $ hg falabala
549 diffing nul "*\\a" (glob) (windows !)
550 diffing /dev/null */a (glob) (no-windows !)
551 [1]
552 $ hg ci -qm a
553 $ hg falabala -c .
554 diffing nul "*\\a" (glob) (windows !)
555 diffing /dev/null */a (glob) (no-windows !)
556 [1]
557 $ echo a >> a
558 $ hg falabala
559 diffing "*\\a" "*\\a" (glob) (windows !)
560 diffing */a */a (glob) (no-windows !)
561 [1]
562 $ hg ci -qm 2a
563 $ hg falabala -c .
564 diffing "*\\a" "*\\a" (glob) (windows !)
565 diffing */a */a (glob) (no-windows !)
566 [1]