Using subrepositories with bitbucket and ToritoiseHg

為{幸葍}努か 提交于 2019-12-05 08:58:11

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!