tests/test-sharing.t
author Greg Ward <greg@gerg.ca>
Tue, 14 Apr 2015 12:53:12 -0400
branchstable
changeset 1261 56cc2eb5995a
parent 1259 0daf56a2032d
child 1263 eb0a1d1d499b
permissions -rw-r--r--
docs: add code review scenario to sharing guide The idea is to demonstrate a simpler multiple-developer situation that does not involve getting into trouble. The final scenario illustrates Alice and Bob getting into trouble with bumped and divergent changesets by amending each other's history. The required tests and text are all written, but will need to be heavily revised because of the inserted scenario.

Test script based on sharing.rst: ensure that all scenarios in that
document work as advertised.

Setting things up

  $ cat >> $HGRCPATH <<EOF
  > [alias]
  > shortlog = log --template '{rev}:{node|short}  {phase}  {desc|firstline}\n'
  > [extensions]
  > rebase =
  > EOF
  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
  $ hg init public
  $ 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
  $ 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'
  $ hg push
  pushing to $TESTTMP/public
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files

and pull that into the development repository::

  $ cd ../dev-repo
  $ hg pull -u
  pulling from $TESTTMP/test-repo
  requesting all changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  pull obsolescence markers
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

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)
  $ hg shortlog -G
  @  1:f6490818a721  draft  prelim change
  |
  o  0:0dc9c9f6ab91  public  create new project
  
Now let's switch to test-repo to test our change and amend::
  $ cd ../test-repo
  $ hg update -q
  $ echo 'Fix fix fix.' > file1
  $ hg amend -m'fix bug 37'

Figure SG02
  $ hg shortlog --hidden -G
  @  3:60ffde5765c5  draft  fix bug 37
  |
  | x  2:2a039763c0f4  draft  temporary amend commit for f6490818a721
  | |
  | x  1:f6490818a721  draft  prelim change
  |/
  o  0:0dc9c9f6ab91  public  create new project
  
Pull into dev-repo: obsolescence markers are transferred, but not
the new obsolete changeset.
  $ cd ../dev-repo
  $ hg pull -u
  pulling from $TESTTMP/test-repo
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  pull obsolescence markers
  2 obsolescence markers added
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Figure SG03
  $ hg shortlog --hidden -G
  @  2:60ffde5765c5  draft  fix bug 37
  |
  | x  1:f6490818a721  draft  prelim change
  |/
  o  0:0dc9c9f6ab91  public  create new project
  
Amend again in dev-repo
  $ echo 'Fix, fix, and fix.' > file1
  $ hg amend
  $ hg push -q

Figure SG04 (dev-repo)
  $ hg shortlog --hidden -G
  @  4:de6151c48e1c  draft  fix bug 37
  |
  | x  3:ad19d3570adb  draft  temporary amend commit for 60ffde5765c5
  | |
  | x  2:60ffde5765c5  draft  fix bug 37
  |/
  | x  1:f6490818a721  draft  prelim change
  |/
  o  0:0dc9c9f6ab91  public  create new project
  
Figure SG04 (test-repo)
  $ cd ../test-repo
  $ hg update
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg shortlog --hidden -G
  @  4:de6151c48e1c  draft  fix bug 37
  |
  | x  3:60ffde5765c5  draft  fix bug 37
  |/
  | x  2:2a039763c0f4  draft  temporary amend commit for f6490818a721
  | |
  | x  1:f6490818a721  draft  prelim change
  |/
  o  0:0dc9c9f6ab91  public  create new project
  
This bug fix is finished. We can push it to the public repository.
  $ hg push
  pushing to $TESTTMP/public (glob)
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  pushing 4 obsolescence markers (* bytes) (glob)
  4 obsolescence markers added

Figure SG05
  $ hg -R ../public shortlog -G
  o  1:de6151c48e1c  public  fix bug 37
  |
  o  0:0dc9c9f6ab91  public  create new project
  
Oops, still have draft changesets in dev-repo.
  $ cd ../dev-repo
  $ hg shortlog -r 'draft()'
  4:de6151c48e1c  draft  fix bug 37
  $ hg pull -u
  pulling from $TESTTMP/test-repo
  searching for changes
  no changes found
  pull obsolescence markers
  0 obsolescence markers added
  $ hg shortlog -r 'draft()'

Sharing with multiple developers: code review

  $ cd ..
  $ hg clone public review
  updating to branch default
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg clone review alice
  updating to branch default
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ 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
  > [phases]
  > publish = false
  > EOF

Alice commits a draft bug fix, pushes to review repo.
  $ cd alice
  $ hg bookmark bug15
  $ echo 'fix' > file2
  $ hg commit -A -u alice -m 'fix bug 15 (v1)'
  adding file2
  $ hg push -B bug15
  pushing to $TESTTMP/review
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  pushing 4 obsolescence markers (* bytes) (glob)
  0 obsolescence markers added
  exporting bookmark bug15
  $ hg -R ../review bookmarks
     bug15                     2:f91e97234c2b

Alice receives code review, amends her fix, and goes out to lunch to
await second review.
  $ echo 'Fix.' > file2
  $ hg amend -m 'fix bug 15 (v2)'
  $ hg push
  pushing to $TESTTMP/review
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  pushing 6 obsolescence markers (* bytes) (glob)
  2 obsolescence markers added
  updating bookmark bug15
  $ hg -R ../review bookmarks
     bug15                     3:cbdfbd5a5db2

Figure SG06: review repository after Alice pushes her amended changeset.
  $ hg --hidden -R ../review shortlog -G -r 1::
  o  3:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  @  1:de6151c48e1c  public  fix bug 37
  |

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
  pushing to $TESTTMP/review
  searching for changes
  remote has heads on branch 'default' that are not known locally: cbdfbd5a5db2
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  pushing 4 obsolescence markers (* bytes) (glob)
  0 obsolescence markers added
  exporting bookmark featureX
  $ hg -R ../review bookmarks
     bug15                     3:cbdfbd5a5db2
     featureX                  4:193657d1e852

Bob receives first review, amends and pushes.
  $ echo 'do stuff' > file1
  $ hg amend -m 'implement feature X (v2)'
  $ hg push
  pushing to $TESTTMP/review
  searching for changes
  remote has heads on branch 'default' that are not known locally: cbdfbd5a5db2
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  pushing 6 obsolescence markers (* bytes) (glob)
  2 obsolescence markers added
  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
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  pushing 8 obsolescence markers (* bytes) (glob)
  4 obsolescence markers added
  $ hg -R ../public bookmarks
  no bookmarks set
  $ hg push ../review
  pushing to ../review
  searching for changes
  remote has heads on branch 'default' that are not known locally: cbdfbd5a5db2
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files (+1 heads)
  pushing 8 obsolescence markers (* bytes) (glob)
  2 obsolescence markers added
  updating bookmark featureX
  $ hg -R ../review bookmarks
     bug15                     3:cbdfbd5a5db2
     featureX                  6:540ba8f317e6

Figure SG07: review and public repos after Bob implements feature X.
  $ hg --hidden -R ../review shortlog -G -r 1::
  o  6:540ba8f317e6  public  implement feature X (v3)
  |
  | x  5:0eb74a7b6698  draft  implement feature X (v2)
  |/
  | x  4:193657d1e852  draft  implement feature X (v1)
  |/
  | o  3:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |/
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  @  1:de6151c48e1c  public  fix bug 37
  |
  $ hg --hidden -R ../public shortlog -G -r 1::
  o  2:540ba8f317e6  public  implement feature X (v3)
  |
  o  1:de6151c48e1c  public  fix bug 37
  |

How do things look in the review repo?
  $ cd ../review
  $ hg --hidden shortlog -G -r 1::
  o  6:540ba8f317e6  public  implement feature X (v3)
  |
  | x  5:0eb74a7b6698  draft  implement feature X (v2)
  |/
  | x  4:193657d1e852  draft  implement feature X (v1)
  |/
  | o  3:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |/
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  @  1:de6151c48e1c  public  fix bug 37
  |

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::
  @  4:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |
  | x  3:55dd95168a35  draft  temporary amend commit for f91e97234c2b
  | |
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  o  1:de6151c48e1c  public  fix bug 37
  |
  $ hg outgoing -q ../public
  4:cbdfbd5a5db2
  $ hg push ../public
  pushing to ../public
  searching for changes
  remote has heads on branch 'default' that are not known locally: 540ba8f317e6
  abort: push creates new remote head cbdfbd5a5db2 with bookmark 'bug15'!
  (pull and merge or see "hg help push" for details about pushing new heads)
  [255]
  $ 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)
  pull obsolescence markers
  4 obsolescence markers added
  (run 'hg heads' to see heads, 'hg merge' to merge)
  $ hg log -G -q -r 'head()'
  o  5:540ba8f317e6
  |
  | @  4:cbdfbd5a5db2
  |/
  $ hg --hidden shortlog -G -r 1::
  o  5:540ba8f317e6  public  implement feature X (v3)
  |
  | @  4:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |/
  | x  3:55dd95168a35  draft  temporary amend commit for f91e97234c2b
  | |
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  o  1:de6151c48e1c  public  fix bug 37
  |

Alice rebases her draft changeset on top of Bob's public changeset and
publishes the result.
  $ hg rebase -d 5
  rebasing 4:cbdfbd5a5db2 "fix bug 15 (v2)" (bug15)
  $ hg push ../public
  pushing to ../public
  searching for changes
  adding changesets
  adding manifests
  adding file changes
  added 1 changesets with 1 changes to 1 files
  pushing 11 obsolescence markers (* bytes) (glob)
  3 obsolescence markers added
  $ 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
  pushing 11 obsolescence markers (* bytes) (glob)
  1 obsolescence markers added
  updating bookmark bug15

Figure SG08: review and public changesets after Alice pushes.
  $ hg --hidden -R ../review shortlog -G -r 1::
  o  7:a06ec1bf97bd  public  fix bug 15 (v2)
  |
  o  6:540ba8f317e6  public  implement feature X (v3)
  |
  | x  5:0eb74a7b6698  draft  implement feature X (v2)
  |/
  | x  4:193657d1e852  draft  implement feature X (v1)
  |/
  | x  3:cbdfbd5a5db2  draft  fix bug 15 (v2)
  |/
  | x  2:f91e97234c2b  draft  fix bug 15 (v1)
  |/
  @  1:de6151c48e1c  public  fix bug 37
  |
  $ hg --hidden -R ../public shortlog -G -r 1::
  o  3:a06ec1bf97bd  public  fix bug 15 (v2)
  |
  o  2:540ba8f317e6  public  implement feature X (v3)
  |
  o  1:de6151c48e1c  public  fix bug 37
  |