test-sharing.t 14.4 KB
Newer Older
1
2
3
4
5
6
7
Test script based on sharing.rst: ensure that all scenarios in that
document work as advertised.

Setting things up

  $ cat >> $HGRCPATH <<EOF
  > [alias]
8
  > shortlog = log --template '{rev}:{node|shortest}  {phase}  {desc|firstline}\n'
9
10
11
  > [extensions]
  > rebase =
  > EOF
12
  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
13
  $ hg init public
14
15
16
17
18
19
  $ hg clone public test-repo
  updating to branch default
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg clone test-repo dev-repo
  updating to branch default
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
20
21
22
23
24
25
26
27
28
29
30
  $ cat >> test-repo/.hg/hgrc <<EOF
  > [phases]
  > publish = false
  > EOF

To start things off, let's make one public, immutable changeset::

  $ cd test-repo
  $ echo 'my new project' > file1
  $ hg add file1
  $ hg commit -m'create new project'
31
  $ hg push
32
  pushing to $TESTTMP/public (glob)
33
34
35
36
37
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
38
39
40
41

and pull that into the development repository::

  $ cd ../dev-repo
42
  $ hg pull -u
43
  pulling from $TESTTMP/test-repo (glob)
44
45
46
47
48
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
49
  new changesets 0dc9c9f6ab91
50
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
51
52
53
54
55
56
57
58
59

Let's commit a preliminary change and push it to ``test-repo`` for
testing. ::

  $ echo 'fix fix fix' > file1
  $ hg commit -m'prelim change'
  $ hg push -q ../test-repo

Figure SG01 (roughly)
60
  $ hg -R ../dev-repo shortlog -G
61
  @  1:f649  draft  prelim change
62
  |
63
  o  0:0dc9  public  create new project
64
  
65
66
67
68
69
  $ hg -R ../test-repo shortlog -G
  o  1:f649  draft  prelim change
  |
  @  0:0dc9  public  create new project
  
70
71
72
Now let's switch to test-repo to test our change and amend::
  $ cd ../test-repo
  $ hg update -q
73
74
  $ echo 'Fix fix fix' > file1
  $ hg amend -m'fix bug 37'
75
76
77
78
  $ echo 'Fix fix fix.' > file1
  $ hg amend -m'fix bug 37'

Figure SG02
79
80
81
82
83
84
  $ hg -R ../dev-repo shortlog --hidden -G
  @  1:f649  draft  prelim change
  |
  o  0:0dc9  public  create new project
  
  $ hg -R ../test-repo shortlog --hidden -G
85
  @  3:522d  draft  fix bug 37
86
  |
87
88
  | x  2:96d8  draft  fix bug 37
  |/
89
  | x  1:f649  draft  prelim change
90
  |/
91
  o  0:0dc9  public  create new project
92
93
94
95
  
Pull into dev-repo: obsolescence markers are transferred, but not
the new obsolete changeset.
  $ cd ../dev-repo
96
  $ hg pull -u
97
  pulling from $TESTTMP/test-repo (glob)
98
99
100
101
102
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
103
  2 new obsolescence markers
104
  obsoleted 1 changesets
105
  new changesets 522d503432a2 (1 drafts)
106
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
107
  updated to "522d503432a2: fix bug 37"
108
  1 other heads for branch "default"
109
110

Figure SG03
111
  $ hg -R ../dev-repo shortlog --hidden -G
112
  @  2:522d  draft  fix bug 37
113
  |
114
  | x  1:f649  draft  prelim change
115
  |/
116
  o  0:0dc9  public  create new project
117
118
  
Amend again in dev-repo
119
120
  $ echo 'Fix, fix, and fix' > file1
  $ hg amend
121
122
123
124
125
126
  $ echo 'Fix, fix, and fix.' > file1
  $ hg amend
  $ hg push -q

Figure SG04 (dev-repo)
  $ hg shortlog --hidden -G
127
  @  4:7b49  draft  fix bug 37
128
  |
129
130
131
  | x  3:e42b  draft  fix bug 37
  |/
  | x  2:522d  draft  fix bug 37
132
  |/
133
  | x  1:f649  draft  prelim change
134
  |/
135
  o  0:0dc9  public  create new project
136
137
138
  
Figure SG04 (test-repo)
  $ cd ../test-repo
139
140
  $ hg update
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
141
  updated to "7b49f864d655: fix bug 37"
142
  1 other heads for branch "default"
143
  $ hg shortlog --hidden -G
144
  @  4:7b49  draft  fix bug 37
145
  |
146
147
148
  | x  3:522d  draft  fix bug 37
  |/
  | x  2:96d8  draft  fix bug 37
149
  |/
150
  | x  1:f649  draft  prelim change
151
  |/
152
  o  0:0dc9  public  create new project
153
154
155
  
This bug fix is finished. We can push it to the public repository.
  $ hg push
156
  pushing to $TESTTMP/public (glob)
157
158
159
160
161
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
162
  4 new obsolescence markers
163

164
165
Now that the fix is public, we cannot amend it any more.
  $ hg amend -m 'fix bug 37'
166
  abort: cannot amend public changesets: 7b49f864d655
167
  (see 'hg help phases' for details)
168
  [10]
169

170
171
Figure SG05
  $ hg -R ../public shortlog -G
172
  o  1:7b49  public  fix bug 37
173
  |
174
  o  0:0dc9  public  create new project
175
  
176
177
Oops, still have draft changesets in dev-repo: push the phase change there.
  $ hg -R ../dev-repo shortlog -r 'draft()'
178
  4:7b49  draft  fix bug 37
179
180
  $ hg push ../dev-repo
  pushing to ../dev-repo
181
182
  searching for changes
  no changes found
183
184
  [1]
  $ hg -R ../dev-repo shortlog -r 'draft()'
185

186
Sharing with multiple developers: code review
187
188

  $ cd ..
189
  $ hg clone public review
190
191
  updating to branch default
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
192
  $ hg clone review alice
193
194
  updating to branch default
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
195
196
197
198
  $ hg clone review bob
  updating to branch default
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cat >> review/.hg/hgrc <<EOF
199
200
201
202
  > [phases]
  > publish = false
  > EOF

203
Alice commits a draft bug fix, pushes to review repo.
204
  $ cd alice
205
  $ hg bookmark bug15
206
  $ echo 'fix' > file2
207
  $ hg commit -A -u alice -m 'fix bug 15 (v1)'
208
  adding file2
209
  $ hg push -B bug15
210
  pushing to $TESTTMP/review (glob)
211
212
213
214
215
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
216
217
  exporting bookmark bug15
  $ hg -R ../review bookmarks
218
     bug15                     2:4e965c66c983
219
220
221

Alice receives code review, amends her fix, and goes out to lunch to
await second review.
222
  $ echo 'Fix.' > file2
223
224
  $ hg amend -m 'fix bug 15 (v2)'
  $ hg push
225
  pushing to $TESTTMP/review (glob)
226
227
228
229
230
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
231
  1 new obsolescence markers
232
  obsoleted 1 changesets
233
234
  updating bookmark bug15
  $ hg -R ../review bookmarks
235
     bug15                     3:3363442626b3
236

237
238
Figure SG06: review repository after Alice pushes her amended changeset.
  $ hg --hidden -R ../review shortlog -G -r 1::
239
  o  3:3363  draft  fix bug 15 (v2)
240
  |
241
  | x  2:4e96  draft  fix bug 15 (v1)
242
  |/
243
  @  1:7b49  public  fix bug 37
244
  |
245
  ~
246
247
248
249
250
251
252

Bob commits a draft changeset, pushes to review repo.
  $ cd ../bob
  $ echo 'stuff' > file1
  $ hg bookmark featureX
  $ hg commit -u bob -m 'implement feature X (v1)'
  $ hg push -B featureX
253
  pushing to $TESTTMP/review (glob)
254
  searching for changes
255
  remote has heads on branch 'default' that are not known locally: 3363442626b3
256
257
258
259
260
261
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  exporting bookmark featureX
  $ hg -R ../review bookmarks
262
263
     bug15                     3:3363442626b3
     featureX                  4:c7ff98c7916f
264

265
266
267
Bob receives first review, amends and pushes.
  $ echo 'do stuff' > file1
  $ hg amend -m 'implement feature X (v2)'
268
  $ hg push
269
  pushing to $TESTTMP/review (glob)
270
  searching for changes
271
  remote has heads on branch 'default' that are not known locally: 3363442626b3
272
273
274
275
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
276
  1 new obsolescence markers
277
  obsoleted 1 changesets
278
279
280
281
282
283
284
285
  updating bookmark featureX

Bob receives second review, amends, and pushes to public:
this time, he's sure he got it right!
  $ echo 'Do stuff.' > file1
  $ hg amend -m 'implement feature X (v3)'
  $ hg push ../public
  pushing to ../public
286
287
288
289
290
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
291
  2 new obsolescence markers
292
293
294
295
296
  $ hg -R ../public bookmarks
  no bookmarks set
  $ hg push ../review
  pushing to ../review
  searching for changes
297
  remote has heads on branch 'default' that are not known locally: 3363442626b3
298
299
300
301
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
302
  1 new obsolescence markers
303
  obsoleted 1 changesets
304
305
  updating bookmark featureX
  $ hg -R ../review bookmarks
306
307
     bug15                     3:3363442626b3
     featureX                  6:9d21d673314a
308

309
310
Figure SG07: review and public repos after Bob implements feature X.
  $ hg --hidden -R ../review shortlog -G -r 1::
311
  o  6:9d21  public  implement feature X (v3)
312
  |
313
  | x  5:1bb4  draft  implement feature X (v2)
314
  |/
315
  | x  4:c7ff  draft  implement feature X (v1)
316
  |/
317
  | o  3:3363  draft  fix bug 15 (v2)
318
  |/
319
  | x  2:4e96  draft  fix bug 15 (v1)
320
  |/
321
  @  1:7b49  public  fix bug 37
322
  |
323
  ~
324
  $ hg --hidden -R ../public shortlog -G -r 1::
325
  o  2:9d21  public  implement feature X (v3)
326
  |
327
  o  1:7b49  public  fix bug 37
328
  |
329
  ~
330

331
332
333
334
Meantime, Alice is back from lunch. While she was away, Bob approved
her change, so now she can publish it.
  $ cd ../alice
  $ hg --hidden shortlog -G -r 1::
335
  @  3:3363  draft  fix bug 15 (v2)
336
  |
337
  | x  2:4e96  draft  fix bug 15 (v1)
338
  |/
339
  o  1:7b49  public  fix bug 37
340
  |
341
  ~
342
  $ hg outgoing -q ../public
343
  3:3363442626b3
344
345
346
  $ hg push ../public
  pushing to ../public
  searching for changes
347
  remote has heads on branch 'default' that are not known locally: 9d21d673314a
348
  abort: push creates new remote head 3363442626b3 with bookmark 'bug15'
349
  (pull and merge or see 'hg help push' for details about pushing new heads)
350
  [20]
351
352
353
354
355
356
357
  $ hg pull ../public
  pulling from ../public
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
358
  2 new obsolescence markers
359
  new changesets 9d21d673314a
360
361
  (run 'hg heads' to see heads, 'hg merge' to merge)
  $ hg log -G -q -r 'head()'
362
  o  4:9d21d673314a
363
  |
364
  ~
365
  @  3:3363442626b3
366
367
  |
  ~
368
  $ hg --hidden shortlog -G -r 1::
369
  o  4:9d21  public  implement feature X (v3)
370
  |
371
  | @  3:3363  draft  fix bug 15 (v2)
372
  |/
373
  | x  2:4e96  draft  fix bug 15 (v1)
374
  |/
375
  o  1:7b49  public  fix bug 37
376
  |
377
  ~
378

379
380
Alice rebases her draft changeset on top of Bob's public changeset and
publishes the result.
381
  $ hg rebase -d 4
382
  rebasing 3:3363442626b3 bug15 "fix bug 15 (v2)"
383
384
  $ hg push ../public
  pushing to ../public
385
386
387
388
389
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
390
  2 new obsolescence markers
391
392
393
394
395
396
397
  $ hg push ../review
  pushing to ../review
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 0 changes to 1 files
Pierre-Yves David's avatar
Pierre-Yves David committed
398
  1 new obsolescence markers
399
  obsoleted 1 changesets
400
  updating bookmark bug15
401

402
403
Figure SG08: review and public changesets after Alice pushes.
  $ hg --hidden -R ../review shortlog -G -r 1::
404
  o  7:dd15  public  fix bug 15 (v2)
405
  |
406
  o  6:9d21  public  implement feature X (v3)
407
  |
408
  | x  5:1bb4  draft  implement feature X (v2)
409
  |/
410
  | x  4:c7ff  draft  implement feature X (v1)
411
  |/
412
  | x  3:3363  draft  fix bug 15 (v2)
413
  |/
414
  | x  2:4e96  draft  fix bug 15 (v1)
415
  |/
416
  @  1:7b49  public  fix bug 37
417
  |
418
  ~
419
  $ hg --hidden -R ../public shortlog -G -r 1::
420
  o  3:dd15  public  fix bug 15 (v2)
421
  |
422
  o  2:9d21  public  implement feature X (v3)
423
  |
424
  o  1:7b49  public  fix bug 37
425
  |
426
  ~
427
428
  $ cd ..

429
Setup for shared mutable history (to illustrate content-divergence and
430
phase-divergent changesets).
431

432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
  $ rm -rf review alice bob
  $ hg clone public alice
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg clone public bob
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cat >> alice/.hg/hgrc <<EOF
  > [phases]
  > publish = false
  > EOF
  $ cp alice/.hg/hgrc bob/.hg/hgrc

Now we'll have Bob commit a bug fix that could still be improved::

  $ cd bob
  $ echo 'pretty good fix' >> file1
  $ hg commit -u bob -m 'fix bug 24 (v1)'
  $ hg shortlog -r .
451
  4:b2be  draft  fix bug 24 (v1)
452

453
Alice pulls Bob's draft changeset and amends it herself. ::
454
455
456
457
458
459
460
461
462

  $ cd ../alice
  $ hg pull -u ../bob
  pulling from ../bob
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
463
  new changesets b2be254b3b9f (1 drafts)
464
465
466
467
468
469
470
471
472
473
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo 'better fix (alice)' >> file1
  $ hg amend -u alice -m 'fix bug 24 (v2 by alice)'

Bob implements a better fix of his own::

  $ cd ../bob
  $ echo 'better fix (bob)' >> file1
  $ hg amend -u bob -m 'fix bug 24 (v2 by bob)'
  $ hg --hidden shortlog -G -r 3::
474
  @  5:541f  draft  fix bug 24 (v2 by bob)
475
  |
476
  | x  4:b2be  draft  fix bug 24 (v1)
477
  |/
478
  o  3:dd15  public  fix bug 15 (v2)
479
  |
480
  ~
481
482
483
484
485
486
487
488
489

Bob discovers the divergence.
  $ hg pull ../alice
  pulling from ../alice
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
490
  1 new obsolescence markers
491
  2 new content-divergent changesets
492
  new changesets e3a586fd2377 (1 drafts)
493
494
495
496
  (run 'hg heads' to see heads, 'hg merge' to merge)

Figure SG09: multiple heads! divergence! oh my!
  $ hg --hidden shortlog -G -r 3::
497
  *  6:e3a5  draft  fix bug 24 (v2 by alice)
498
  |
499
  | @  5:541f  draft  fix bug 24 (v2 by bob)
500
  |/
501
  | x  4:b2be  draft  fix bug 24 (v1)
502
  |/
503
  o  3:dd15  public  fix bug 15 (v2)
504
  |
505
  ~
506
507
508
  $ hg --hidden shortlog -r 'successors(b2be)'
  5:541f  draft  fix bug 24 (v2 by bob)
  6:e3a5  draft  fix bug 24 (v2 by alice)
509
510

Use evolve to fix the divergence.
511
512
513
514
515
516
517
518
  $ cat > editor.sh <<EOF
  > #!/bin/sh
  > cat > \$1 <<ENDOF
  > fix bug 24 (v2 by bob)
  > ENDOF
  > EOF

  $ HGEDITOR='sh ./editor.sh' HGMERGE=internal:other hg evolve --content-divergent
519
520
  merge:[5] fix bug 24 (v2 by bob)
  with: [6] fix bug 24 (v2 by alice)
521
522
  base: [4] fix bug 24 (v1)
  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
523
  working directory is now at f92394e17e33
524
  $ hg log -q -r 'contentdivergent()'
525
526
527

Figure SG10: Bob's repository after fixing divergence.
  $ hg --hidden shortlog -G -r 3::
528
  @  7:f923  draft  fix bug 24 (v2 by bob)
529
  |
530
  | x  6:e3a5  draft  fix bug 24 (v2 by alice)
531
  |/
532
  | x  5:541f  draft  fix bug 24 (v2 by bob)
533
  |/
534
  | x  4:b2be  draft  fix bug 24 (v1)
535
  |/
536
  o  3:dd15  public  fix bug 15 (v2)
537
  |
538
  ~
539
  $ hg --hidden shortlog -r 'predecessors(.)'
540
541
  5:541f  draft  fix bug 24 (v2 by bob)
  6:e3a5  draft  fix bug 24 (v2 by alice)
542
543
544
545
  $ cat file1
  Do stuff.
  pretty good fix
  better fix (alice)