Moving files by subrepositions in Mercury

Does anyone know how to move files through suprepos while saving history to file

I am using hg mv /Product/common/modules/sub-repo1/scripts/filename /Product/common/modules/sub-repo2/scripts/filename

Product is a repo at the shell level, and sub-repo1 and sub-repo2 are subrepos

It throws an error abort /Product/common/modules/sub-repo2/scripts/filename not under root ..

+4
source share
2 answers

This is possible by combining the two repositories together:

  • Convert to a new repository with a file file that filters out everything except the file you are interested in. There is a good description at hgtip.com .

     echo include my-file > filemap hg convert --filemap sourcerepo temprepo 
  • Pull the new repository into the existing repository. This will create a whole new head that does not come from the previous set of changes. It is also described in more detail at hgtip.com .

     cd destrepo hg pull --force temprepo 
  • Finally, drain the new head.

     hg merge 

Here is an example on the command line. First, we create the original source repository:

 $ mkdir sourcerepo $ cd sourcerepo $ hg init $ echo aaa > a $ echo bbb > b $ hg add ab $ hg commit -m first $ echo xxx > a $ echo yyy > b $ hg commit -m second 

Then we create the file and convert it to a temporary repository containing only the desired file:

 $ cd .. $ echo include a > filemap $ hg convert --filemap filemap sourcerepo temprepo initializing destination temprepo repository scanning source... sorting... converting... 1 first 0 second $ hg glog temprepo/a @ changeset: 1:a2c44f396733 | tag: tip | user: Laurens Holst <...> | date: Fri Oct 21 13:02:53 2011 +0200 | summary: second | o changeset: 0:68090379058b user: Laurens Holst <...> date: Fri Oct 21 13:02:41 2011 +0200 summary: first 

Now we create the recipient repository:

 $ mkdir destrepo $ cd destrepo $ echo zzz > z $ hg add z $ hg commit -m another $ hg glog o changeset: 0:890b51ba85c6 tag: tip user: Laurens Holst <...> date: Fri Oct 21 13:15:51 2011 +0200 summary: another 

Finally, we pull the changes from the temporary repo and merge it:

 $ hg pull --force ../temprepo pulling from ../temprepo searching for changes warning: repository is unrelated requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 2 changes to 1 files (+1 heads) (run 'hg heads' to see heads, 'hg merge' to merge) $ hg merge 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg commit -m "merge file a from sourcerepo" $ ls az $ hg glog @ changeset: 3:7becd66c019a |\ tag: tip | | parent: 0:890b51ba85c6 | | parent: 2:dc9ac503efba | | user: Laurens Holst <...> | | date: Fri Oct 21 13:39:51 2011 +0200 | | summary: merge file a from sourcerepo | | | o changeset: 2:dc9ac503efba | | user: Laurens Holst <...> | | date: Fri Oct 21 13:02:53 2011 +0200 | | summary: second | | | o changeset: 1:2a5fa6bd9021 | parent: -1:000000000000 | user: Laurens Holst <...> | date: Fri Oct 21 13:02:41 2011 +0200 | summary: first | o changeset: 0:890b51ba85c6 user: Laurens Holst <...> date: Fri Oct 21 13:15:51 2011 +0200 summary: another 

Now your file from the source repository is merged into the recipient repository, while maintaining the entire history of changes!

+5
source

You cannot do this.

You need to do this in the following steps:

  • Copy the file from one repository to another using the usual file system tools.
  • Add it to the new repository via hg add
  • Delete file from old repository via hg remove

Please note that in this process you will lose the story, as it will remain in the old repository and will not be transferred to the new one. If you need it, there are other ways associated with creating a new repository containing only this file and its history, by conversion, but this is a different topic.

You cannot convince Mercurial to work with several repositories at the same time, so there is no single command that will transfer it from one repository to another.

+3
source

All Articles