In Mercurial, one way to share code amongst projects, is to create a 'super' repository for each project that wants to use common code.
You then have the common code in one or more Mercurial repositories.
You re-use the repositories, as sub repositories of what I call 'super' repositories.
The 'super' repository only contains 1 file .hgsub which tells Mercurial which sub repositories to pull/push.
Here are some rough notes on creating a Hg super repository:
1. create a directory for the new super repository
mkdir hg_PRS_with_Common
cd hg_PRS_with_Common
2. create a file .hgsub
echo # > .hgsub
The file should have contents like this, where the values are simply the names of the sub repositories (the top level directory of each repository that shows the green Hg icon)
hg_OdinCommon = hg_OdinCommon
hg_PRS_main = hg_PRS_main
3. copy the sub repositories to the appropriate sub directory.
For example, hg_OdinCommon should be in the subdirectory hg_OdinCommon (and not intermediate directories)
C:\shared\hg_PRS_with_OdinCommon>tree /f | more
Folder PATH listing for volume OS
Volume serial number is BCE0-FD4B
C:.
│ .hgsub
│ .hgsubstate
│ fetch_all.bat
│
├───.hg
│ │ 00changelog.i
│ │ dirstate
.....
.....
├───hg_OdinCommon
│ ├───.hg
│ │ │ 00changelog.i
│ │ │ branch
│ │ │ dirstate
│ │ │ hgrc
│ │ │ requires
│ │ │ thgstatus
│ │ │
.....
.....
└───hg_PRS_main
│ .hgignore
│
├───.hg
│ │ 00changelog.i
│ │ branch
│ │ dirstate
│ │ hgrc
│ │ requires
│ │ thgstatus
4. only now should you create the new super-repo:
hg init
hg add
hg ci -m"creating new super repo"
5. test the new super repo, by opening a cmd line at a new location, and cloning the super repo
hg clone ...\super-repo
you should get a full copy of all of the sub-repos.
hg commands + sub-repos
the following commands work automagically from the super-repo:
hg fetch
hg pull
other commands have a special -subrepo switch:
hg diff --subrepo
hg st --subrepo
and hg ci is different again!
hg ci --subrepos
the official documentation: http://mercurial.selenic.com/wiki/Subrepository
You then have the common code in one or more Mercurial repositories.
You re-use the repositories, as sub repositories of what I call 'super' repositories.
The 'super' repository only contains 1 file .hgsub which tells Mercurial which sub repositories to pull/push.
Here are some rough notes on creating a Hg super repository:
1. create a directory for the new super repository
mkdir hg_PRS_with_Common
cd hg_PRS_with_Common
2. create a file .hgsub
echo # > .hgsub
The file should have contents like this, where the values are simply the names of the sub repositories (the top level directory of each repository that shows the green Hg icon)
hg_OdinCommon = hg_OdinCommon
hg_PRS_main = hg_PRS_main
3. copy the sub repositories to the appropriate sub directory.
For example, hg_OdinCommon should be in the subdirectory hg_OdinCommon (and not intermediate directories)
C:\shared\hg_PRS_with_OdinCommon>tree /f | more
Folder PATH listing for volume OS
Volume serial number is BCE0-FD4B
C:.
│ .hgsub
│ .hgsubstate
│ fetch_all.bat
│
├───.hg
│ │ 00changelog.i
│ │ dirstate
.....
.....
├───hg_OdinCommon
│ ├───.hg
│ │ │ 00changelog.i
│ │ │ branch
│ │ │ dirstate
│ │ │ hgrc
│ │ │ requires
│ │ │ thgstatus
│ │ │
.....
.....
└───hg_PRS_main
│ .hgignore
│
├───.hg
│ │ 00changelog.i
│ │ branch
│ │ dirstate
│ │ hgrc
│ │ requires
│ │ thgstatus
4. only now should you create the new super-repo:
hg init
hg add
hg ci -m"creating new super repo"
5. test the new super repo, by opening a cmd line at a new location, and cloning the super repo
hg clone ...\super-repo
you should get a full copy of all of the sub-repos.
hg commands + sub-repos
the following commands work automagically from the super-repo:
hg fetch
hg pull
other commands have a special -subrepo switch:
hg diff --subrepo
hg st --subrepo
and hg ci is different again!
hg ci --subrepos
the official documentation: http://mercurial.selenic.com/wiki/Subrepository
after a bit more experience with sub-repos in Mercurial, I find the following:
ReplyDelete- some parts of Mercurial do seem to not fully support sub-repos:
- hgweb (the web server)
- hg fetch
- cloning a 'super-repo' can make it painful to keep the original sub-repo up to date
- Jenkins CI will not detect changes to a super-repo, so no CI build will trigger,
and changes will not show in the build summaries
- it is generally simpler to have common code in a separate repository, and NOT use sub-repos
sub-repos - good for using code from an external project
The only time I find sub-repos useful, is when I am using code from an external site,
such as an open source host like bitbucket.com
In this case, a project can use a sub-repo for code that is external and you only need to fetch and push occasionally.
eating my words here ...
ReplyDeleteif you launch the web server from Windows Explorer
(browse to inside repository, select TortoiseHg | WebServer
then a web server launches,
and it DOES handle sub repositories.
however not sure how to do this on the cmd line