Debian Codegraph @

tests/test-commit-amend.t

raw
1 $ hg init repo
2 $ cd repo
3
4 Setup:
5
6 $ echo a >> a
7 $ hg ci -Am 'base'
8 adding a
9
10 Refuse to amend public csets:
11
12 $ hg phase -r . -p
13 $ hg ci --amend
14 abort: cannot amend public changesets: ad120869acf0
15 (see 'hg help phases' for details)
16 [10]
17 $ hg phase -r . -f -d
18
19 $ echo a >> a
20 $ hg ci -Am 'base1'
21
22 Nothing to amend:
23
24 $ hg ci --amend -m 'base1'
25 nothing changed
26 [1]
27
28 $ cat >> $HGRCPATH <<EOF
29 > [hooks]
30 > pretxncommit.foo = sh -c "echo \\"pretxncommit \$HG_NODE\\"; hg id -r \$HG_NODE"
31 > EOF
32
33 Amending changeset with changes in working dir:
34 (and check that --message does not trigger an editor)
35
36 $ echo a >> a
37 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -m 'amend base1'
38 pretxncommit 43f1ba15f28a50abf0aae529cf8a16bfced7b149
39 43f1ba15f28a tip
40 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/489edb5b847d-5ab4f721-amend.hg
41 $ echo 'pretxncommit.foo = ' >> $HGRCPATH
42 $ hg diff -c .
43 diff -r ad120869acf0 -r 43f1ba15f28a a
44 --- a/a Thu Jan 01 00:00:00 1970 +0000
45 +++ b/a Thu Jan 01 00:00:00 1970 +0000
46 @@ -1,1 +1,3 @@
47 a
48 +a
49 +a
50 $ hg log
51 changeset: 1:43f1ba15f28a
52 tag: tip
53 user: test
54 date: Thu Jan 01 00:00:00 1970 +0000
55 summary: amend base1
56
57 changeset: 0:ad120869acf0
58 user: test
59 date: Thu Jan 01 00:00:00 1970 +0000
60 summary: base
61
62
63 Check proper abort for empty message
64
65 $ cat > editor.sh << '__EOF__'
66 > #!/bin/sh
67 > echo "" > "$1"
68 > __EOF__
69
70 Update the existing file to ensure that the dirstate is not in pending state
71 (where the status of some files in the working copy is not known yet). This in
72 turn ensures that when the transaction is aborted due to an empty message during
73 the amend, there should be no rollback.
74 $ echo a >> a
75
76 $ echo b > b
77 $ hg add b
78 $ hg summary
79 parent: 1:43f1ba15f28a tip
80 amend base1
81 branch: default
82 commit: 1 modified, 1 added, 1 unknown
83 update: (current)
84 phases: 2 draft
85 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend
86 abort: empty commit message
87 [10]
88 $ hg summary
89 parent: 1:43f1ba15f28a tip
90 amend base1
91 branch: default
92 commit: 1 modified, 1 added, 1 unknown
93 update: (current)
94 phases: 2 draft
95
96 Add new file along with modified existing file:
97 $ hg ci --amend -m 'amend base1 new file'
98 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/43f1ba15f28a-007467c2-amend.hg
99
100 Remove file that was added in amended commit:
101 (and test logfile option)
102 (and test that logfile option do not trigger an editor)
103
104 $ hg rm b
105 $ echo 'amend base1 remove new file' > ../logfile
106 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg ci --amend --logfile ../logfile
107 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/c16295aaf401-1ada9901-amend.hg
108
109 $ hg cat b
110 b: no such file in rev 47343646fa3d
111 [1]
112
113 No changes, just a different message:
114
115 $ hg ci -v --amend -m 'no changes, new message'
116 amending changeset 47343646fa3d
117 copying changeset 47343646fa3d to ad120869acf0
118 committing files:
119 a
120 committing manifest
121 committing changelog
122 1 changesets found
123 uncompressed size of bundle content:
124 256 (changelog)
125 165 (manifests)
126 135 a
127 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/47343646fa3d-c2758885-amend.hg
128 1 changesets found
129 uncompressed size of bundle content:
130 252 (changelog)
131 165 (manifests)
132 135 a
133 adding branch
134 adding changesets
135 adding manifests
136 adding file changes
137 added 1 changesets with 1 changes to 1 files
138 committed changeset 1:401431e913a1
139 $ hg diff -c .
140 diff -r ad120869acf0 -r 401431e913a1 a
141 --- a/a Thu Jan 01 00:00:00 1970 +0000
142 +++ b/a Thu Jan 01 00:00:00 1970 +0000
143 @@ -1,1 +1,4 @@
144 a
145 +a
146 +a
147 +a
148 $ hg log
149 changeset: 1:401431e913a1
150 tag: tip
151 user: test
152 date: Thu Jan 01 00:00:00 1970 +0000
153 summary: no changes, new message
154
155 changeset: 0:ad120869acf0
156 user: test
157 date: Thu Jan 01 00:00:00 1970 +0000
158 summary: base
159
160
161 Disable default date on commit so when -d isn't given, the old date is preserved:
162
163 $ echo '[defaults]' >> $HGRCPATH
164 $ echo 'commit=' >> $HGRCPATH
165
166 Test -u/-d:
167
168 $ cat > .hg/checkeditform.sh <<EOF
169 > env | grep HGEDITFORM
170 > true
171 > EOF
172 $ HGEDITOR="sh .hg/checkeditform.sh" hg ci --amend -u foo -d '1 0'
173 HGEDITFORM=commit.amend.normal
174 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/401431e913a1-5e8e532c-amend.hg
175 $ echo a >> a
176 $ hg ci --amend -u foo -d '1 0'
177 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/d96b1d28ae33-677e0afb-amend.hg
178 $ hg log -r .
179 changeset: 1:a9a13940fc03
180 tag: tip
181 user: foo
182 date: Thu Jan 01 00:00:01 1970 +0000
183 summary: no changes, new message
184
185
186 Open editor with old commit message if a message isn't given otherwise:
187
188 $ cat > editor.sh << '__EOF__'
189 > #!/bin/sh
190 > cat $1
191 > echo "another precious commit message" > "$1"
192 > __EOF__
193
194 at first, test saving last-message.txt
195
196 $ cat > .hg/hgrc << '__EOF__'
197 > [hooks]
198 > pretxncommit.test-saving-last-message = false
199 > __EOF__
200
201 $ rm -f .hg/last-message.txt
202 $ hg commit --amend -v -m "message given from command line"
203 amending changeset a9a13940fc03
204 copying changeset a9a13940fc03 to ad120869acf0
205 committing files:
206 a
207 committing manifest
208 committing changelog
209 running hook pretxncommit.test-saving-last-message: false
210 transaction abort!
211 rollback completed
212 abort: pretxncommit.test-saving-last-message hook exited with status 1
213 [40]
214 $ cat .hg/last-message.txt
215 message given from command line (no-eol)
216
217 $ rm -f .hg/last-message.txt
218 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
219 amending changeset a9a13940fc03
220 copying changeset a9a13940fc03 to ad120869acf0
221 no changes, new message
222
223
224 HG: Enter commit message. Lines beginning with 'HG:' are removed.
225 HG: Leave message empty to abort commit.
226 HG: --
227 HG: user: foo
228 HG: branch 'default'
229 HG: changed a
230 committing files:
231 a
232 committing manifest
233 committing changelog
234 running hook pretxncommit.test-saving-last-message: false
235 transaction abort!
236 rollback completed
237 abort: pretxncommit.test-saving-last-message hook exited with status 1
238 [40]
239
240 $ cat .hg/last-message.txt
241 another precious commit message
242
243 $ cat > .hg/hgrc << '__EOF__'
244 > [hooks]
245 > pretxncommit.test-saving-last-message =
246 > __EOF__
247
248 then, test editing custom commit message
249
250 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
251 amending changeset a9a13940fc03
252 copying changeset a9a13940fc03 to ad120869acf0
253 no changes, new message
254
255
256 HG: Enter commit message. Lines beginning with 'HG:' are removed.
257 HG: Leave message empty to abort commit.
258 HG: --
259 HG: user: foo
260 HG: branch 'default'
261 HG: changed a
262 committing files:
263 a
264 committing manifest
265 committing changelog
266 1 changesets found
267 uncompressed size of bundle content:
268 251 (changelog)
269 165 (manifests)
270 137 a
271 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/a9a13940fc03-7c2e8674-amend.hg
272 1 changesets found
273 uncompressed size of bundle content:
274 259 (changelog)
275 165 (manifests)
276 137 a
277 adding branch
278 adding changesets
279 adding manifests
280 adding file changes
281 added 1 changesets with 1 changes to 1 files
282 committed changeset 1:64a124ba1b44
283
284 Same, but with changes in working dir (different code path):
285
286 $ echo a >> a
287 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend -v
288 amending changeset 64a124ba1b44
289 another precious commit message
290
291
292 HG: Enter commit message. Lines beginning with 'HG:' are removed.
293 HG: Leave message empty to abort commit.
294 HG: --
295 HG: user: foo
296 HG: branch 'default'
297 HG: changed a
298 committing files:
299 a
300 committing manifest
301 committing changelog
302 1 changesets found
303 uncompressed size of bundle content:
304 259 (changelog)
305 165 (manifests)
306 137 a
307 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/64a124ba1b44-10374b8f-amend.hg
308 1 changesets found
309 uncompressed size of bundle content:
310 259 (changelog)
311 165 (manifests)
312 139 a
313 adding branch
314 adding changesets
315 adding manifests
316 adding file changes
317 added 1 changesets with 1 changes to 1 files
318 committed changeset 1:7892795b8e38
319
320 $ rm editor.sh
321 $ hg log -r .
322 changeset: 1:7892795b8e38
323 tag: tip
324 user: foo
325 date: Thu Jan 01 00:00:01 1970 +0000
326 summary: another precious commit message
327
328
329 Moving bookmarks, preserve active bookmark:
330
331 $ hg book book1
332 $ hg book book2
333 $ hg ci --amend -m 'move bookmarks'
334 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/7892795b8e38-3fb46217-amend.hg
335 $ hg book
336 book1 1:8311f17e2616
337 * book2 1:8311f17e2616
338 $ echo a >> a
339 $ hg ci --amend -m 'move bookmarks'
340 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/8311f17e2616-f0504fe3-amend.hg
341 $ hg book
342 book1 1:a3b65065808c
343 * book2 1:a3b65065808c
344
345 abort does not loose bookmarks
346
347 $ cat > editor.sh << '__EOF__'
348 > #!/bin/sh
349 > echo "" > "$1"
350 > __EOF__
351 $ echo a >> a
352 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit --amend
353 abort: empty commit message
354 [10]
355 $ hg book
356 book1 1:a3b65065808c
357 * book2 1:a3b65065808c
358 $ hg revert -Caq
359 $ rm editor.sh
360
361 $ echo '[defaults]' >> $HGRCPATH
362 $ echo "commit=-d '0 0'" >> $HGRCPATH
363
364 Moving branches:
365
366 $ hg branch foo
367 marked working directory as branch foo
368 (branches are permanent and global, did you want a bookmark?)
369 $ echo a >> a
370 $ hg ci -m 'branch foo'
371 $ hg branch default -f
372 marked working directory as branch default
373 $ hg ci --amend -m 'back to default'
374 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/f8339a38efe1-c18453c9-amend.hg
375 $ hg branches
376 default 2:9c07515f2650
377
378 Close branch:
379
380 $ hg up -q 0
381 $ echo b >> b
382 $ hg branch foo
383 marked working directory as branch foo
384 (branches are permanent and global, did you want a bookmark?)
385 $ hg ci -Am 'fork'
386 adding b
387 $ echo b >> b
388 $ hg ci -mb
389 $ hg ci --amend --close-branch -m 'closing branch foo'
390 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/c962248fa264-54245dc7-amend.hg
391
392 Same thing, different code path:
393
394 $ echo b >> b
395 $ hg ci -m 'reopen branch'
396 reopening closed branch head 4
397 $ echo b >> b
398 $ hg ci --amend --close-branch
399 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/027371728205-b900d9fa-amend.hg
400 $ hg branches
401 default 2:9c07515f2650
402
403 Refuse to amend during a merge:
404
405 $ hg up -q default
406 $ hg merge foo
407 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
408 (branch merge, don't forget to commit)
409 $ hg ci --amend
410 abort: cannot amend changesets while merging
411 [20]
412 $ hg ci -m 'merge'
413
414 Refuse to amend if there is a merge conflict (issue5805):
415
416 $ hg up -q foo
417 $ echo c > a
418 $ hg up default -t :fail
419 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
420 use 'hg resolve' to retry unresolved file merges
421 [1]
422 $ hg resolve -l
423 U a
424
425 $ hg ci --amend
426 abort: unresolved merge conflicts (see 'hg help resolve')
427 [20]
428
429 $ hg up -qC .
430
431 Follow copies/renames:
432
433 $ hg mv b c
434 $ hg ci -m 'b -> c'
435 $ hg mv c d
436 $ hg ci --amend -m 'b -> d'
437 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/42f3f27a067d-f23cc9f7-amend.hg
438 $ hg st --rev '.^' --copies d
439 A d
440 b
441 $ hg cp d e
442 $ hg ci -m 'e = d'
443 $ hg cp e f
444 $ hg ci --amend -m 'f = d'
445 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/9198f73182d5-251d584a-amend.hg
446 $ hg st --rev '.^' --copies f
447 A f
448 d
449
450 $ mv f f.orig
451 $ hg rm -A f
452 $ hg ci -m removef
453 $ hg cp a f
454 $ mv f.orig f
455 $ hg ci --amend -m replacef
456 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/f0993ab6b482-eda301bf-amend.hg
457 $ hg st --change . --copies
458 $ hg log -r . --template "{file_copies}\n"
459
460
461 Move added file (issue3410):
462
463 $ echo g >> g
464 $ hg ci -Am g
465 adding g
466 $ hg mv g h
467 $ hg ci --amend
468 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/58585e3f095c-0f5ebcda-amend.hg
469 $ hg st --change . --copies h
470 A h
471 $ hg log -r . --template "{file_copies}\n"
472
473
474 Can't rollback an amend:
475
476 $ hg rollback
477 no rollback information available
478 [1]
479
480 Preserve extra dict (issue3430):
481
482 $ hg branch a
483 marked working directory as branch a
484 (branches are permanent and global, did you want a bookmark?)
485 $ echo a >> a
486 $ hg ci -ma
487 $ hg ci --amend -m "a'"
488 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/39a162f1d65e-9dfe13d8-amend.hg
489 $ hg log -r . --template "{branch}\n"
490 a
491 $ hg ci --amend -m "a''"
492 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/d5ca7b1ac72b-0b4c1a34-amend.hg
493 $ hg log -r . --template "{branch}\n"
494 a
495
496 Also preserve other entries in the dict that are in the old commit,
497 first graft something so there's an additional entry:
498
499 $ hg up 0 -q
500 $ echo z > z
501 $ hg ci -Am 'fork'
502 adding z
503 created new head
504 $ hg up 11
505 5 files updated, 0 files merged, 1 files removed, 0 files unresolved
506 $ hg graft 12
507 grafting 12:2647734878ef "fork" (tip)
508 $ hg ci --amend -m 'graft amend'
509 saved backup bundle to $TESTTMP/repo/.hg/strip-backup/fe8c6f7957ca-25638666-amend.hg
510 $ hg log -r . --debug | grep extra
511 extra: amend_source=fe8c6f7957ca1665ed77496ed7a07657d469ac60
512 extra: branch=a
513 extra: source=2647734878ef0236dda712fae9c1651cf694ea8a
514
515 Preserve phase
516
517 $ hg phase '.^::.'
518 11: draft
519 13: draft
520 $ hg phase --secret --force .
521 $ hg phase '.^::.'
522 11: draft
523 13: secret
524 $ hg commit --amend -m 'amend for phase' -q
525 $ hg phase '.^::.'
526 11: draft
527 13: secret
528
529 Test amend with obsolete
530 ---------------------------
531
532 Enable obsolete
533
534 $ cat >> $HGRCPATH << EOF
535 > [experimental]
536 > evolution.createmarkers=True
537 > evolution.allowunstable=True
538 > EOF
539
540 Amend with no files changes
541
542 $ hg id -n
543 13
544 $ hg ci --amend -m 'babar'
545 $ hg id -n
546 14
547 $ hg log -Gl 3 --style=compact
548 @ 14[tip]:11 682950e85999 1970-01-01 00:00 +0000 test
549 | babar
550 |
551 | o 12:0 2647734878ef 1970-01-01 00:00 +0000 test
552 | | fork
553 | ~
554 o 11 0ddb275cfad1 1970-01-01 00:00 +0000 test
555 | a''
556 ~
557 $ hg log -Gl 4 --hidden --style=compact
558 @ 14[tip]:11 682950e85999 1970-01-01 00:00 +0000 test
559 | babar
560 |
561 | x 13:11 5167600b0f7a 1970-01-01 00:00 +0000 test
562 |/ amend for phase
563 |
564 | o 12:0 2647734878ef 1970-01-01 00:00 +0000 test
565 | | fork
566 | ~
567 o 11 0ddb275cfad1 1970-01-01 00:00 +0000 test
568 | a''
569 ~
570
571 Amend with files changes
572
573 (note: the extra commit over 15 is a temporary junk I would be happy to get
574 ride of)
575
576 $ echo 'babar' >> a
577 $ hg commit --amend
578 $ hg log -Gl 6 --hidden --style=compact
579 @ 15[tip]:11 a5b42b49b0d5 1970-01-01 00:00 +0000 test
580 | babar
581 |
582 | x 14:11 682950e85999 1970-01-01 00:00 +0000 test
583 |/ babar
584 |
585 | x 13:11 5167600b0f7a 1970-01-01 00:00 +0000 test
586 |/ amend for phase
587 |
588 | o 12:0 2647734878ef 1970-01-01 00:00 +0000 test
589 | | fork
590 | ~
591 o 11 0ddb275cfad1 1970-01-01 00:00 +0000 test
592 | a''
593 |
594 o 10 5fa75032e226 1970-01-01 00:00 +0000 test
595 | g
596 ~
597
598
599 Test that amend does not make it easy to create obsolescence cycle
600 ---------------------------------------------------------------------
601
602 $ hg id -r 14 --hidden
603 682950e85999 (a)
604 $ hg revert -ar 14 --hidden
605 reverting a
606 $ hg commit --amend
607 $ hg id
608 37973c7e0b61 (a) tip
609
610 Test that rewriting leaving instability behind is allowed
611 ---------------------------------------------------------------------
612
613 $ hg up '.^'
614 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
615 $ echo 'b' >> a
616 $ hg log --style compact -r 'children(.)'
617 16[tip]:11 37973c7e0b61 1970-01-01 00:00 +0000 test
618 babar
619
620 $ hg commit --amend
621 1 new orphan changesets
622 $ hg log -r 'orphan()'
623 changeset: 16:37973c7e0b61
624 branch: a
625 parent: 11:0ddb275cfad1
626 user: test
627 date: Thu Jan 01 00:00:00 1970 +0000
628 instability: orphan
629 summary: babar
630
631
632 Amend a merge changeset (with renames and conflicts from the second parent):
633
634 $ hg up -q default
635 $ hg branch -q bar
636 $ hg cp a aa
637 $ hg mv z zz
638 $ echo cc > cc
639 $ hg add cc
640 $ hg ci -m aazzcc
641 $ hg up -q default
642 $ echo a >> a
643 $ echo dd > cc
644 $ hg add cc
645 $ hg ci -m aa
646 $ hg merge -q bar
647 warning: conflicts while merging cc! (edit, then use 'hg resolve --mark')
648 [1]
649 $ hg resolve -m cc
650 (no more unresolved files)
651 $ hg ci -m 'merge bar'
652 $ hg log --config diff.git=1 -pr .
653 changeset: 20:5aba7f3726e6
654 tag: tip
655 parent: 19:30d96aeaf27b
656 parent: 18:1aa437659d19
657 user: test
658 date: Thu Jan 01 00:00:00 1970 +0000
659 summary: merge bar
660
661 diff --git a/a b/aa
662 copy from a
663 copy to aa
664 diff --git a/cc b/cc
665 --- a/cc
666 +++ b/cc
667 @@ -1,1 +1,5 @@
668 +<<<<<<< working copy: 30d96aeaf27b - test: aa
669 dd
670 +=======
671 +cc
672 +>>>>>>> merge rev: 1aa437659d19 bar - test: aazzcc
673 diff --git a/z b/zz
674 rename from z
675 rename to zz
676
677 $ hg debugrename aa
678 aa renamed from a:a80d06849b333b8a3d5c445f8ba3142010dcdc9e
679 $ hg debugrename zz
680 zz renamed from z:69a1b67522704ec122181c0890bd16e9d3e7516a
681 $ hg debugrename cc
682 cc not renamed
683 $ HGEDITOR="sh .hg/checkeditform.sh" hg ci --amend -m 'merge bar (amend message)' --edit
684 HGEDITFORM=commit.amend.merge
685 $ hg log --config diff.git=1 -pr .
686 changeset: 21:4b0631ef043e
687 tag: tip
688 parent: 19:30d96aeaf27b
689 parent: 18:1aa437659d19
690 user: test
691 date: Thu Jan 01 00:00:00 1970 +0000
692 summary: merge bar (amend message)
693
694 diff --git a/a b/aa
695 copy from a
696 copy to aa
697 diff --git a/cc b/cc
698 --- a/cc
699 +++ b/cc
700 @@ -1,1 +1,5 @@
701 +<<<<<<< working copy: 30d96aeaf27b - test: aa
702 dd
703 +=======
704 +cc
705 +>>>>>>> merge rev: 1aa437659d19 bar - test: aazzcc
706 diff --git a/z b/zz
707 rename from z
708 rename to zz
709
710 $ hg debugrename aa
711 aa renamed from a:a80d06849b333b8a3d5c445f8ba3142010dcdc9e
712 $ hg debugrename zz
713 zz renamed from z:69a1b67522704ec122181c0890bd16e9d3e7516a
714 $ hg debugrename cc
715 cc not renamed
716 $ hg mv zz z
717 $ hg ci --amend -m 'merge bar (undo rename)'
718 $ hg log --config diff.git=1 -pr .
719 changeset: 22:06423be42d60
720 tag: tip
721 parent: 19:30d96aeaf27b
722 parent: 18:1aa437659d19
723 user: test
724 date: Thu Jan 01 00:00:00 1970 +0000
725 summary: merge bar (undo rename)
726
727 diff --git a/a b/aa
728 copy from a
729 copy to aa
730 diff --git a/cc b/cc
731 --- a/cc
732 +++ b/cc
733 @@ -1,1 +1,5 @@
734 +<<<<<<< working copy: 30d96aeaf27b - test: aa
735 dd
736 +=======
737 +cc
738 +>>>>>>> merge rev: 1aa437659d19 bar - test: aazzcc
739
740 $ hg debugrename z
741 z not renamed
742
743 Amend a merge changeset (with renames during the merge):
744
745 $ hg up -q bar
746 $ echo x > x
747 $ hg add x
748 $ hg ci -m x
749 $ hg up -q default
750 $ hg merge -q bar
751 $ hg mv aa aaa
752 $ echo aa >> aaa
753 $ hg ci -m 'merge bar again'
754 $ hg log --config diff.git=1 -pr .
755 changeset: 24:a89974a20457
756 tag: tip
757 parent: 22:06423be42d60
758 parent: 23:4c94d5bc65f5
759 user: test
760 date: Thu Jan 01 00:00:00 1970 +0000
761 summary: merge bar again
762
763 diff --git a/aa b/aa
764 deleted file mode 100644
765 --- a/aa
766 +++ /dev/null
767 @@ -1,2 +0,0 @@
768 -a
769 -a
770 diff --git a/aaa b/aaa
771 new file mode 100644
772 --- /dev/null
773 +++ b/aaa
774 @@ -0,0 +1,3 @@
775 +a
776 +a
777 +aa
778 diff --git a/x b/x
779 new file mode 100644
780 --- /dev/null
781 +++ b/x
782 @@ -0,0 +1,1 @@
783 +x
784
785 $ hg debugrename aaa
786 aaa renamed from aa:37d9b5d994eab34eda9c16b195ace52c7b129980
787
788 Update to p1 with 'aaa' modified. 'aaa' was renamed from 'aa' in p2. 'aa' exists
789 in p1 too, but it was recorded as copied from p2.
790 $ echo modified >> aaa
791 $ hg co -m '.^' -t :merge3
792 file 'aaa' was deleted in other [destination] but was modified in local [working copy].
793 You can use (c)hanged version, (d)elete, or leave (u)nresolved.
794 What do you want to do? u
795 1 files updated, 0 files merged, 1 files removed, 1 files unresolved
796 use 'hg resolve' to retry unresolved file merges
797 [1]
798 $ hg co -C tip
799 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
800
801 $ hg mv aaa aa
802 $ hg ci --amend -m 'merge bar again (undo rename)'
803 $ hg log --config diff.git=1 -pr .
804 changeset: 25:282080768800
805 tag: tip
806 parent: 22:06423be42d60
807 parent: 23:4c94d5bc65f5
808 user: test
809 date: Thu Jan 01 00:00:00 1970 +0000
810 summary: merge bar again (undo rename)
811
812 diff --git a/aa b/aa
813 --- a/aa
814 +++ b/aa
815 @@ -1,2 +1,3 @@
816 a
817 a
818 +aa
819 diff --git a/x b/x
820 new file mode 100644
821 --- /dev/null
822 +++ b/x
823 @@ -0,0 +1,1 @@
824 +x
825
826 $ hg debugrename aa
827 aa not renamed
828 $ hg debugrename -r '.^' aa
829 aa renamed from a:a80d06849b333b8a3d5c445f8ba3142010dcdc9e
830
831 Amend a merge changeset (with manifest-level conflicts):
832
833 $ hg up -q bar
834 $ hg rm aa
835 $ hg ci -m 'rm aa'
836 $ hg up -q default
837 $ echo aa >> aa
838 $ hg ci -m aa
839 $ hg merge -q bar --config ui.interactive=True << EOF
840 > c
841 > EOF
842 file 'aa' was deleted in other [merge rev] but was modified in local [working copy].
843 You can use (c)hanged version, (d)elete, or leave (u)nresolved.
844 What do you want to do? c
845 $ hg ci -m 'merge bar (with conflicts)'
846 $ hg log --config diff.git=1 -pr .
847 changeset: 28:ed15db12298d
848 tag: tip
849 parent: 27:eb5adec0b43b
850 parent: 26:67db8847a540
851 user: test
852 date: Thu Jan 01 00:00:00 1970 +0000
853 summary: merge bar (with conflicts)
854
855
856 $ hg rm aa
857 $ hg ci --amend -m 'merge bar (with conflicts, amended)'
858 $ hg log --config diff.git=1 -pr .
859 changeset: 29:0eeafd043f63
860 tag: tip
861 parent: 27:eb5adec0b43b
862 parent: 26:67db8847a540
863 user: test
864 date: Thu Jan 01 00:00:00 1970 +0000
865 summary: merge bar (with conflicts, amended)
866
867 diff --git a/aa b/aa
868 deleted file mode 100644
869 --- a/aa
870 +++ /dev/null
871 @@ -1,4 +0,0 @@
872 -a
873 -a
874 -aa
875 -aa
876
877 Issue 3445: amending with --close-branch a commit that created a new head should fail
878 This shouldn't be possible:
879
880 $ hg up -q default
881 $ hg branch closewithamend
882 marked working directory as branch closewithamend
883 $ echo foo > foo
884 $ hg add foo
885 $ hg ci -m..
886 $ hg ci --amend --close-branch -m 'closing'
887 abort: can only close branch heads
888 [10]
889
890 This silliness fails:
891
892 $ hg branch silliness
893 marked working directory as branch silliness
894 $ echo b >> b
895 $ hg ci --close-branch -m'open and close'
896 abort: branch "silliness" has no heads to close
897 [10]
898
899 Test that amend with --secret creates new secret changeset forcibly
900 ---------------------------------------------------------------------
901
902 $ hg phase '.^::.'
903 29: draft
904 30: draft
905 $ hg commit --amend --secret -m 'amend as secret' -q
906 $ hg phase '.^::.'
907 29: draft
908 31: secret
909
910 Test that amend with --edit invokes editor forcibly
911 ---------------------------------------------------
912
913 $ hg parents --template "{desc}\n"
914 amend as secret
915 $ HGEDITOR=cat hg commit --amend -m "editor should be suppressed"
916 $ hg parents --template "{desc}\n"
917 editor should be suppressed
918
919 $ hg status --rev '.^1::.'
920 A foo
921 $ HGEDITOR=cat hg commit --amend -m "editor should be invoked" --edit
922 editor should be invoked
923
924
925 HG: Enter commit message. Lines beginning with 'HG:' are removed.
926 HG: Leave message empty to abort commit.
927 HG: --
928 HG: user: test
929 HG: branch 'silliness'
930 HG: added foo
931 $ hg parents --template "{desc}\n"
932 editor should be invoked
933
934 Test that amend with --no-edit avoids the editor
935 ------------------------------------------------
936
937 $ hg commit --amend -m "before anything happens"
938 $ hg parents --template "{desc}\n"
939 before anything happens
940 $ HGEDITOR=cat hg commit --amend --no-edit -m "editor should be suppressed"
941 $ hg parents --template "{desc}\n"
942 editor should be suppressed
943
944 (We need a file change here since we won't have a message change)
945 $ cp foo foo.orig
946 $ echo hi >> foo
947 $ HGEDITOR=cat hg commit --amend --no-edit
948 $ hg parents --template "{desc}\n"
949 editor should be suppressed
950 $ hg status -mar
951 (Let's undo adding that "hi" so later tests don't need to be adjusted)
952 $ mv foo.orig foo
953 $ hg commit --amend --no-edit
954
955 Test that "diff()" in committemplate works correctly for amending
956 -----------------------------------------------------------------
957
958 $ cat >> .hg/hgrc <<EOF
959 > [committemplate]
960 > changeset.commit.amend = {desc}\n
961 > HG: {revset('parents()') % 'parent: {desc|firstline}\n'}
962 > HG: M: {file_mods}
963 > HG: A: {file_adds}
964 > HG: R: {file_dels}
965 > {splitlines(diff()) % 'HG: {line}\n'}
966 > EOF
967
968 $ hg parents --template "M: {file_mods}\nA: {file_adds}\nR: {file_dels}\n"
969 M:
970 A: foo
971 R:
972 $ hg status -amr
973 $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo"
974 expecting diff of foo
975
976 HG: parent: editor should be suppressed
977
978 HG: M:
979 HG: A: foo
980 HG: R:
981 HG: diff -r 0eeafd043f63 foo
982 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
983 HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000
984 HG: @@ -0,0 +1,1 @@
985 HG: +foo
986
987 $ echo y > y
988 $ hg add y
989 $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of foo and y"
990 expecting diff of foo and y
991
992 HG: parent: expecting diff of foo
993
994 HG: M:
995 HG: A: foo y
996 HG: R:
997 HG: diff -r 0eeafd043f63 foo
998 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
999 HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000
1000 HG: @@ -0,0 +1,1 @@
1001 HG: +foo
1002 HG: diff -r 0eeafd043f63 y
1003 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1004 HG: +++ b/y Thu Jan 01 00:00:00 1970 +0000
1005 HG: @@ -0,0 +1,1 @@
1006 HG: +y
1007
1008 $ hg rm a
1009 $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo and y"
1010 expecting diff of a, foo and y
1011
1012 HG: parent: expecting diff of foo and y
1013
1014 HG: M:
1015 HG: A: foo y
1016 HG: R: a
1017 HG: diff -r 0eeafd043f63 a
1018 HG: --- a/a Thu Jan 01 00:00:00 1970 +0000
1019 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1020 HG: @@ -1,2 +0,0 @@
1021 HG: -a
1022 HG: -a
1023 HG: diff -r 0eeafd043f63 foo
1024 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1025 HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000
1026 HG: @@ -0,0 +1,1 @@
1027 HG: +foo
1028 HG: diff -r 0eeafd043f63 y
1029 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1030 HG: +++ b/y Thu Jan 01 00:00:00 1970 +0000
1031 HG: @@ -0,0 +1,1 @@
1032 HG: +y
1033
1034 $ hg rm x
1035 $ HGEDITOR=cat hg commit --amend -e -m "expecting diff of a, foo, x and y"
1036 expecting diff of a, foo, x and y
1037
1038 HG: parent: expecting diff of a, foo and y
1039
1040 HG: M:
1041 HG: A: foo y
1042 HG: R: a x
1043 HG: diff -r 0eeafd043f63 a
1044 HG: --- a/a Thu Jan 01 00:00:00 1970 +0000
1045 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1046 HG: @@ -1,2 +0,0 @@
1047 HG: -a
1048 HG: -a
1049 HG: diff -r 0eeafd043f63 foo
1050 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1051 HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000
1052 HG: @@ -0,0 +1,1 @@
1053 HG: +foo
1054 HG: diff -r 0eeafd043f63 x
1055 HG: --- a/x Thu Jan 01 00:00:00 1970 +0000
1056 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1057 HG: @@ -1,1 +0,0 @@
1058 HG: -x
1059 HG: diff -r 0eeafd043f63 y
1060 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1061 HG: +++ b/y Thu Jan 01 00:00:00 1970 +0000
1062 HG: @@ -0,0 +1,1 @@
1063 HG: +y
1064
1065 $ echo cccc >> cc
1066 $ hg status -amr
1067 M cc
1068 $ HGEDITOR=cat hg commit --amend -e -m "cc should be excluded" -X cc
1069 cc should be excluded
1070
1071 HG: parent: expecting diff of a, foo, x and y
1072
1073 HG: M:
1074 HG: A: foo y
1075 HG: R: a x
1076 HG: diff -r 0eeafd043f63 a
1077 HG: --- a/a Thu Jan 01 00:00:00 1970 +0000
1078 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1079 HG: @@ -1,2 +0,0 @@
1080 HG: -a
1081 HG: -a
1082 HG: diff -r 0eeafd043f63 foo
1083 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1084 HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000
1085 HG: @@ -0,0 +1,1 @@
1086 HG: +foo
1087 HG: diff -r 0eeafd043f63 x
1088 HG: --- a/x Thu Jan 01 00:00:00 1970 +0000
1089 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1090 HG: @@ -1,1 +0,0 @@
1091 HG: -x
1092 HG: diff -r 0eeafd043f63 y
1093 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1094 HG: +++ b/y Thu Jan 01 00:00:00 1970 +0000
1095 HG: @@ -0,0 +1,1 @@
1096 HG: +y
1097
1098 Check for issue4405
1099 -------------------
1100
1101 Setup the repo with a file that gets moved in a second commit.
1102 $ hg init repo
1103 $ cd repo
1104 $ touch a0
1105 $ hg add a0
1106 $ hg commit -m a0
1107 $ hg mv a0 a1
1108 $ hg commit -m a1
1109 $ hg up -q 0
1110 $ hg log -G --template '{rev} {desc}'
1111 o 1 a1
1112 |
1113 @ 0 a0
1114
1115
1116 Now we branch the repro, but re-use the file contents, so we have a divergence
1117 in the file revlog topology and the changelog topology.
1118 $ hg revert --rev 1 --all
1119 removing a0
1120 adding a1
1121 $ hg ci -qm 'a1-amend'
1122 $ hg log -G --template '{rev} {desc}'
1123 @ 2 a1-amend
1124 |
1125 | o 1 a1
1126 |/
1127 o 0 a0
1128
1129
1130 The way mercurial does amends is by folding the working copy and old commit
1131 together into another commit (rev 3). During this process, _findlimit is called
1132 to check how far back to look for the transitive closure of file copy
1133 information, but due to the divergence of the filelog and changelog graph
1134 topologies, before _findlimit was fixed, it returned a rev which was not far
1135 enough back in this case.
1136 $ hg mv a1 a2
1137 $ hg status --copies --rev 0
1138 A a2
1139 a0
1140 R a0
1141 $ hg ci --amend -q
1142 $ hg log -G --template '{rev} {desc}'
1143 @ 3 a1-amend
1144 |
1145 | o 1 a1
1146 |/
1147 o 0 a0
1148
1149
1150 Before the fix, the copy information was lost.
1151 $ hg status --copies --rev 0
1152 A a2
1153 a0
1154 R a0
1155 $ cd ..
1156
1157 Check that amend properly preserve rename from directory rename (issue-4516)
1158
1159 If a parent of the merge renames a full directory, any files added to the old
1160 directory in the other parent will be renamed to the new directory. For some
1161 reason, the rename metadata was when amending such merge. This test ensure we
1162 do not regress. We have a dedicated repo because it needs a setup with renamed
1163 directory)
1164
1165 $ hg init issue4516
1166 $ cd issue4516
1167 $ mkdir olddirname
1168 $ echo line1 > olddirname/commonfile.py
1169 $ hg add olddirname/commonfile.py
1170 $ hg ci -m first
1171
1172 $ hg branch newdirname
1173 marked working directory as branch newdirname
1174 (branches are permanent and global, did you want a bookmark?)
1175 $ hg mv olddirname newdirname
1176 moving olddirname/commonfile.py to newdirname/commonfile.py
1177 $ hg ci -m rename
1178
1179 $ hg update default
1180 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1181 $ echo line1 > olddirname/newfile.py
1182 $ hg add olddirname/newfile.py
1183 $ hg ci -m log
1184
1185 $ hg up newdirname
1186 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
1187 $ # create newdirname/newfile.py
1188 $ hg merge default
1189 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1190 (branch merge, don't forget to commit)
1191 $ hg ci -m add
1192 $
1193 $ hg debugrename newdirname/newfile.py
1194 newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
1195 $ hg status -C --change .
1196 A newdirname/newfile.py
1197 $ hg status -C --rev 1
1198 A newdirname/newfile.py
1199 $ hg status -C --rev 2
1200 A newdirname/commonfile.py
1201 olddirname/commonfile.py
1202 A newdirname/newfile.py
1203 olddirname/newfile.py
1204 R olddirname/commonfile.py
1205 R olddirname/newfile.py
1206 $ hg debugindex newdirname/newfile.py
1207 rev linkrev nodeid p1-nodeid p2-nodeid
1208 0 3 34a4d536c0c0 000000000000 000000000000
1209
1210 $ echo a >> newdirname/commonfile.py
1211 $ hg ci --amend -m bug
1212 $ hg debugrename newdirname/newfile.py
1213 newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
1214 $ hg debugindex newdirname/newfile.py
1215 rev linkrev nodeid p1-nodeid p2-nodeid
1216 0 3 34a4d536c0c0 000000000000 000000000000
1217
1218 #if execbit
1219
1220 Test if amend preserves executable bit changes
1221 $ chmod +x newdirname/commonfile.py
1222 $ hg ci -m chmod
1223 $ hg ci --amend -m "chmod amended"
1224 $ hg ci --amend -m "chmod amended second time"
1225 $ hg log -p --git -r .
1226 changeset: 7:b1326f52dddf
1227 branch: newdirname
1228 tag: tip
1229 parent: 4:7fd235f7cb2f
1230 user: test
1231 date: Thu Jan 01 00:00:00 1970 +0000
1232 summary: chmod amended second time
1233
1234 diff --git a/newdirname/commonfile.py b/newdirname/commonfile.py
1235 old mode 100644
1236 new mode 100755
1237
1238 #endif
1239
1240 Test amend with file inclusion options
1241 --------------------------------------
1242
1243 These tests ensure that we are always amending some files that were part of the
1244 pre-amend commit. We want to test that the remaining files in the pre-amend
1245 commit were not changed in the amended commit. We do so by performing a diff of
1246 the amended commit against its parent commit.
1247 $ cd ..
1248 $ hg init testfileinclusions
1249 $ cd testfileinclusions
1250 $ echo a > a
1251 $ echo b > b
1252 $ hg commit -Aqm "Adding a and b"
1253
1254 Only add changes to a particular file
1255 $ echo a >> a
1256 $ echo b >> b
1257 $ hg commit --amend -I a
1258 $ hg diff --git -r null -r .
1259 diff --git a/a b/a
1260 new file mode 100644
1261 --- /dev/null
1262 +++ b/a
1263 @@ -0,0 +1,2 @@
1264 +a
1265 +a
1266 diff --git a/b b/b
1267 new file mode 100644
1268 --- /dev/null
1269 +++ b/b
1270 @@ -0,0 +1,1 @@
1271 +b
1272
1273 $ echo a >> a
1274 $ hg commit --amend b
1275 $ hg diff --git -r null -r .
1276 diff --git a/a b/a
1277 new file mode 100644
1278 --- /dev/null
1279 +++ b/a
1280 @@ -0,0 +1,2 @@
1281 +a
1282 +a
1283 diff --git a/b b/b
1284 new file mode 100644
1285 --- /dev/null
1286 +++ b/b
1287 @@ -0,0 +1,2 @@
1288 +b
1289 +b
1290
1291 Exclude changes to a particular file
1292 $ echo b >> b
1293 $ hg commit --amend -X a
1294 $ hg diff --git -r null -r .
1295 diff --git a/a b/a
1296 new file mode 100644
1297 --- /dev/null
1298 +++ b/a
1299 @@ -0,0 +1,2 @@
1300 +a
1301 +a
1302 diff --git a/b b/b
1303 new file mode 100644
1304 --- /dev/null
1305 +++ b/b
1306 @@ -0,0 +1,3 @@
1307 +b
1308 +b
1309 +b
1310
1311 Check the addremove flag
1312 $ echo c > c
1313 $ rm a
1314 $ hg commit --amend -A
1315 removing a
1316 adding c
1317 $ hg diff --git -r null -r .
1318 diff --git a/b b/b
1319 new file mode 100644
1320 --- /dev/null
1321 +++ b/b
1322 @@ -0,0 +1,3 @@
1323 +b
1324 +b
1325 +b
1326 diff --git a/c b/c
1327 new file mode 100644
1328 --- /dev/null
1329 +++ b/c
1330 @@ -0,0 +1,1 @@
1331 +c