test-fold.t 11.4 KB
Newer Older
1
2
3
4
5
6
7
  $ . $TESTDIR/testlib/common.sh

setup

  $ cat >> $HGRCPATH <<EOF
  > [extensions]
  > evolve=
8
9
10
  > [alias]
  > glog = log -GT "{rev}: {desc}"
  > glf = log -GT "{rev}: {desc} ({files})"
11
  > [ui]
12
  > logtemplate = '{rev} - {node|short} {desc|firstline} [{author}] ({phase}) {bookmarks}\n'
13
14
15
16
17
18
19
  > EOF

  $ hg init fold-tests
  $ cd fold-tests/
  $ hg debugbuilddag .+3:branchpoint+4*branchpoint+2
  $ hg up 'desc("r7")'
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
20
  $ hg bookmark bm1
21
22
23
24
25
26
27
  $ hg log -G
  o  10 - a8407f9a3dc1 r10 [debugbuilddag] (draft)
  |
  o  9 - 529dfc5bb875 r9 [debugbuilddag] (draft)
  |
  o  8 - abf57d94268b r8 [debugbuilddag] (draft)
  |
28
  | @  7 - 4de32a90b66c r7 [debugbuilddag] (draft) bm1
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  | |
  | o  6 - f69452c5b1af r6 [debugbuilddag] (draft)
  | |
  | o  5 - c8d03c1b5e94 r5 [debugbuilddag] (draft)
  | |
  | o  4 - bebd167eb94d r4 [debugbuilddag] (draft)
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (draft)
  

Test various error case

47
48
49
  $ hg fold --exact null::
  abort: cannot fold the null revision
  (no changeset checked out)
50
  [10]
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  $ hg fold
  abort: no revisions specified
  [255]
  $ hg fold --from
  abort: no revisions specified
  [255]
  $ hg fold .
  abort: must specify either --from or --exact
  [255]
  $ hg fold --from . --exact
  abort: cannot use both --from and --exact
  [255]
  $ hg fold --from .
  single revision specified, nothing to fold
  [1]
  $ hg fold '0::(7+10)' --exact
  abort: cannot fold non-linear revisions (multiple heads given)
  [255]
  $ hg fold -r 4 -r 6 --exact
  abort: cannot fold non-linear revisions (multiple roots given)
  [255]
  $ hg fold --from 10 1
  abort: cannot fold non-linear revisions
  (given revisions are unrelated to parent of working directory)
  [255]
  $ hg fold --exact -r "4 and not 4"
  abort: specified revisions evaluate to an empty set
  (use different revision arguments)
  [255]
  $ hg phase --public 0
  $ hg fold --from -r 0
82
  abort: cannot fold public changesets: 1ea73414a91b
83
  (see 'hg help phases' for details)
84
  [10]
85
86
87
88
89
90

Test actual folding

  $ hg fold --from -r 'desc("r5")'
  3 changesets folded
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
91
92
93
94
  $ hg debugobsolete -r 'desc("r5")' --exclusive
  4de32a90b66cd083ebf3c00b41277aa7abca51dd 198b5c405d01a50c41a81a00fc61677b81981a5f 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '37', 'fold-id': '25cb328e', 'fold-idx': '3', 'fold-size': '3', 'operation': 'fold', 'user': 'test'}
  c8d03c1b5e94af74b772900c58259d2e08917735 198b5c405d01a50c41a81a00fc61677b81981a5f 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '33', 'fold-id': '25cb328e', 'fold-idx': '1', 'fold-size': '3', 'operation': 'fold', 'user': 'test'}
  f69452c5b1af6cbaaa56ef50cf94fff5bcc6ca23 198b5c405d01a50c41a81a00fc61677b81981a5f 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '37', 'fold-id': '25cb328e', 'fold-idx': '2', 'fold-size': '3', 'operation': 'fold', 'user': 'test'}
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  $ hg obslog --no-origin
  @    198b5c405d01 (11) r5
  |\
  | \
  | |\
  x | |  4de32a90b66c (7) r7
   / /     folded(description, date, parent) as 198b5c405d01 using fold by test (Thu Jan 01 00:00:00 1970 +0000)
  | |
  x |  c8d03c1b5e94 (5) r5
   /     folded(description, date) as 198b5c405d01 using fold by test (Thu Jan 01 00:00:00 1970 +0000)
  |
  x  f69452c5b1af (6) r6
       folded(description, date, parent) as 198b5c405d01 using fold by test (Thu Jan 01 00:00:00 1970 +0000)
  
  $ hg obslog
  @    198b5c405d01 (11) r5
  |\     folded(description, date, parent) from 4de32a90b66c, c8d03c1b5e94, f69452c5b1af using fold by test (Thu Jan 01 00:00:00 1970 +0000)
  | |
  | \
  | |\
  x | |  4de32a90b66c (7) r7
   / /
  x /  c8d03c1b5e94 (5) r5
   /
  x  f69452c5b1af (6) r6
  

123
124
125
Checking whether the bookmarks are moved or not

  $ hg log -G
126
  @  11 - 198b5c405d01 r5 [debugbuilddag] (draft) bm1
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  |
  | o  10 - a8407f9a3dc1 r10 [debugbuilddag] (draft)
  | |
  | o  9 - 529dfc5bb875 r9 [debugbuilddag] (draft)
  | |
  | o  8 - abf57d94268b r8 [debugbuilddag] (draft)
  | |
  o |  4 - bebd167eb94d r4 [debugbuilddag] (draft)
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  
144
145
146
(test inherited from test-evolve.t)

  $ hg fold --from 6 # want to run hg fold 6
147
  abort: hidden revision '6' was rewritten as: 198b5c405d01
148
  (use --hidden to access hidden revisions)
149
150
151
  [255]

  $ hg log -G
152
  @  11 - 198b5c405d01 r5 [debugbuilddag] (draft) bm1
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  |
  | o  10 - a8407f9a3dc1 r10 [debugbuilddag] (draft)
  | |
  | o  9 - 529dfc5bb875 r9 [debugbuilddag] (draft)
  | |
  | o  8 - abf57d94268b r8 [debugbuilddag] (draft)
  | |
  o |  4 - bebd167eb94d r4 [debugbuilddag] (draft)
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  

test fold --exact

  $ hg fold --exact 'desc("r8") + desc("r10")'
  abort: cannot fold non-linear revisions (multiple roots given)
  [255]
  $ hg fold --exact 'desc("r8")::desc("r10")'
  3 changesets folded
  $ hg log -G
  o  12 - b568edbee6e0 r8 [debugbuilddag] (draft)
  |
181
  | @  11 - 198b5c405d01 r5 [debugbuilddag] (draft) bm1
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  | |
  | o  4 - bebd167eb94d r4 [debugbuilddag] (draft)
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  

Test allow unstable

  $ echo a > a
  $ hg add a
  $ hg commit '-m r11'
  $ hg up '.^'
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
201
  (leaving bookmark bm1)
202
  $ hg log -G
203
  o  13 - 14d0e0da8e91 r11 [test] (draft) bm1
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  |
  | o  12 - b568edbee6e0 r8 [debugbuilddag] (draft)
  | |
  @ |  11 - 198b5c405d01 r5 [debugbuilddag] (draft)
  | |
  o |  4 - bebd167eb94d r4 [debugbuilddag] (draft)
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  

  $ cat << EOF >> .hg/hgrc
  > [experimental]
  > evolution = createmarkers, allnewcommands
  > EOF
  $ hg fold --from 'desc("r4")'
225
  abort: cannot fold changeset, as that will orphan 1 descendants
226
  (see 'hg help evolution.instability')
227
  [10]
228
  $ hg fold --from 'desc("r3")::desc("r11")'
229
  abort: cannot fold changeset, as that will orphan 1 descendants
230
  (see 'hg help evolution.instability')
231
  [10]
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

test --user variant

  $ cat << EOF >> .hg/hgrc
  > [experimental]
  > evolution = createmarkers, allnewcommands
  > EOF
  $ cat << EOF >> .hg/hgrc
  > [experimental]
  > evolution = all
  > EOF

  $ hg fold --exact 'desc("r5") + desc("r11")' --user 'Victor Rataxes <victor@rhino.savannah>'
  2 changesets folded
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg log -G
248
  @  14 - 29b470a33594 r5 [Victor Rataxes <victor@rhino.savannah>] (draft) bm1
249
  |
250
  | o  12 - b568edbee6e0 r8 [debugbuilddag] (draft)
251
  | |
252
  o |  4 - bebd167eb94d r4 [debugbuilddag] (draft)
253
254
255
256
257
258
259
260
261
262
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  

263
264
265
266
  $ hg fold --from 'desc("r4")' -U
  2 changesets folded
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg log -G
267
  @  15 - 91880abed0f2 r4 [test] (draft) bm1
268
  |
269
  | o  12 - b568edbee6e0 r8 [debugbuilddag] (draft)
270
271
272
273
274
275
276
277
278
  |/
  o  3 - 2dc09a01254d r3 [debugbuilddag] (draft)
  |
  o  2 - 01241442b3c2 r2 [debugbuilddag] (draft)
  |
  o  1 - 66f7d451a68b r1 [debugbuilddag] (draft)
  |
  o  0 - 1ea73414a91b r0 [debugbuilddag] (public)
  
279
280
Test order of proposed commit message

281
282
  $ hg fold --exact --hidden -r 4 -r 5 -r 6 \
  >         --config experimental.evolution.allowdivergence=yes
283
284
285
286
287
288
289
290
291
292
  2 new content-divergent changesets
  3 changesets folded
  $ hg log -r tip -T '{desc}'
  r4
  
  
  r5
  
  
  r6 (no-eol)
293
294
  $ hg fold --exact --hidden -r 6 -r 4 -r 5 \
  >         --config experimental.evolution.allowdivergence=yes
295
296
297
298
299
300
301
302
303
304
  3 changesets folded
  $ hg log -r tip -T '{desc}'
  r4
  
  
  r5
  
  
  r6 (no-eol)

305
306
  $ cd ..

307
308
309
310
311
312
313
314
315
316
One merge commit

  $ hg init fold-a-merge
  $ cd fold-a-merge

  $ mkcommit zebra

  $ hg up null
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ mkcommit apple
317
  created new head
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
  $ mkcommit banana

  $ hg merge
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  (branch merge, don't forget to commit)
  $ hg ci -m merge

  $ mkcommit coconut

  $ hg glf
  @  4: coconut (coconut)
  |
  o    3: merge ()
  |\
  | o  2: banana (banana)
  | |
  | o  1: apple (apple)
  |
  o  0: zebra (zebra)
  

now we merge some of the fruits

  $ hg fold --exact -r 'desc("banana")::desc("coconut")' -m 'banana+coconut in a merge with zebra'
  3 changesets folded
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg glf
  @    5: banana+coconut in a merge with zebra (banana coconut)
  |\
  | o  1: apple (apple)
  |
  o  0: zebra (zebra)
  

let's go even further: zebra becomes a parent of the squashed fruit commit

  $ hg fold --from -r 'desc("apple")' -m 'apple+banana+coconut is a child of zebra'
  2 changesets folded
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg glf
  @  6: apple+banana+coconut is a child of zebra (apple banana coconut)
  |
  o  0: zebra (zebra)
  

make sure zebra exists at tip and has expected contents

  $ hg cat -r tip zebra
  zebra

  $ cd ..

Multiple merge commits

  $ hg init fold-many-merges
  $ cd fold-many-merges

  $ hg debugbuilddag '+3 *3 /3 /4 /4'
  $ hg glog
  o    6: r6
  |\
  | o    5: r5
  | |\
  | | o  4: r4
  | |/|
  | | o  3: r3
  | | |
  o | |  2: r2
  |/ /
  o /  1: r1
  |/
  o  0: r0
  

cannot fold 5 and 6 because they have 3 external parents in total: 1, 2, 4

  $ hg fold --exact -r 5:6 -m r5+r6
  abort: cannot fold revisions that merge with more than one external changeset (not in revisions)
  [255]

now many of the parents are included in the revisions to fold, only 0 and 3 are external

  $ hg fold --exact -r 1+2+4+5+6 -m r1+r2+r4+r5+r6
  5 changesets folded

  $ hg glog
  o    7: r1+r2+r4+r5+r6
  |\
  | o  3: r3
  |/
  o  0: r0
  
  $ cd ..
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

Fold should respect experimental.evolution.allowdivergence option
https://bz.mercurial-scm.org/show_bug.cgi?id=5817

  $ hg init issue5817
  $ cd issue5817

  $ echo A > foo
  $ hg ci -qAm A
  $ echo B > foo
  $ hg ci -m B
  $ echo C > foo
  $ hg ci -m C

  $ hg fold --exact -r 'desc("A")::desc("B")' -m 'first fold'
  1 new orphan changesets
  2 changesets folded

429
fold aborts here because divergence is not allowed
430
431
432

  $ hg fold --exact -r 'desc("A")::desc("B")' -m 'second fold' \
  >         --config experimental.evolution.allowdivergence=no
433
  abort: cannot fold 4b34ecfb0d56, as that creates content-divergence with fcfd42a7fa46
434
  (add --verbose for details or see 'hg help evolution.instability')
435
  [10]
436
437
438
439
440

but if we allow divergence, this should work and should create new content-divergent changesets

  $ hg fold --exact -r 'desc("A")::desc("B")' -m 'second fold' \
  >         --config experimental.evolution.allowdivergence=yes
441
  2 new content-divergent changesets
442
443
444
  2 changesets folded

  $ cd ..