tests/test-url-rev.t
author Gregory Szorc <gregory.szorc@gmail.com>
Thu, 22 Dec 2016 23:28:35 -0700
changeset 30661 ced0d686ecb3
parent 30036 3f4e1c033f40
child 31064 4431add9aef9
permissions -rw-r--r--
convert: add config option to control storing original revision common.commit.__init__ sets saverev=True by default. The side effect of this is that the hg sink will always set the "convert_revision" extras key to the commit being converted. This patch adds a config option to disable this behavior. While most consumers will want "convert_revision" to be a) written b) with the exact Git commit that was converted, some have use cases that prefer otherwise. In my case, I am performing significant rewrites of a Git repository *before* it is fed into `hg convert`. I have to do this because `hg convert` does not easily support the kind of transform I desire, even with extensions. (For the curious, I am "linearizing" the history of a GitHub repo by removing merge commits which add little value to the final history. It isn't easy to do this during `hg convert` because of Mercurial's file copy/rename metadata requirements.) In my scenario, my pre-convert transform stores a "convert_revision" key in the Git commit object containing the original Git commit ID. I want this original Git commit ID carried forward to Mercurial. By disabling the setting of this extra during `hg convert` and copying the value from the Git commit object, I can have the final "convert_revision" extra key contain the original Git commit ID. An added test verifies this exact scenario. This feature could likely be implemented for other VCS sources. But until someone needs the feature, I'm inclined to hold off implementing.

Test basic functionality of url#rev syntax

  $ hg init repo
  $ cd repo
  $ echo a > a
  $ hg ci -qAm 'add a'
  $ hg branch foo
  marked working directory as branch foo
  (branches are permanent and global, did you want a bookmark?)
  $ echo >> a
  $ hg ci -m 'change a'
  $ cd ..

  $ hg clone 'repo#foo' clone
  adding changesets
  adding manifests
  adding file changes
  added 2 changesets with 2 changes to 1 files
  updating to branch foo
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

  $ hg --cwd clone heads
  changeset:   1:cd2a86ecc814
  branch:      foo
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     change a
  
  changeset:   0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a
  
  $ hg --cwd clone parents
  changeset:   1:cd2a86ecc814
  branch:      foo
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     change a
  
  $ cat clone/.hg/hgrc
  # example repository config (see 'hg help config' for more info)
  [paths]
  default = $TESTTMP/repo#foo (glob)
  
  # path aliases to other clones of this repo in URLs or filesystem paths
  # (see 'hg help config.paths' for more info)
  #
  # default-push = ssh://jdoe@example.net/hg/jdoes-fork
  # my-fork      = ssh://jdoe@example.net/hg/jdoes-fork
  # my-clone     = /home/jdoe/jdoes-clone
  
  [ui]
  # name and email (local to this repository, optional), e.g.
  # username = Jane Doe <jdoe@example.com>

Changing original repo:

  $ cd repo

  $ echo >> a
  $ hg ci -m 'new head of branch foo'

  $ hg up -qC default
  $ echo bar > bar
  $ hg ci -qAm 'add bar'

  $ hg log
  changeset:   3:4cd725637392
  tag:         tip
  parent:      0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add bar
  
  changeset:   2:faba9097cad4
  branch:      foo
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     new head of branch foo
  
  changeset:   1:cd2a86ecc814
  branch:      foo
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     change a
  
  changeset:   0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a
  
  $ hg -q outgoing '../clone'
  2:faba9097cad4
  3:4cd725637392
  $ hg summary --remote --config paths.default='../clone'
  parent: 3:4cd725637392 tip
   add bar
  branch: default
  commit: (clean)
  update: (current)
  phases: 4 draft
  remote: 2 outgoing
  $ hg -q outgoing '../clone#foo'
  2:faba9097cad4
  $ hg summary --remote --config paths.default='../clone#foo'
  parent: 3:4cd725637392 tip
   add bar
  branch: default
  commit: (clean)
  update: (current)
  phases: 4 draft
  remote: 1 outgoing

  $ hg -q --cwd ../clone incoming '../repo#foo'
  2:faba9097cad4
  $ hg --cwd ../clone summary --remote --config paths.default='../repo#foo'
  parent: 1:cd2a86ecc814 tip
   change a
  branch: foo
  commit: (clean)
  update: (current)
  remote: 1 or more incoming

  $ hg -q push '../clone#foo'

  $ hg --cwd ../clone heads
  changeset:   2:faba9097cad4
  branch:      foo
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     new head of branch foo
  
  changeset:   0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a
  
  $ hg -q --cwd ../clone incoming '../repo#foo'
  [1]
  $ hg --cwd ../clone summary --remote --config paths.default='../repo#foo'
  parent: 1:cd2a86ecc814 
   change a
  branch: foo
  commit: (clean)
  update: 1 new changesets (update)
  remote: (synced)

  $ cd ..

  $ cd clone
  $ hg rollback
  repository tip rolled back to revision 1 (undo push)

  $ hg -q incoming
  2:faba9097cad4

  $ hg -q pull

  $ hg heads
  changeset:   2:faba9097cad4
  branch:      foo
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     new head of branch foo
  
  changeset:   0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a
  
Pull should not have updated:

  $ hg parents -q
  1:cd2a86ecc814

Going back to the default branch:

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

  $ hg parents
  changeset:   0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a
  
No new revs, no update:

  $ hg pull -qu

  $ hg parents -q
  0:1f0dee641bb7

  $ hg rollback
  repository tip rolled back to revision 1 (undo pull)

  $ hg parents -q
  0:1f0dee641bb7

Pull -u takes us back to branch foo:

  $ hg pull -qu

  $ hg parents
  changeset:   2:faba9097cad4
  branch:      foo
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     new head of branch foo
  
  $ hg rollback
  repository tip rolled back to revision 1 (undo pull)
  working directory now based on revision 0

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

  $ hg parents -q
  0:1f0dee641bb7

  $ hg heads -q
  1:cd2a86ecc814
  0:1f0dee641bb7

  $ hg pull -qur default default

  $ hg parents
  changeset:   3:4cd725637392
  tag:         tip
  parent:      0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add bar
  
  $ hg heads
  changeset:   3:4cd725637392
  tag:         tip
  parent:      0:1f0dee641bb7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add bar
  
  changeset:   2:faba9097cad4
  branch:      foo
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     new head of branch foo
  
Test handling of invalid urls

  $ hg id http://foo/?bar
  abort: unsupported URL component: "bar"
  [255]

  $ cd ..

Test handling common incoming revisions between "default" and
"default-push"

  $ hg -R clone rollback
  repository tip rolled back to revision 1 (undo pull)
  working directory now based on revision 0

  $ cd repo

  $ hg update -q -C default
  $ echo modified >> bar
  $ hg commit -m "new head to push current default head"
  $ hg -q push -r ".^1" '../clone'

  $ hg -q outgoing '../clone'
  2:faba9097cad4
  4:d515801a8f3d

  $ hg summary --remote --config paths.default='../clone#default' --config paths.default-push='../clone#foo'
  parent: 4:d515801a8f3d tip
   new head to push current default head
  branch: default
  commit: (clean)
  update: (current)
  phases: 1 draft
  remote: 1 outgoing

  $ hg summary --remote --config paths.default='../clone#foo' --config paths.default-push='../clone'
  parent: 4:d515801a8f3d tip
   new head to push current default head
  branch: default
  commit: (clean)
  update: (current)
  phases: 1 draft
  remote: 2 outgoing

  $ hg summary --remote --config paths.default='../clone' --config paths.default-push='../clone#foo'
  parent: 4:d515801a8f3d tip
   new head to push current default head
  branch: default
  commit: (clean)
  update: (current)
  phases: 1 draft
  remote: 1 outgoing

  $ hg clone -q -r 0 . ../another
  $ hg -q outgoing '../another#default'
  3:4cd725637392
  4:d515801a8f3d

  $ hg summary --remote --config paths.default='../another#default' --config paths.default-push='../clone#default'
  parent: 4:d515801a8f3d tip
   new head to push current default head
  branch: default
  commit: (clean)
  update: (current)
  phases: 1 draft
  remote: 1 outgoing

  $ cd ..

Test url#rev syntax of local destination path, which should be taken as
a 'url#rev' path

  $ hg clone repo '#foo'
  updating to branch default
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg root -R '#foo'
  $TESTTMP/#foo (glob)