test-pick.t 9.79 KB
Newer Older
1
#testcases abortcommand abortflag
2
3
4
5
6
Test for the pick command

  $ cat >> $HGRCPATH <<EOF
  > [alias]
  > glog = log -G -T "{rev}:{node|short} {desc}\n"
7
  > glf = log -GT "{rev}: {desc} ({files})\n"
8
9
10
11
  > [extensions]
  > EOF
  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH

12
13
14
15
16
17
18
#if abortflag
  $ cat >> $HGRCPATH <<EOF
  > [alias]
  > abort = pick --abort
  > EOF
#endif

19
20
21
22
23
24
25
26
27
  $ mkcommit() {
  >    echo "$1" > "$1"
  >    hg add "$1"
  >    hg ci -m "add $1"
  > }

  $ hg init repo
  $ cd repo
  $ hg help pick
28
  hg pick [OPTION]... [-r] REV
29
30
31
32
33
34
35
  
  aliases: grab
  
  move a commit on the top of working directory parent and updates to it.
  
  options:
  
36
37
38
39
   -r --rev REV   revision to pick
   -c --continue  continue interrupted pick
   -a --abort     abort interrupted pick
   -t --tool TOOL specify merge tool
40
41
42
43
44
45
46
47
48
49
50
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
82
83
84
85
86
87
88
89
  
  (some details hidden, use --verbose to show complete help)

  $ mkcommit a
  $ mkcommit b
  $ mkcommit c

  $ hg glog
  @  2:4538525df7e2 add c
  |
  o  1:7c3bad9141dc add b
  |
  o  0:1f0dee641bb7 add a
  

Grabbing an ancestor

  $ hg pick -r 7c3bad9141dc
  abort: cannot pick an ancestor revision
  [255]

Grabbing the working directory parent

  $ hg pick -r .
  abort: cannot pick an ancestor revision
  [255]

Specifying multiple revisions to pick

  $ hg pick 1f0dee641bb7 -r 7c3bad9141dc
  abort: specify just one revision
  [255]

Specifying no revisions to pick

  $ hg pick
  abort: empty revision set
  [255]

Continuing without interrupted pick

  $ hg pick --continue
  abort: no interrupted pick state exists
  [255]

Aborting without interrupted pick

  $ hg pick --abort
  abort: no interrupted pick state exists
  [255]
90
91
92
#if abortcommand
  $ hg abort
  abort: no operation in progress
93
  [20]
94
#endif
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

Specifying both continue and revs

  $ hg up 1f0dee641bb7
  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ hg pick -r 4538525df7e2 --continue
  abort: cannot specify both --continue and revision
  [255]

Making new branch heads

  $ mkcommit x
  created new head
  $ mkcommit y

  $ hg glog
  @  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  | o  2:4538525df7e2 add c
  | |
  | o  1:7c3bad9141dc add b
  |/
  o  0:1f0dee641bb7 add a
  
Grabbing a revision

  $ hg pick 7c3bad9141dc
  picking 1:7c3bad9141dc "add b"
  1 new orphan changesets
  $ hg glog
  @  5:7c15c05db6fa add b
  |
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  | *  2:4538525df7e2 add c
  | |
  | x  1:7c3bad9141dc add b
  |/
  o  0:1f0dee641bb7 add a
  

When pick does not create any changes

  $ hg graft -r 4538525df7e2
  grafting 2:4538525df7e2 "add c"

  $ hg glog
  @  6:c4636a81ebeb add c
  |
  o  5:7c15c05db6fa add b
  |
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  | *  2:4538525df7e2 add c
  | |
  | x  1:7c3bad9141dc add b
  |/
  o  0:1f0dee641bb7 add a
  
  $ hg pick -r 4538525df7e2
  picking 2:4538525df7e2 "add c"
  note: picking 2:4538525df7e2 created no changes to commit

  $ hg glog
  @  6:c4636a81ebeb add c
  |
  o  5:7c15c05db6fa add b
  |
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  o  0:1f0dee641bb7 add a
  
175
176
177
178

there were no changes to commit, so there shouldn't be any predecessors of 6,
and 2 should say it was pruned (issue6093)

179
180
181
  $ hg debugobsolete
  7c3bad9141dcb46ff89abf5f61856facd56e476c 7c15c05db6fa1458a8a745f977f4d2426abde6a0 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '4', 'operation': 'pick', 'user': 'test'}
  4538525df7e2b9f09423636c61ef63a4cb872a2d 0 {7c3bad9141dcb46ff89abf5f61856facd56e476c} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'pick', 'user': 'test'}
182
183
184
185
186
187
188
  $ hg olog --all --hidden -r 2+6
  x  4538525df7e2 (2) add c
       pruned using pick by test (Thu Jan 01 00:00:00 1970 +0000)
  
  @  c4636a81ebeb (6) add c
  

189
190
191
192
193
194
195
196
197
198
199
interrupted pick

  $ hg up d46dc301d92f
  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
  $ echo foo > c
  $ hg ci -Aqm "foo to c"
  $ hg pick -r c4636a81ebeb
  picking 6:c4636a81ebeb "add c"
  merging c
  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
  unresolved merge conflicts (see hg help resolve)
200
  [240]
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

  $ echo foobar > c
  $ hg resolve --all --mark
  (no more unresolved files)
  continue: hg pick --continue
  $ hg pick --continue
  $ hg glog
  @  8:44e155eb95c7 add c
  |
  o  7:2ccc03d1d096 foo to c
  |
  | o  5:7c15c05db6fa add b
  |/
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  o  0:1f0dee641bb7 add a
  

When interrupted pick results in no changes to commit

  $ hg up d46dc301d92f
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ echo bar > c
  $ hg add c
  $ hg ci -m "foo to c"
  created new head

  $ hg up 44e155eb95c7
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

  $ hg pick 4e04628911f6
  picking 9:4e04628911f6 "foo to c"
  merging c
  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
  unresolved merge conflicts (see hg help resolve)
238
  [240]
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  $ echo foobar > c
  $ hg resolve -m
  (no more unresolved files)
  continue: hg pick --continue

  $ hg pick --continue
  note: picking 9:4e04628911f6 created no changes to commit

Testing the abort functionality of hg pick

  $ echo foo > b
  $ hg ci -Aqm "foo to b"
  $ hg glog -r .^::
  @  10:c437988de89f foo to b
  |
  o  8:44e155eb95c7 add c
  |
  ~

  $ hg pick -r 7c15c05db6fa
  picking 5:7c15c05db6fa "add b"
  merging b
  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
  unresolved merge conflicts (see hg help resolve)
263
  [240]
264

265
266
267
268
269
#if abortcommand
  $ hg abort --dry-run
  pick in progress, will be aborted
#endif
  $ hg abort
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
  aborting pick, updating to c437988de89f

  $ hg glog
  @  10:c437988de89f foo to b
  |
  o  8:44e155eb95c7 add c
  |
  o  7:2ccc03d1d096 foo to c
  |
  | o  5:7c15c05db6fa add b
  |/
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  o  0:1f0dee641bb7 add a
  

Trying to pick a public changeset

  $ hg phase -r 7c15c05db6fa -p

  $ hg pick -r 7c15c05db6fa
  abort: cannot pick public changesets: 7c15c05db6fa
  (see 'hg help phases' for details)
295
  [10]
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

  $ hg glog
  @  10:c437988de89f foo to b
  |
  o  8:44e155eb95c7 add c
  |
  o  7:2ccc03d1d096 foo to c
  |
  | o  5:7c15c05db6fa add b
  |/
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  o  0:1f0dee641bb7 add a
  
Checking phase preservation while picking secret changeset

In case of merge conflicts

  $ hg phase -r 7c15c05db6fa -s -f

  $ hg pick -r 7c15c05db6fa
  picking 5:7c15c05db6fa "add b"
  merging b
  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
  unresolved merge conflicts (see hg help resolve)
323
  [240]
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

  $ echo bar > b
  $ hg resolve -m
  (no more unresolved files)
  continue: hg pick --continue

  $ hg pick --continue
  $ hg phase -r .
  11: secret

No merge conflicts

  $ hg up d46dc301d92f
  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
  $ echo foo > l
  $ hg add l
  $ hg ci -qm "added l" --secret

  $ hg phase -r .
  12: secret

  $ hg glog
  @  12:508d572e7053 added l
  |
  | o  11:10427de9e26e add b
  | |
  | o  10:c437988de89f foo to b
  | |
  | o  8:44e155eb95c7 add c
  | |
  | o  7:2ccc03d1d096 foo to c
  |/
  o  4:d46dc301d92f add y
  |
  o  3:8e224524cd09 add x
  |
  o  0:1f0dee641bb7 add a
  
  $ hg up 10427de9e26e
  3 files updated, 0 files merged, 1 files removed, 0 files unresolved

  $ hg pick -r 508d572e7053
  picking 12:508d572e7053 "added l"

  $ hg phase -r .
  13: secret
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
411
412
413
414
415
416
417
418
419
420
  $ cd ..

Check pick behavior regarding working copy branch (issue6089)
-------------------------------------------------------------

The branch of the picked changeset should be preserved, and the working copy updated

  $ hg init issue6089
  $ cd issue6089

  $ touch a
  $ hg add a
  $ hg ci -m 'first commit on default'

  $ hg branch foo
  marked working directory as branch foo
  (branches are permanent and global, did you want a bookmark?)
  $ touch b
  $ hg add b
  $ hg ci -m 'first commit on foo'

  $ hg up default
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ echo test > a
  $ hg ci -m 'second commit on default'
  $ hg log -G --template '{node|short}: {branch}\n' --rev 'all()+wdir()'
  o  ffffffffffff: default
  |
  @  5f07cbf7d111: default
  |
  | o  96bb2057779e: foo
  |/
  o  d03a6bcc83cd: default
  

  $ hg pick 1
  picking 1:96bb2057779e "first commit on foo"
  $ hg log --template '{branch}\n' -r tip
  foo
  $ hg branch
  foo
  $ hg log -G --template '{node|short}: {branch}\n' --rev 'all()+wdir()'
  o  ffffffffffff: foo
  |
  @  5344a77549bd: foo
  |
  o  5f07cbf7d111: default
  |
  o  d03a6bcc83cd: default
  
  $ cd ..
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461

Check that pick doesn't drop files after conflicts occur (issue6037)
--------------------------------------------------------------------

  $ hg init issue6037
  $ cd issue6037

  $ echo apple > a
  $ hg ci -qAm 'apple'

  $ echo apricot > a
  $ echo banana > b
  $ hg ci -qAm 'apricot and banana'

  $ echo avocado > a
  $ hg ci -m 'avocado'

  $ hg glf
  @  2: avocado (a)
  |
  o  1: apricot and banana (a b)
  |
  o  0: apple (a)
  
Now let's change order of 1 and 2 using pick command

  $ hg up -r 0
  1 files updated, 0 files merged, 1 files removed, 0 files unresolved

We avoid merge conflict here just to make the test shorter

  $ hg pick -r 2 --tool :other
  picking 2:f08a1e4a33c4 "avocado"

Now we pick revision 1 that touches two files (a and b), merge conflict is expected

  $ hg pick -r 1
  picking 1:892e123ebf62 "apricot and banana"
  merging a
  warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
  unresolved merge conflicts (see hg help resolve)
462
  [240]
463
464
465
466
467
  $ hg resolve -t :other a
  (no more unresolved files)
  continue: hg pick --continue
  $ hg pick --continue

468
Demonstrate that b was not forgotten and is definitely included in 4
469

470
471
  $ hg status b -A
  C b
472
  $ hg glf
473
  @  4: apricot and banana (a b)
474
475
476
477
478
479
  |
  o  3: avocado (a)
  |
  o  0: apple (a)
  
  $ cd ..