Debian Codegraph @

tests/test-histedit-edit.t

raw
1 $ . "$TESTDIR/histedit-helpers.sh"
2
3 $ cat >> $HGRCPATH <<EOF
4 > [extensions]
5 > histedit=
6 > strip=
7 > mockmakedate = $TESTDIR/mockmakedate.py
8 > EOF
9
10 $ initrepo ()
11 > {
12 > hg init r
13 > cd r
14 > for x in a b c d e f g; do
15 > echo $x > $x
16 > hg add $x
17 > hg ci -m $x
18 > done
19 > }
20
21 $ initrepo
22
23 log before edit
24 $ hg log --graph
25 @ changeset: 6:3c6a8ed2ebe8
26 | tag: tip
27 | user: test
28 | date: Thu Jan 01 00:00:00 1970 +0000
29 | summary: g
30 |
31 o changeset: 5:652413bf663e
32 | user: test
33 | date: Thu Jan 01 00:00:00 1970 +0000
34 | summary: f
35 |
36 o changeset: 4:e860deea161a
37 | user: test
38 | date: Thu Jan 01 00:00:00 1970 +0000
39 | summary: e
40 |
41 o changeset: 3:055a42cdd887
42 | user: test
43 | date: Thu Jan 01 00:00:00 1970 +0000
44 | summary: d
45 |
46 o changeset: 2:177f92b77385
47 | user: test
48 | date: Thu Jan 01 00:00:00 1970 +0000
49 | summary: c
50 |
51 o changeset: 1:d2ae7f538514
52 | user: test
53 | date: Thu Jan 01 00:00:00 1970 +0000
54 | summary: b
55 |
56 o changeset: 0:cb9a9f314b8b
57 user: test
58 date: Thu Jan 01 00:00:00 1970 +0000
59 summary: a
60
61 dirty a file
62 $ echo a > g
63 $ hg histedit 177f92b77385 --commands - 2>&1 << EOF
64 > EOF
65 abort: uncommitted changes
66 [20]
67 $ echo g > g
68
69 edit the history
70 $ hg histedit 177f92b77385 --commands - 2>&1 << EOF| fixbundle
71 > pick 177f92b77385 c
72 > pick 055a42cdd887 d
73 > edit e860deea161a e
74 > pick 652413bf663e f
75 > pick 3c6a8ed2ebe8 g
76 > EOF
77 0 files updated, 0 files merged, 3 files removed, 0 files unresolved
78 Editing (e860deea161a), commit as needed now to split the change
79 (to edit e860deea161a, `hg histedit --continue` after making changes)
80
81 try to update and get an error
82 $ hg update tip
83 abort: histedit in progress
84 (use 'hg histedit --continue' or 'hg histedit --abort')
85 [20]
86
87 edit the plan via the editor
88 $ cat >> $TESTTMP/editplan.sh <<EOF
89 > cat > \$1 <<EOF2
90 > drop e860deea161a e
91 > drop 652413bf663e f
92 > drop 3c6a8ed2ebe8 g
93 > EOF2
94 > EOF
95 $ HGEDITOR="sh $TESTTMP/editplan.sh" hg histedit --edit-plan
96 $ cat .hg/histedit-state
97 v1
98 055a42cdd88768532f9cf79daa407fc8d138de9b
99 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
100 False
101 3
102 drop
103 e860deea161a2f77de56603b340ebbb4536308ae
104 drop
105 652413bf663ef2a641cab26574e46d5f5a64a55a
106 drop
107 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
108 0
109 strip-backup/177f92b77385-0ebe6a8f-histedit.hg
110
111 edit the plan via --commands
112 $ hg histedit --edit-plan --commands - 2>&1 << EOF
113 > edit e860deea161a e
114 > pick 652413bf663e f
115 > drop 3c6a8ed2ebe8 g
116 > EOF
117 $ cat .hg/histedit-state
118 v1
119 055a42cdd88768532f9cf79daa407fc8d138de9b
120 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
121 False
122 3
123 edit
124 e860deea161a2f77de56603b340ebbb4536308ae
125 pick
126 652413bf663ef2a641cab26574e46d5f5a64a55a
127 drop
128 3c6a8ed2ebe862cc949d2caa30775dd6f16fb799
129 0
130 strip-backup/177f92b77385-0ebe6a8f-histedit.hg
131
132 Go at a random point and try to continue
133
134 $ hg id -n
135 3+
136 $ hg up 0
137 abort: histedit in progress
138 (use 'hg histedit --continue' or 'hg histedit --abort')
139 [20]
140
141 Try to delete necessary commit
142 $ hg strip -r 652413b
143 abort: histedit in progress, can't strip 652413bf663e
144 [255]
145
146 commit, then edit the revision
147 $ hg ci -m 'wat'
148 created new head
149 $ echo a > e
150
151 qnew should fail while we're in the middle of the edit step
152
153 $ hg --config extensions.mq= qnew please-fail
154 abort: histedit in progress
155 (use 'hg histedit --continue' or 'hg histedit --abort')
156 [20]
157 $ HGEDITOR='echo foobaz > ' hg histedit --continue 2>&1 | fixbundle
158
159 $ hg log --graph
160 @ changeset: 6:b5f70786f9b0
161 | tag: tip
162 | user: test
163 | date: Thu Jan 01 00:00:00 1970 +0000
164 | summary: f
165 |
166 o changeset: 5:a5e1ba2f7afb
167 | user: test
168 | date: Thu Jan 01 00:00:00 1970 +0000
169 | summary: foobaz
170 |
171 o changeset: 4:1a60820cd1f6
172 | user: test
173 | date: Thu Jan 01 00:00:00 1970 +0000
174 | summary: wat
175 |
176 o changeset: 3:055a42cdd887
177 | user: test
178 | date: Thu Jan 01 00:00:00 1970 +0000
179 | summary: d
180 |
181 o changeset: 2:177f92b77385
182 | user: test
183 | date: Thu Jan 01 00:00:00 1970 +0000
184 | summary: c
185 |
186 o changeset: 1:d2ae7f538514
187 | user: test
188 | date: Thu Jan 01 00:00:00 1970 +0000
189 | summary: b
190 |
191 o changeset: 0:cb9a9f314b8b
192 user: test
193 date: Thu Jan 01 00:00:00 1970 +0000
194 summary: a
195
196
197 $ hg cat e
198 a
199
200 Stripping necessary commits should not break --abort
201
202 $ hg histedit 1a60820cd1f6 --commands - 2>&1 << EOF| fixbundle
203 > edit 1a60820cd1f6 wat
204 > pick a5e1ba2f7afb foobaz
205 > pick b5f70786f9b0 g
206 > EOF
207 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
208 Editing (1a60820cd1f6), commit as needed now to split the change
209 (to edit 1a60820cd1f6, `hg histedit --continue` after making changes)
210
211 $ mv .hg/histedit-state .hg/histedit-state.bak
212 $ hg strip -q -r b5f70786f9b0
213 $ mv .hg/histedit-state.bak .hg/histedit-state
214 $ hg histedit --abort
215 adding changesets
216 adding manifests
217 adding file changes
218 added 1 changesets with 1 changes to 3 files
219 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
220 $ hg log -r .
221 changeset: 6:b5f70786f9b0
222 tag: tip
223 user: test
224 date: Thu Jan 01 00:00:00 1970 +0000
225 summary: f
226
227
228 check histedit_source
229
230 $ hg log --debug --rev 5
231 changeset: 5:a5e1ba2f7afb899ef1581cea528fd885d2fca70d
232 phase: draft
233 parent: 4:1a60820cd1f6004a362aa622ebc47d59bc48eb34
234 parent: -1:0000000000000000000000000000000000000000
235 manifest: 5:5ad3be8791f39117565557781f5464363b918a45
236 user: test
237 date: Thu Jan 01 00:00:00 1970 +0000
238 files: e
239 extra: branch=default
240 extra: histedit_source=e860deea161a2f77de56603b340ebbb4536308ae
241 description:
242 foobaz
243
244
245
246 $ hg histedit tip --commands - 2>&1 <<EOF| fixbundle
247 > edit b5f70786f9b0 f
248 > EOF
249 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
250 Editing (b5f70786f9b0), commit as needed now to split the change
251 (to edit b5f70786f9b0, `hg histedit --continue` after making changes)
252 $ hg status
253 A f
254
255 $ hg summary
256 parent: 5:a5e1ba2f7afb
257 foobaz
258 branch: default
259 commit: 1 added (new branch head)
260 update: 1 new changesets (update)
261 phases: 7 draft
262 hist: 1 remaining (histedit --continue)
263
264 (test also that editor is invoked if histedit is continued for
265 "edit" action)
266
267 $ HGEDITOR='cat' hg continue
268 f
269
270
271 HG: Enter commit message. Lines beginning with 'HG:' are removed.
272 HG: Leave message empty to abort commit.
273 HG: --
274 HG: user: test
275 HG: branch 'default'
276 HG: added f
277 saved backup bundle to $TESTTMP/r/.hg/strip-backup/b5f70786f9b0-c28d9c86-histedit.hg
278
279 $ hg status
280
281 log after edit
282 $ hg log --limit 1
283 changeset: 6:a107ee126658
284 tag: tip
285 user: test
286 date: Thu Jan 01 00:00:00 1970 +0000
287 summary: f
288
289
290 say we'll change the message, but don't.
291 $ cat > ../edit.sh <<EOF
292 > cat "\$1" | sed s/pick/mess/ > tmp
293 > mv tmp "\$1"
294 > EOF
295 $ HGEDITOR="sh ../edit.sh" hg histedit tip 2>&1 | fixbundle
296 $ hg status
297 $ hg log --limit 1
298 changeset: 6:1fd3b2fe7754
299 tag: tip
300 user: test
301 date: Thu Jan 01 00:00:00 1970 +0000
302 summary: f
303
304
305 modify the message
306
307 check saving last-message.txt, at first
308
309 $ cat > $TESTTMP/commitfailure.py <<EOF
310 > from mercurial import error
311 > def reposetup(ui, repo):
312 > class commitfailure(repo.__class__):
313 > def commit(self, *args, **kwargs):
314 > raise error.Abort(b'emulating unexpected abort')
315 > repo.__class__ = commitfailure
316 > EOF
317 $ cat >> .hg/hgrc <<EOF
318 > [extensions]
319 > # this failure occurs before editor invocation
320 > commitfailure = $TESTTMP/commitfailure.py
321 > EOF
322
323 $ cat > $TESTTMP/editor.sh <<EOF
324 > echo "==== before editing"
325 > cat \$1
326 > echo "===="
327 > echo "check saving last-message.txt" >> \$1
328 > EOF
329
330 (test that editor is not invoked before transaction starting)
331
332 $ rm -f .hg/last-message.txt
333 $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit tip --commands - 2>&1 << EOF | fixbundle
334 > mess 1fd3b2fe7754 f
335 > EOF
336 abort: emulating unexpected abort
337 $ test -f .hg/last-message.txt
338 [1]
339
340 $ cat >> .hg/hgrc <<EOF
341 > [extensions]
342 > commitfailure = !
343 > EOF
344 $ hg histedit --abort -q
345
346 (test that editor is invoked and commit message is saved into
347 "last-message.txt")
348
349 $ cat >> .hg/hgrc <<EOF
350 > [hooks]
351 > # this failure occurs after editor invocation
352 > pretxncommit.unexpectedabort = false
353 > EOF
354
355 $ hg status --rev '1fd3b2fe7754^1' --rev 1fd3b2fe7754
356 A f
357
358 $ rm -f .hg/last-message.txt
359 $ mkdir dir
360 $ cd dir
361 $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit tip --commands - 2>&1 << EOF
362 > mess 1fd3b2fe7754 f
363 > EOF
364 ==== before editing
365 f
366
367
368 HG: Enter commit message. Lines beginning with 'HG:' are removed.
369 HG: Leave message empty to abort commit.
370 HG: --
371 HG: user: test
372 HG: branch 'default'
373 HG: added f
374 ====
375 transaction abort!
376 rollback completed
377 note: commit message saved in ../.hg/last-message.txt
378 note: use 'hg commit --logfile ../.hg/last-message.txt --edit' to reuse it
379 abort: pretxncommit.unexpectedabort hook exited with status 1
380 [40]
381 $ cd ..
382 $ cat .hg/last-message.txt
383 f
384
385
386 check saving last-message.txt
387
388 (test also that editor is invoked if histedit is continued for "message"
389 action)
390
391 $ HGEDITOR=cat hg histedit --continue
392 f
393
394
395 HG: Enter commit message. Lines beginning with 'HG:' are removed.
396 HG: Leave message empty to abort commit.
397 HG: --
398 HG: user: test
399 HG: branch 'default'
400 HG: added f
401 transaction abort!
402 rollback completed
403 note: commit message saved in .hg/last-message.txt
404 note: use 'hg commit --logfile .hg/last-message.txt --edit' to reuse it
405 abort: pretxncommit.unexpectedabort hook exited with status 1
406 [40]
407
408 $ cat >> .hg/hgrc <<EOF
409 > [hooks]
410 > pretxncommit.unexpectedabort =
411 > EOF
412 $ hg histedit --abort -q
413
414 then, check "modify the message" itself
415
416 $ hg histedit tip --commands - 2>&1 << EOF | fixbundle
417 > mess 1fd3b2fe7754 f
418 > EOF
419 $ hg status
420 $ hg log --limit 1
421 changeset: 6:62feedb1200e
422 tag: tip
423 user: test
424 date: Thu Jan 01 00:00:00 1970 +0000
425 summary: f
426
427
428 rollback should not work after a histedit
429 $ hg rollback
430 no rollback information available
431 [1]
432
433 $ cd ..
434 $ hg clone -qr0 r r0
435 $ cd r0
436 $ hg phase -fdr0
437 $ hg histedit --commands - 0 2>&1 << EOF
438 > edit cb9a9f314b8b a > $EDITED
439 > EOF
440 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
441 Editing (cb9a9f314b8b), commit as needed now to split the change
442 (to edit cb9a9f314b8b, `hg histedit --continue` after making changes)
443 [240]
444 $ HGEDITOR=true hg continue
445 saved backup bundle to $TESTTMP/r0/.hg/strip-backup/cb9a9f314b8b-cc5ccb0b-histedit.hg
446
447 $ hg log -G
448 @ changeset: 0:0efcea34f18a
449 tag: tip
450 user: test
451 date: Thu Jan 01 00:00:00 1970 +0000
452 summary: a
453
454 $ echo foo >> b
455 $ hg addr
456 adding b
457 $ hg ci -m 'add b'
458 $ echo foo >> a
459 $ hg ci -m 'extend a'
460 $ hg phase --public 1
461 Attempting to fold a change into a public change should not work:
462 $ cat > ../edit.sh <<EOF
463 > cat "\$1" | sed s/pick/fold/ > tmp
464 > mv tmp "\$1"
465 > EOF
466 $ HGEDITOR="sh ../edit.sh" hg histedit 2
467 warning: histedit rules saved to: .hg/histedit-last-edit.txt
468 hg: parse error: first changeset cannot use verb "fold"
469 [10]
470 $ cat .hg/histedit-last-edit.txt
471 fold 0012be4a27ea 2 extend a
472
473 # Edit history between 0012be4a27ea and 0012be4a27ea
474 #
475 # Commits are listed from least to most recent
476 #
477 # You can reorder changesets by reordering the lines
478 #
479 # Commands:
480 #
481 # e, edit = use commit, but allow edits before making new commit
482 # m, mess = edit commit message without changing commit content
483 # p, fold = use commit
484 # b, base = checkout changeset and apply further changesets from there
485 # d, drop = remove commit from history
486 # f, fold = use commit, but combine it with the one above
487 # r, roll = like fold, but discard this commit's description and date
488 #
489
490 $ cd ..
491
492 ============================================
493 Test update-timestamp config option in mess|
494 ============================================
495
496 $ addwithdate ()
497 > {
498 > echo $1 > $1
499 > hg add $1
500 > hg ci -m $1 -d "$2 0"
501 > }
502
503 $ initrepo ()
504 > {
505 > hg init r2
506 > cd r2
507 > addwithdate a 1
508 > addwithdate b 2
509 > addwithdate c 3
510 > addwithdate d 4
511 > addwithdate e 5
512 > addwithdate f 6
513 > }
514
515 $ initrepo
516
517 log before edit
518
519 $ hg log --limit 1
520 changeset: 5:178e35e0ce73
521 tag: tip
522 user: test
523 date: Thu Jan 01 00:00:06 1970 +0000
524 summary: f
525
526 $ hg histedit tip --commands - 2>&1 --config rewrite.update-timestamp=True << EOF | fixbundle
527 > mess 178e35e0ce73 f
528 > EOF
529
530 log after edit
531
532 $ hg log --limit 1
533 changeset: 5:98bf456d476b
534 tag: tip
535 user: test
536 date: Thu Jan 01 00:00:00 1970 +0000
537 summary: f
538
539
540 $ cd ..
541
542 warn the user on editing tagged commits
543
544 $ hg init issue4017
545 $ cd issue4017
546 $ echo > a
547 $ hg ci -Am 'add a'
548 adding a
549 $ hg tag a
550 $ hg tags
551 tip 1:bd7ee4f3939b
552 a 0:a8a82d372bb3
553 $ hg histedit
554 warning: tags associated with the given changeset will be lost after histedit.
555 do you want to continue (yN)? n
556 abort: histedit cancelled
557
558 [250]
559 $ cd ..