Using subrepositories with bitbucket and ToritoiseHg
Asked Answered
D

2

5

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?

Dunigan answered 6/12, 2012 at 19:3 Comment(1)
I also tried using [subpaths] as shown in example for subrepository at link. I added following to end of my .hgsub file: (https://(?:[^@]+@)?bitbucket\.org/[^/]+/[^/]+)/(.*) = \1-\2 This didn't work either as the repository doesn't exist for the replaced UI. Is there any other way to do this without renaming all my repositories to match the regular expression. Also since this is private repository bitbucket adds user name to the formatted link and it fails for other users.Dunigan
D
5

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
Dunigan answered 8/12, 2012 at 23:21 Comment(0)
U
2

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
Unmeet answered 12/7, 2015 at 3:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.