I have subrepository structure as following in TortoiseHg:
/MainFolder/
/MainFolder/SubFolder1
/MainFolder/SubFolder2
MainFolder is a private repository on bitbucket SubFolder1 is a private repository on bitbucket SubFolder2 is a private repository on bitbucket
The file .hgsub inside MainFolder looks like this:
SubFolder1 = SubFolder1
SubFolder2 = SubFolder2
The file .hgsubstat inside MainFolder also have valid guids and subrepository names.
The problem is whenever I try to push to bitbucket for MainFolder, first it pushes the MainFolder, then SubFolder1, but when it gets to SubFolder2, TortoiseHg throws error "abort: repository is unrelated".
When i check my MainFolder repository on bitbucket, it has actually contents of SubFolder1 (it should be listed there as subrepository).
How can I fix this so that the MainFolder is correctly uploaded as parent repository and SubFolder1 and SubFolder2 are listed as its sub-repository on bitbucket?
The example shown in bitbucket documentation requires to rename repositories so that all the repositories are named as MainRepository-SubRepository. I didn't want to rename all my repositories so modified the regular expression as shown in following example and it works correctly now. This version doesn't require the dash separator in repository name, Main repository and sub repositories can be named independently. The example .hgsub looks like this:
SubFolder1 = SubFolder1
SubFolder2 = SubFolder2
[subpaths]
(https://(?:[^@]+@)?bitbucket\.org/[^/]+)(/[^/]+)/(.*) = \1/\3
Bitbucket doesn't do subrepos in situ. As a result, Mercurial is attempting to push every one of your repositories to the same location, and complains when you try to push the repo SubFolder2 into a remote copy of the SubFolder1 repo.
Subrepositories are ostensibly libraries that are shared between multiple projects, and therefore don't live under any one main repo but instead in their own space. Therefore, you must create separate remote repositories to house each subrepository (library) and reference that separate remote path in the .hgsub file.
For example, your example project could have three bitbucket-hosted repositories
https://bitbucket.org/bitbucketname/main_project
https://bitbucket.org/bitbucketname/library1
https://bitbucket.org/bitbucketname/library2
You want your local clone's filespace to look like this:
/MainFolder/
/MainFolder/SubFolder1
/MainFolder/SubFolder2
In your local clone of main_project (MainFolder), set the default path of the parent repository to https://bitbucket.org/bitbucketname/main_project
i.e., /MainFolder/.hg/hgrc
contains
[paths]
default = https://bitbucket.org/bitbucketname/main_project
Now, indicate the remote paths of the subrepositories/libraries in the .hgsub file. The general format of the .hgsub entries is:
local/path/to/subrepo = remote/path/to/matching/library
So your .hgsub might contain relative local and remote paths (relative to the location of the main repo locally or remotely, as the case may be):
SubFolder1 = ../library1
SubFolder2 = ../library2
or relative local paths with absolute paths to each library's remote repo:
SubFolder1 = https://bitbucket.org/bitbucketname/library1
SubFolder2 = https://bitbucket.org/bitbucketname/library2
or absolute paths for everything:
/MainFolder/SubFolder1 = https://bitbucket.org/bitbucketname/library1
/MainFolder/SubFolder2 = https://bitbucket.org/bitbucketname/library2
Now, when you push from your local main project, Mercurial knows exactly where to find all subrepositories (locally) and where to push the changes made to each library (remotely).
Additionally, let's say you want to add someone else's library to your project. Then your .hgsub might look something like this:
SubFolder1 = ../library1
SubFolder2 = ../library2
another_library = https://bitbucket.org/honkaboy/honkaboys_excellent_library
来源:https://stackoverflow.com/questions/13750664/using-subrepositories-with-bitbucket-and-toritoisehg