Debian Codegraph @

tests/test-absorb.t

raw
1 $ cat >> $HGRCPATH << EOF
2 > [extensions]
3 > absorb=
4 > EOF
5
6 $ sedi() { # workaround check-code
7 > pattern="$1"
8 > shift
9 > for i in "$@"; do
10 > sed "$pattern" "$i" > "$i".tmp
11 > mv "$i".tmp "$i"
12 > done
13 > }
14
15 $ hg init repo1
16 $ cd repo1
17
18 Do not crash with empty repo:
19
20 $ hg absorb
21 abort: no mutable changeset to change
22 [10]
23
24 Make some commits:
25
26 $ for i in 1 2 3 4 5; do
27 > echo $i >> a
28 > hg commit -A a -m "commit $i" -q
29 > done
30
31 $ hg annotate a
32 0: 1
33 1: 2
34 2: 3
35 3: 4
36 4: 5
37
38 Change a few lines:
39
40 $ cat > a <<EOF
41 > 1a
42 > 2b
43 > 3
44 > 4d
45 > 5e
46 > EOF
47
48 Preview absorb changes:
49
50 $ hg absorb --print-changes --dry-run
51 showing changes for a
52 @@ -0,2 +0,2 @@
53 4ec16f8 -1
54 5c5f952 -2
55 4ec16f8 +1a
56 5c5f952 +2b
57 @@ -3,2 +3,2 @@
58 ad8b8b7 -4
59 4f55fa6 -5
60 ad8b8b7 +4d
61 4f55fa6 +5e
62
63 4 changesets affected
64 4f55fa6 commit 5
65 ad8b8b7 commit 4
66 5c5f952 commit 2
67 4ec16f8 commit 1
68
69 Run absorb:
70
71 $ hg absorb --apply-changes
72 saved backup bundle to * (glob)
73 2 of 2 chunk(s) applied
74 $ hg annotate a
75 0: 1a
76 1: 2b
77 2: 3
78 3: 4d
79 4: 5e
80
81 Delete a few lines and related commits will be removed if they will be empty:
82
83 $ cat > a <<EOF
84 > 2b
85 > 4d
86 > EOF
87 $ echo y | hg absorb --config ui.interactive=1
88 showing changes for a
89 @@ -0,1 +0,0 @@
90 f548282 -1a
91 @@ -2,1 +1,0 @@
92 ff5d556 -3
93 @@ -4,1 +2,0 @@
94 84e5416 -5e
95
96 3 changesets affected
97 84e5416 commit 5
98 ff5d556 commit 3
99 f548282 commit 1
100 apply changes (y/N)? y
101 saved backup bundle to * (glob)
102 3 of 3 chunk(s) applied
103 $ hg annotate a
104 1: 2b
105 2: 4d
106 $ hg log -T '{rev} {desc}\n' -Gp
107 @ 2 commit 4
108 | diff -r 1cae118c7ed8 -r 58a62bade1c6 a
109 | --- a/a Thu Jan 01 00:00:00 1970 +0000
110 | +++ b/a Thu Jan 01 00:00:00 1970 +0000
111 | @@ -1,1 +1,2 @@
112 | 2b
113 | +4d
114 |
115 o 1 commit 2
116 | diff -r 84add69aeac0 -r 1cae118c7ed8 a
117 | --- a/a Thu Jan 01 00:00:00 1970 +0000
118 | +++ b/a Thu Jan 01 00:00:00 1970 +0000
119 | @@ -0,0 +1,1 @@
120 | +2b
121 |
122 o 0 commit 1
123
124
125 Non 1:1 map changes will be ignored:
126
127 $ echo 1 > a
128 $ hg absorb --apply-changes
129 nothing applied
130 [1]
131
132 The prompt is not given if there are no changes to be applied, even if there
133 are some changes that won't be applied:
134
135 $ hg absorb
136 showing changes for a
137 @@ -0,2 +0,1 @@
138 -2b
139 -4d
140 +1
141
142 0 changesets affected
143 nothing applied
144 [1]
145
146 Insertaions:
147
148 $ cat > a << EOF
149 > insert before 2b
150 > 2b
151 > 4d
152 > insert aftert 4d
153 > EOF
154 $ hg absorb -q --apply-changes
155 $ hg status
156 $ hg annotate a
157 1: insert before 2b
158 1: 2b
159 2: 4d
160 2: insert aftert 4d
161
162 Bookmarks are moved:
163
164 $ hg bookmark -r 1 b1
165 $ hg bookmark -r 2 b2
166 $ hg bookmark ba
167 $ hg bookmarks
168 b1 1:b35060a57a50
169 b2 2:946e4bc87915
170 * ba 2:946e4bc87915
171 $ sedi 's/insert/INSERT/' a
172 $ hg absorb -q --apply-changes
173 $ hg status
174 $ hg bookmarks
175 b1 1:a4183e9b3d31
176 b2 2:c9b20c925790
177 * ba 2:c9b20c925790
178
179 Non-modified files are ignored:
180
181 $ touch b
182 $ hg commit -A b -m b
183 $ touch c
184 $ hg add c
185 $ hg rm b
186 $ hg absorb --apply-changes
187 nothing applied
188 [1]
189 $ sedi 's/INSERT/Insert/' a
190 $ hg absorb --apply-changes
191 saved backup bundle to * (glob)
192 2 of 2 chunk(s) applied
193 $ hg status
194 A c
195 R b
196
197 Public commits will not be changed:
198
199 $ hg phase -p 1
200 $ sedi 's/Insert/insert/' a
201 $ hg absorb -pn
202 showing changes for a
203 @@ -0,1 +0,1 @@
204 -Insert before 2b
205 +insert before 2b
206 @@ -3,1 +3,1 @@
207 85b4e0e -Insert aftert 4d
208 85b4e0e +insert aftert 4d
209
210 1 changesets affected
211 85b4e0e commit 4
212 $ hg absorb --apply-changes
213 saved backup bundle to * (glob)
214 1 of 2 chunk(s) applied
215 $ hg diff -U 0
216 diff -r 1c8eadede62a a
217 --- a/a Thu Jan 01 00:00:00 1970 +0000
218 +++ b/a * (glob)
219 @@ -1,1 +1,1 @@
220 -Insert before 2b
221 +insert before 2b
222 $ hg annotate a
223 1: Insert before 2b
224 1: 2b
225 2: 4d
226 2: insert aftert 4d
227
228 $ hg co -qC 1
229 $ sedi 's/Insert/insert/' a
230 $ hg absorb --apply-changes
231 abort: no mutable changeset to change
232 [10]
233
234 Make working copy clean:
235
236 $ hg co -qC ba
237 $ rm c
238 $ hg status
239
240 Merge commit will not be changed:
241
242 $ echo 1 > m1
243 $ hg commit -A m1 -m m1
244 $ hg bookmark -q -i m1
245 $ hg update -q '.^'
246 $ echo 2 > m2
247 $ hg commit -q -A m2 -m m2
248 $ hg merge -q m1
249 $ hg commit -m merge
250 $ hg bookmark -d m1
251 $ hg log -G -T '{rev} {desc} {phase}\n'
252 @ 6 merge draft
253 |\
254 | o 5 m2 draft
255 | |
256 o | 4 m1 draft
257 |/
258 o 3 b draft
259 |
260 o 2 commit 4 draft
261 |
262 o 1 commit 2 public
263 |
264 o 0 commit 1 public
265
266 $ echo 2 >> m1
267 $ echo 2 >> m2
268 $ hg absorb --apply-changes
269 abort: cannot absorb into a merge
270 [10]
271 $ hg revert -q -C m1 m2
272
273 Use a new repo:
274
275 $ cd ..
276 $ hg init repo2
277 $ cd repo2
278
279 Make some commits to multiple files:
280
281 $ for f in a b; do
282 > for i in 1 2; do
283 > echo $f line $i >> $f
284 > hg commit -A $f -m "commit $f $i" -q
285 > done
286 > done
287
288 Use pattern to select files to be fixed up:
289
290 $ sedi 's/line/Line/' a b
291 $ hg status
292 M a
293 M b
294 $ hg absorb --apply-changes a
295 saved backup bundle to * (glob)
296 1 of 1 chunk(s) applied
297 $ hg status
298 M b
299 $ hg absorb --apply-changes --exclude b
300 nothing applied
301 [1]
302 $ hg absorb --apply-changes b
303 saved backup bundle to * (glob)
304 1 of 1 chunk(s) applied
305 $ hg status
306 $ cat a b
307 a Line 1
308 a Line 2
309 b Line 1
310 b Line 2
311
312 Test config option absorb.max-stack-size:
313
314 $ sedi 's/Line/line/' a b
315 $ hg log -T '{rev}:{node} {desc}\n'
316 3:712d16a8f445834e36145408eabc1d29df05ec09 commit b 2
317 2:74cfa6294160149d60adbf7582b99ce37a4597ec commit b 1
318 1:28f10dcf96158f84985358a2e5d5b3505ca69c22 commit a 2
319 0:f9a81da8dc53380ed91902e5b82c1b36255a4bd0 commit a 1
320 $ hg --config absorb.max-stack-size=1 absorb -pn
321 absorb: only the recent 1 changesets will be analysed
322 showing changes for a
323 @@ -0,2 +0,2 @@
324 -a Line 1
325 -a Line 2
326 +a line 1
327 +a line 2
328 showing changes for b
329 @@ -0,2 +0,2 @@
330 -b Line 1
331 712d16a -b Line 2
332 +b line 1
333 712d16a +b line 2
334
335 1 changesets affected
336 712d16a commit b 2
337
338 Test obsolete markers creation:
339
340 $ cat >> $HGRCPATH << EOF
341 > [experimental]
342 > evolution=createmarkers
343 > [absorb]
344 > add-noise=1
345 > EOF
346
347 $ hg --config absorb.max-stack-size=3 absorb -a
348 absorb: only the recent 3 changesets will be analysed
349 2 of 2 chunk(s) applied
350 $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
351 6:3dfde4199b46 commit b 2 712d16a8f445834e36145408eabc1d29df05ec09
352 5:99cfab7da5ff commit b 1 74cfa6294160149d60adbf7582b99ce37a4597ec
353 4:fec2b3bd9e08 commit a 2 28f10dcf96158f84985358a2e5d5b3505ca69c22
354 0:f9a81da8dc53 commit a 1
355 $ hg absorb --apply-changes
356 1 of 1 chunk(s) applied
357 $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
358 10:e1c8c1e030a4 commit b 2 3dfde4199b4610ea6e3c6fa9f5bdad8939d69524
359 9:816c30955758 commit b 1 99cfab7da5ffdaf3b9fc6643b14333e194d87f46
360 8:5867d584106b commit a 2 fec2b3bd9e0834b7cb6a564348a0058171aed811
361 7:8c76602baf10 commit a 1 f9a81da8dc53380ed91902e5b82c1b36255a4bd0
362
363 Executable files:
364
365 $ cat >> $HGRCPATH << EOF
366 > [diff]
367 > git=True
368 > EOF
369 $ cd ..
370 $ hg init repo3
371 $ cd repo3
372
373 #if execbit
374 $ echo > foo.py
375 $ chmod +x foo.py
376 $ hg add foo.py
377 $ hg commit -mfoo
378 #else
379 $ hg import -q --bypass - <<EOF
380 > # HG changeset patch
381 > foo
382 >
383 > diff --git a/foo.py b/foo.py
384 > new file mode 100755
385 > --- /dev/null
386 > +++ b/foo.py
387 > @@ -0,0 +1,1 @@
388 > +
389 > EOF
390 $ hg up -q
391 #endif
392
393 $ echo bla > foo.py
394 $ hg absorb --dry-run --print-changes
395 showing changes for foo.py
396 @@ -0,1 +0,1 @@
397 99b4ae7 -
398 99b4ae7 +bla
399
400 1 changesets affected
401 99b4ae7 foo
402 $ hg absorb --dry-run --interactive --print-changes
403 diff -r 99b4ae712f84 foo.py
404 1 hunks, 1 lines changed
405 examine changes to 'foo.py'?
406 (enter ? for help) [Ynesfdaq?] y
407
408 @@ -1,1 +1,1 @@
409 -
410 +bla
411 record this change to 'foo.py'?
412 (enter ? for help) [Ynesfdaq?] y
413
414 showing changes for foo.py
415 @@ -0,1 +0,1 @@
416 99b4ae7 -
417 99b4ae7 +bla
418
419 1 changesets affected
420 99b4ae7 foo
421 $ hg absorb --apply-changes
422 1 of 1 chunk(s) applied
423 $ hg diff -c .
424 diff --git a/foo.py b/foo.py
425 new file mode 100755
426 --- /dev/null
427 +++ b/foo.py
428 @@ -0,0 +1,1 @@
429 +bla
430 $ hg diff
431
432 Remove lines may delete changesets:
433
434 $ cd ..
435 $ hg init repo4
436 $ cd repo4
437 $ cat > a <<EOF
438 > 1
439 > 2
440 > EOF
441 $ hg commit -m a12 -A a
442 $ cat > b <<EOF
443 > 1
444 > 2
445 > EOF
446 $ hg commit -m b12 -A b
447 $ echo 3 >> b
448 $ hg commit -m b3
449 $ echo 4 >> b
450 $ hg commit -m b4
451 $ echo 1 > b
452 $ echo 3 >> a
453 $ hg absorb -pn
454 showing changes for a
455 @@ -2,0 +2,1 @@
456 bfafb49 +3
457 showing changes for b
458 @@ -1,3 +1,0 @@
459 1154859 -2
460 30970db -3
461 a393a58 -4
462
463 4 changesets affected
464 a393a58 b4
465 30970db b3
466 1154859 b12
467 bfafb49 a12
468 $ hg absorb -av | grep became
469 0:bfafb49242db: 1 file(s) changed, became 4:1a2de97fc652
470 1:115485984805: 2 file(s) changed, became 5:0c930dfab74c
471 2:30970dbf7b40: became empty and was dropped
472 3:a393a58b9a85: became empty and was dropped
473 $ hg log -T '{rev} {desc}\n' -Gp
474 @ 5 b12
475 | diff --git a/b b/b
476 | new file mode 100644
477 | --- /dev/null
478 | +++ b/b
479 | @@ -0,0 +1,1 @@
480 | +1
481 |
482 o 4 a12
483 diff --git a/a b/a
484 new file mode 100644
485 --- /dev/null
486 +++ b/a
487 @@ -0,0 +1,3 @@
488 +1
489 +2
490 +3
491
492
493 Setting config rewrite.empty-successor=keep causes empty changesets to get committed:
494
495 $ cd ..
496 $ hg init repo4a
497 $ cd repo4a
498 $ cat > a <<EOF
499 > 1
500 > 2
501 > EOF
502 $ hg commit -m a12 -A a
503 $ cat > b <<EOF
504 > 1
505 > 2
506 > EOF
507 $ hg commit -m b12 -A b
508 $ echo 3 >> b
509 $ hg commit -m b3
510 $ echo 4 >> b
511 $ hg commit -m b4
512 $ hg commit -m empty --config ui.allowemptycommit=True
513 $ echo 1 > b
514 $ echo 3 >> a
515 $ hg absorb -pn
516 showing changes for a
517 @@ -2,0 +2,1 @@
518 bfafb49 +3
519 showing changes for b
520 @@ -1,3 +1,0 @@
521 1154859 -2
522 30970db -3
523 a393a58 -4
524
525 4 changesets affected
526 a393a58 b4
527 30970db b3
528 1154859 b12
529 bfafb49 a12
530 $ hg absorb -av --config rewrite.empty-successor=keep | grep became
531 0:bfafb49242db: 1 file(s) changed, became 5:1a2de97fc652
532 1:115485984805: 2 file(s) changed, became 6:0c930dfab74c
533 2:30970dbf7b40: 2 file(s) changed, became empty as 7:df6574ae635c
534 3:a393a58b9a85: 2 file(s) changed, became empty as 8:ad4bd3462c9e
535 4:1bb0e8cff87a: 2 file(s) changed, became 9:2dbed75af996
536 $ hg log -T '{rev} {desc}\n' -Gp
537 @ 9 empty
538 |
539 o 8 b4
540 |
541 o 7 b3
542 |
543 o 6 b12
544 | diff --git a/b b/b
545 | new file mode 100644
546 | --- /dev/null
547 | +++ b/b
548 | @@ -0,0 +1,1 @@
549 | +1
550 |
551 o 5 a12
552 diff --git a/a b/a
553 new file mode 100644
554 --- /dev/null
555 +++ b/a
556 @@ -0,0 +1,3 @@
557 +1
558 +2
559 +3
560
561
562 Use revert to make the current change and its parent disappear.
563 This should move us to the non-obsolete ancestor.
564
565 $ cd ..
566 $ hg init repo5
567 $ cd repo5
568 $ cat > a <<EOF
569 > 1
570 > 2
571 > EOF
572 $ hg commit -m a12 -A a
573 $ hg id
574 bfafb49242db tip
575 $ echo 3 >> a
576 $ hg commit -m a123 a
577 $ echo 4 >> a
578 $ hg commit -m a1234 a
579 $ hg id
580 82dbe7fd19f0 tip
581 $ hg revert -r 0 a
582 $ hg absorb -pn
583 showing changes for a
584 @@ -2,2 +2,0 @@
585 f1c23dd -3
586 82dbe7f -4
587
588 2 changesets affected
589 82dbe7f a1234
590 f1c23dd a123
591 $ hg absorb --apply-changes --verbose
592 1:f1c23dd5d08d: became empty and was dropped
593 2:82dbe7fd19f0: became empty and was dropped
594 a: 1 of 1 chunk(s) applied
595 $ hg id
596 bfafb49242db tip
597
598 $ cd ..
599 $ hg init repo6
600 $ cd repo6
601 $ echo a1 > a
602 $ touch b
603 $ hg commit -m a -A a b
604 $ hg branch foo -q
605 $ echo b > b
606 $ hg commit -m 'foo (child of 0cde1ae39321)' # will become empty
607 $ hg branch bar -q
608 $ hg commit -m 'bar (child of e969dc86aefc)' # is already empty
609 $ echo a2 > a
610 $ printf '' > b
611 $ hg absorb --apply-changes --verbose | grep became
612 0:0cde1ae39321: 1 file(s) changed, became 3:fc7fcdd90fdb
613 1:e969dc86aefc: 2 file(s) changed, became 4:8fc6b2cb43a5
614 2:0298954ced32: 2 file(s) changed, became 5:ca8386dc4e2c
615 $ hg log -T '{rev}:{node|short} (branch: {branch}) {desc}\n' -G --stat
616 @ 5:ca8386dc4e2c (branch: bar) bar (child of 8fc6b2cb43a5)
617 |
618 o 4:8fc6b2cb43a5 (branch: foo) foo (child of fc7fcdd90fdb)
619 |
620 o 3:fc7fcdd90fdb (branch: default) a
621 a | 1 +
622 b | 0
623 2 files changed, 1 insertions(+), 0 deletions(-)
624
625
626 $ cd ..
627 $ hg init repo7
628 $ cd repo7
629 $ echo a1 > a
630 $ touch b
631 $ hg commit -m a -A a b
632 $ echo b > b
633 $ hg commit -m foo --close-branch # will become empty
634 $ echo c > c
635 $ hg commit -m reopen -A c -q
636 $ hg commit -m bar --close-branch # is already empty
637 $ echo a2 > a
638 $ printf '' > b
639 $ hg absorb --apply-changes --verbose | grep became
640 0:0cde1ae39321: 1 file(s) changed, became 4:fc7fcdd90fdb
641 1:651b953d5764: 2 file(s) changed, became 5:0c9de988ecdc
642 2:76017bba73f6: 2 file(s) changed, became 6:d53ac896eb25
643 3:c7c1d67efc1d: 2 file(s) changed, became 7:66520267fe96
644 $ hg up null -q # to make visible closed heads
645 $ hg log -T '{rev} {desc}\n' -G --stat
646 _ 7 bar
647 |
648 o 6 reopen
649 | c | 1 +
650 | 1 files changed, 1 insertions(+), 0 deletions(-)
651 |
652 _ 5 foo
653 |
654 o 4 a
655 a | 1 +
656 b | 0
657 2 files changed, 1 insertions(+), 0 deletions(-)
658
659
660 $ cd ..
661 $ hg init repo8
662 $ cd repo8
663 $ echo a1 > a
664 $ hg commit -m a -A a
665 $ hg commit -m empty --config ui.allowemptycommit=True
666 $ echo a2 > a
667 $ hg absorb --apply-changes --verbose | grep became
668 0:ecf99a8d6699: 1 file(s) changed, became 2:7e3ccf8e2fa5
669 1:97f72456ae0d: 1 file(s) changed, became 3:2df488325d6f
670 $ hg log -T '{rev} {desc}\n' -G --stat
671 @ 3 empty
672 |
673 o 2 a
674 a | 1 +
675 1 files changed, 1 insertions(+), 0 deletions(-)
676