Debian Codegraph @

tests/test-histedit-fold.t

raw
1 Test histedit extension: Fold commands
2 ======================================
3
4 This test file is dedicated to testing the fold command in non conflicting
5 case.
6
7 Initialization
8 ---------------
9
10
11 $ . "$TESTDIR/histedit-helpers.sh"
12
13 $ cat >> $HGRCPATH <<EOF
14 > [alias]
15 > logt = log --template '{rev}:{node|short} {desc|firstline}\n'
16 > [extensions]
17 > histedit=
18 > mockmakedate = $TESTDIR/mockmakedate.py
19 > EOF
20
21
22 Simple folding
23 --------------------
24 $ addwithdate ()
25 > {
26 > echo $1 > $1
27 > hg add $1
28 > hg ci -m $1 -d "$2 0"
29 > }
30
31 $ initrepo ()
32 > {
33 > hg init r
34 > cd r
35 > addwithdate a 1
36 > addwithdate b 2
37 > addwithdate c 3
38 > addwithdate d 4
39 > addwithdate e 5
40 > addwithdate f 6
41 > }
42
43 $ initrepo
44
45 log before edit
46 $ hg logt --graph
47 @ 5:178e35e0ce73 f
48 |
49 o 4:1ddb6c90f2ee e
50 |
51 o 3:532247a8969b d
52 |
53 o 2:ff2c9fa2018b c
54 |
55 o 1:97d72e5f12c7 b
56 |
57 o 0:8580ff50825a a
58
59
60 $ hg histedit ff2c9fa2018b --commands - 2>&1 <<EOF | fixbundle
61 > pick 1ddb6c90f2ee e
62 > pick 178e35e0ce73 f
63 > fold ff2c9fa2018b c
64 > pick 532247a8969b d
65 > EOF
66
67 log after edit
68 $ hg logt --graph
69 @ 4:c4d7f3def76d d
70 |
71 o 3:575228819b7e f
72 |
73 o 2:505a591af19e e
74 |
75 o 1:97d72e5f12c7 b
76 |
77 o 0:8580ff50825a a
78
79
80 post-fold manifest
81 $ hg manifest
82 a
83 b
84 c
85 d
86 e
87 f
88
89
90 check histedit_source, including that it uses the later date, from the first changeset
91
92 $ hg log --debug --rev 3
93 changeset: 3:575228819b7e6ed69e8c0a6a383ee59a80db7358
94 phase: draft
95 parent: 2:505a591af19eed18f560af827b9e03d2076773dc
96 parent: -1:0000000000000000000000000000000000000000
97 manifest: 3:81eede616954057198ead0b2c73b41d1f392829a
98 user: test
99 date: Thu Jan 01 00:00:06 1970 +0000
100 files+: c f
101 extra: branch=default
102 extra: histedit_source=7cad1d7030207872dfd1c3a7cb430f24f2884086,ff2c9fa2018b15fa74b33363bda9527323e2a99f
103 description:
104 f
105 ***
106 c
107
108
109
110 rollup will fold without preserving the folded commit's message or date
111
112 $ OLDHGEDITOR=$HGEDITOR
113 $ HGEDITOR=false
114 $ hg histedit 97d72e5f12c7 --commands - 2>&1 <<EOF | fixbundle
115 > pick 97d72e5f12c7 b
116 > roll 505a591af19e e
117 > pick 575228819b7e f
118 > pick c4d7f3def76d d
119 > EOF
120
121 $ HGEDITOR=$OLDHGEDITOR
122
123 log after edit
124 $ hg logt --graph
125 @ 3:bab801520cec d
126 |
127 o 2:58c8f2bfc151 f
128 |
129 o 1:5d939c56c72e b
130 |
131 o 0:8580ff50825a a
132
133
134 description is taken from rollup target commit
135
136 $ hg log --debug --rev 1
137 changeset: 1:5d939c56c72e77e29f5167696218e2131a40f5cf
138 phase: draft
139 parent: 0:8580ff50825a50c8f716709acdf8de0deddcd6ab
140 parent: -1:0000000000000000000000000000000000000000
141 manifest: 1:b5e112a3a8354e269b1524729f0918662d847c38
142 user: test
143 date: Thu Jan 01 00:00:02 1970 +0000
144 files+: b e
145 extra: branch=default
146 extra: histedit_source=97d72e5f12c7e84f85064aa72e5a297142c36ed9,505a591af19eed18f560af827b9e03d2076773dc
147 description:
148 b
149
150
151
152 check saving last-message.txt
153
154 $ cat > $TESTTMP/abortfolding.py <<EOF
155 > from mercurial import util
156 > def abortfolding(ui, repo, hooktype, **kwargs):
157 > ctx = repo[kwargs.get('node')]
158 > if set(ctx.files()) == {b'c', b'd', b'f'}:
159 > return True # abort folding commit only
160 > ui.warn(b'allow non-folding commit\\n')
161 > EOF
162 $ cat > .hg/hgrc <<EOF
163 > [hooks]
164 > pretxncommit.abortfolding = python:$TESTTMP/abortfolding.py:abortfolding
165 > EOF
166
167 $ cat > $TESTTMP/editor.sh << EOF
168 > echo "==== before editing"
169 > cat \$1
170 > echo "===="
171 > echo "check saving last-message.txt" >> \$1
172 > EOF
173
174 $ rm -f .hg/last-message.txt
175 $ hg status --rev '58c8f2bfc151^1::bab801520cec'
176 A c
177 A d
178 A f
179 $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 58c8f2bfc151 --commands - 2>&1 <<EOF
180 > pick 58c8f2bfc151 f
181 > fold bab801520cec d
182 > EOF
183 allow non-folding commit
184 ==== before editing
185 f
186 ***
187 c
188 ***
189 d
190
191
192
193 HG: Enter commit message. Lines beginning with 'HG:' are removed.
194 HG: Leave message empty to abort commit.
195 HG: --
196 HG: user: test
197 HG: branch 'default'
198 HG: added c
199 HG: added d
200 HG: added f
201 ====
202 transaction abort!
203 rollback completed
204 abort: pretxncommit.abortfolding hook failed
205 [40]
206
207 $ cat .hg/last-message.txt
208 f
209 ***
210 c
211 ***
212 d
213
214
215
216 check saving last-message.txt
217
218 $ cd ..
219 $ rm -r r
220
221 folding preserves initial author but uses later date
222 ----------------------------------------------------
223
224 $ initrepo
225
226 $ hg ci -d '7 0' --user "someone else" --amend --quiet
227
228 tip before edit
229 $ hg log --rev .
230 changeset: 5:10c36dd37515
231 tag: tip
232 user: someone else
233 date: Thu Jan 01 00:00:07 1970 +0000
234 summary: f
235
236
237 $ hg --config progress.debug=1 --debug \
238 > histedit 1ddb6c90f2ee --commands - 2>&1 <<EOF | \
239 > grep -E 'editing|unresolved'
240 > pick 1ddb6c90f2ee e
241 > fold 10c36dd37515 f
242 > EOF
243 editing: pick 1ddb6c90f2ee 4 e 1/2 changes (50.00%)
244 editing: fold 10c36dd37515 5 f 2/2 changes (100.00%)
245
246 tip after edit, which should use the later date, from the second changeset
247 $ hg log --rev .
248 changeset: 4:e4f3ec5d0b40
249 tag: tip
250 user: test
251 date: Thu Jan 01 00:00:07 1970 +0000
252 summary: e
253
254
255 $ cd ..
256 $ rm -r r
257
258 folding and creating no new change doesn't break:
259 -------------------------------------------------
260
261 folded content is dropped during a merge. The folded commit should properly disappear.
262
263 $ mkdir fold-to-empty-test
264 $ cd fold-to-empty-test
265 $ hg init
266 $ printf "1\n2\n3\n" > file
267 $ hg add file
268 $ hg commit -m '1+2+3'
269 $ echo 4 >> file
270 $ hg commit -m '+4'
271 $ echo 5 >> file
272 $ hg commit -m '+5'
273 $ echo 6 >> file
274 $ hg commit -m '+6'
275 $ hg logt --graph
276 @ 3:251d831eeec5 +6
277 |
278 o 2:888f9082bf99 +5
279 |
280 o 1:617f94f13c0f +4
281 |
282 o 0:0189ba417d34 1+2+3
283
284
285 $ hg histedit 1 --commands - << EOF
286 > pick 617f94f13c0f 1 +4
287 > drop 888f9082bf99 2 +5
288 > fold 251d831eeec5 3 +6
289 > EOF
290 merging file
291 warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
292 Fix up the change (fold 251d831eeec5)
293 (hg histedit --continue to resume)
294 [240]
295 There were conflicts, we keep P1 content. This
296 should effectively drop the changes from +6.
297
298 $ hg status -v
299 M file
300 ? file.orig
301 # The repository is in an unfinished *histedit* state.
302
303 # Unresolved merge conflicts:
304 #
305 # file
306 #
307 # To mark files as resolved: hg resolve --mark FILE
308
309 # To continue: hg histedit --continue
310 # To abort: hg histedit --abort
311
312 $ hg resolve -l
313 U file
314 $ hg revert -r 'p1()' file
315 $ hg resolve --mark file
316 (no more unresolved files)
317 continue: hg histedit --continue
318 $ hg histedit --continue
319 251d831eeec5: empty changeset
320 saved backup bundle to $TESTTMP/fold-to-empty-test/.hg/strip-backup/888f9082bf99-daa0b8b3-histedit.hg
321 $ hg logt --graph
322 @ 1:617f94f13c0f +4
323 |
324 o 0:0189ba417d34 1+2+3
325
326
327 $ cd ..
328
329
330 Test fold through dropped
331 -------------------------
332
333
334 Test corner case where folded revision is separated from its parent by a
335 dropped revision.
336
337
338 $ hg init fold-with-dropped
339 $ cd fold-with-dropped
340 $ printf "1\n2\n3\n" > file
341 $ hg commit -Am '1+2+3'
342 adding file
343 $ echo 4 >> file
344 $ hg commit -m '+4'
345 $ echo 5 >> file
346 $ hg commit -m '+5'
347 $ echo 6 >> file
348 $ hg commit -m '+6'
349 $ hg logt -G
350 @ 3:251d831eeec5 +6
351 |
352 o 2:888f9082bf99 +5
353 |
354 o 1:617f94f13c0f +4
355 |
356 o 0:0189ba417d34 1+2+3
357
358 $ hg histedit 1 --commands - << EOF
359 > pick 617f94f13c0f 1 +4
360 > drop 888f9082bf99 2 +5
361 > fold 251d831eeec5 3 +6
362 > EOF
363 merging file
364 warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
365 Fix up the change (fold 251d831eeec5)
366 (hg histedit --continue to resume)
367 [240]
368 $ cat > file << EOF
369 > 1
370 > 2
371 > 3
372 > 4
373 > 5
374 > EOF
375 $ hg resolve --mark file
376 (no more unresolved files)
377 continue: hg histedit --continue
378 $ hg commit -m '+5.2'
379 created new head
380 $ echo 6 >> file
381 $ HGEDITOR=cat hg continue
382 +4
383 ***
384 +5.2
385 ***
386 +6
387
388
389
390 HG: Enter commit message. Lines beginning with 'HG:' are removed.
391 HG: Leave message empty to abort commit.
392 HG: --
393 HG: user: test
394 HG: branch 'default'
395 HG: changed file
396 saved backup bundle to $TESTTMP/fold-with-dropped/.hg/strip-backup/617f94f13c0f-3d69522c-histedit.hg
397 $ hg logt -G
398 @ 1:10c647b2cdd5 +4
399 |
400 o 0:0189ba417d34 1+2+3
401
402 $ hg export tip
403 # HG changeset patch
404 # User test
405 # Date 0 0
406 # Thu Jan 01 00:00:00 1970 +0000
407 # Node ID 10c647b2cdd54db0603ecb99b2ff5ce66d5a5323
408 # Parent 0189ba417d34df9dda55f88b637dcae9917b5964
409 +4
410 ***
411 +5.2
412 ***
413 +6
414
415 diff -r 0189ba417d34 -r 10c647b2cdd5 file
416 --- a/file Thu Jan 01 00:00:00 1970 +0000
417 +++ b/file Thu Jan 01 00:00:00 1970 +0000
418 @@ -1,3 +1,6 @@
419 1
420 2
421 3
422 +4
423 +5
424 +6
425 $ cd ..
426
427
428 Folding with initial rename (issue3729)
429 ---------------------------------------
430
431 $ hg init fold-rename
432 $ cd fold-rename
433 $ echo a > a.txt
434 $ hg add a.txt
435 $ hg commit -m a
436 $ hg rename a.txt b.txt
437 $ hg commit -m rename
438 $ echo b >> b.txt
439 $ hg commit -m b
440
441 $ hg logt --follow b.txt
442 2:e0371e0426bc b
443 1:1c4f440a8085 rename
444 0:6c795aa153cb a
445
446 $ hg histedit 1c4f440a8085 --commands - 2>&1 << EOF | fixbundle
447 > pick 1c4f440a8085 rename
448 > fold e0371e0426bc b
449 > EOF
450
451 $ hg logt --follow b.txt
452 1:cf858d235c76 rename
453 0:6c795aa153cb a
454
455 $ cd ..
456
457 Folding with swapping
458 ---------------------
459
460 This is an excuse to test hook with histedit temporary commit (issue4422)
461
462
463 $ hg init issue4422
464 $ cd issue4422
465 $ echo a > a.txt
466 $ hg add a.txt
467 $ hg commit -m a
468 $ echo b > b.txt
469 $ hg add b.txt
470 $ hg commit -m b
471 $ echo c > c.txt
472 $ hg add c.txt
473 $ hg commit -m c
474
475 $ hg logt
476 2:a1a953ffb4b0 c
477 1:199b6bb90248 b
478 0:6c795aa153cb a
479
480 $ hg histedit 6c795aa153cb --config hooks.commit='echo commit $HG_NODE' --config hooks.tonative.commit=True \
481 > --commands - 2>&1 << EOF | fixbundle
482 > pick 199b6bb90248 b
483 > fold a1a953ffb4b0 c
484 > pick 6c795aa153cb a
485 > EOF
486 commit 9599899f62c05f4377548c32bf1c9f1a39634b0c
487
488 $ hg logt
489 1:9599899f62c0 a
490 0:79b99e9c8e49 b
491
492 Test unix -> windows style variable substitution in external hooks.
493
494 $ cat > $TESTTMP/tmp.hgrc <<'EOF'
495 > [hooks]
496 > pre-add = echo no variables
497 > post-add = echo ran $HG_ARGS, literal \$non-var, 'also $non-var', $HG_RESULT
498 > tonative.post-add = True
499 > EOF
500
501 $ echo "foo" > amended.txt
502 $ HGRCPATH=$TESTTMP/tmp.hgrc hg add -v amended.txt
503 running hook pre-add: echo no variables
504 no variables
505 adding amended.txt
506 converting hook "post-add" to native (windows !)
507 running hook post-add: echo ran %HG_ARGS%, literal $non-var, "also $non-var", %HG_RESULT% (windows !)
508 running hook post-add: echo ran $HG_ARGS, literal \$non-var, 'also $non-var', $HG_RESULT (no-windows !)
509 ran add -v amended.txt, literal $non-var, "also $non-var", 0 (windows !)
510 ran add -v amended.txt, literal $non-var, also $non-var, 0 (no-windows !)
511 $ hg ci -q --config extensions.largefiles= --amend -I amended.txt
512 The fsmonitor extension is incompatible with the largefiles extension and has been disabled. (fsmonitor !)
513
514 Test that folding multiple changes in a row doesn't show multiple
515 editors.
516
517 $ echo foo >> foo
518 $ hg add foo
519 $ hg ci -m foo1
520 $ echo foo >> foo
521 $ hg ci -m foo2
522 $ echo foo >> foo
523 $ hg ci -m foo3
524 $ hg logt
525 4:21679ff7675c foo3
526 3:b7389cc4d66e foo2
527 2:0e01aeef5fa8 foo1
528 1:578c7455730c a
529 0:79b99e9c8e49 b
530 $ cat > "$TESTTMP/editor.sh" <<EOF
531 > echo ran editor >> "$TESTTMP/editorlog.txt"
532 > cat \$1 >> "$TESTTMP/editorlog.txt"
533 > echo END >> "$TESTTMP/editorlog.txt"
534 > echo merged foos > \$1
535 > EOF
536 $ HGEDITOR="sh \"$TESTTMP/editor.sh\"" hg histedit 1 --commands - 2>&1 <<EOF | fixbundle
537 > pick 578c7455730c 1 a
538 > pick 0e01aeef5fa8 2 foo1
539 > fold b7389cc4d66e 3 foo2
540 > fold 21679ff7675c 4 foo3
541 > EOF
542 merging foo
543 $ hg logt
544 2:e8bedbda72c1 merged foos
545 1:578c7455730c a
546 0:79b99e9c8e49 b
547 Editor should have run only once
548 $ cat $TESTTMP/editorlog.txt
549 ran editor
550 foo1
551 ***
552 foo2
553 ***
554 foo3
555
556
557
558 HG: Enter commit message. Lines beginning with 'HG:' are removed.
559 HG: Leave message empty to abort commit.
560 HG: --
561 HG: user: test
562 HG: branch 'default'
563 HG: added foo
564 END
565
566 $ cd ..
567
568 Test rolling into a commit with multiple children (issue5498)
569
570 $ hg init roll
571 $ cd roll
572 $ echo a > a
573 $ hg commit -qAm aa
574 $ echo b > b
575 $ hg commit -qAm bb
576 $ hg up -q ".^"
577 $ echo c > c
578 $ hg commit -qAm cc
579 $ hg log -G -T '{node|short} {desc}'
580 @ 5db65b93a12b cc
581 |
582 | o 301d76bdc3ae bb
583 |/
584 o 8f0162e483d0 aa
585
586
587 $ hg histedit . --commands - << EOF
588 > r 5db65b93a12b
589 > EOF
590 hg: parse error: first changeset cannot use verb "roll"
591 [10]
592 $ hg log -G -T '{node|short} {desc}'
593 @ 5db65b93a12b cc
594 |
595 | o 301d76bdc3ae bb
596 |/
597 o 8f0162e483d0 aa
598
599
600 $ cd ..
601
602 ====================================
603 Test update-timestamp config option|
604 ====================================
605
606 $ addwithdate ()
607 > {
608 > echo $1 > $1
609 > hg add $1
610 > hg ci -m $1 -d "$2 0"
611 > }
612
613 $ initrepo ()
614 > {
615 > hg init r
616 > cd r
617 > addwithdate a 1
618 > addwithdate b 2
619 > addwithdate c 3
620 > addwithdate d 4
621 > addwithdate e 5
622 > addwithdate f 6
623 > }
624
625 $ initrepo
626
627 log before edit
628
629 $ hg log
630 changeset: 5:178e35e0ce73
631 tag: tip
632 user: test
633 date: Thu Jan 01 00:00:06 1970 +0000
634 summary: f
635
636 changeset: 4:1ddb6c90f2ee
637 user: test
638 date: Thu Jan 01 00:00:05 1970 +0000
639 summary: e
640
641 changeset: 3:532247a8969b
642 user: test
643 date: Thu Jan 01 00:00:04 1970 +0000
644 summary: d
645
646 changeset: 2:ff2c9fa2018b
647 user: test
648 date: Thu Jan 01 00:00:03 1970 +0000
649 summary: c
650
651 changeset: 1:97d72e5f12c7
652 user: test
653 date: Thu Jan 01 00:00:02 1970 +0000
654 summary: b
655
656 changeset: 0:8580ff50825a
657 user: test
658 date: Thu Jan 01 00:00:01 1970 +0000
659 summary: a
660
661
662 $ hg histedit 1ddb6c90f2ee --commands - 2>&1 --config rewrite.update-timestamp=True <<EOF | fixbundle
663 > pick 178e35e0ce73 f
664 > fold 1ddb6c90f2ee e
665 > EOF
666
667 log after edit
668 observe time from f is updated
669
670 $ hg log
671 changeset: 4:f7909b1863a2
672 tag: tip
673 user: test
674 date: Thu Jan 01 00:00:01 1970 +0000
675 summary: f
676
677 changeset: 3:532247a8969b
678 user: test
679 date: Thu Jan 01 00:00:04 1970 +0000
680 summary: d
681
682 changeset: 2:ff2c9fa2018b
683 user: test
684 date: Thu Jan 01 00:00:03 1970 +0000
685 summary: c
686
687 changeset: 1:97d72e5f12c7
688 user: test
689 date: Thu Jan 01 00:00:02 1970 +0000
690 summary: b
691
692 changeset: 0:8580ff50825a
693 user: test
694 date: Thu Jan 01 00:00:01 1970 +0000
695 summary: a
696
697 post-fold manifest
698 $ hg manifest
699 a
700 b
701 c
702 d
703 e
704 f
705
706 $ cd ..