Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial to Bitbucket - Subrepository - Repository is unrelated error

Here are the steps I've taken to build the repo and subrepos.

Everything is hosted on Bitbucket.

  1. Per best practices, created a skeleton repo to hold all of the subrepos. Cloned to my machine.
  2. Cloned primary project as subrepo1 (within the mainrepo directory structure).
  3. Added primary project to mainrepo as a subrepo1.
  4. Committal of mainrepo works as expected.
  5. Pushed successfully mainrepo and subrepo1 to Bitbucket.
  6. Proceeded to clone another subrepo2 to mainrepo directory.
  7. Added subrepo2 to mainrepo as subrepo2
  8. Committal of mainrepo works as expected.
  9. Push of mainrepo results in "Repository is unrrelated" error after is "searching for changes" Error occurs only on the newly added subrepo2.

Here is directory structure: mainrepo --subrepo1 (main project) --subrepo2 (class library)

I've spent countless hours trying to get this working and I must be missing something obvious.

What is causing this error and what am I missing? I need to be able to add additional subrepos as the project grows.

like image 935
faldeland Avatar asked Dec 14 '12 22:12

faldeland


1 Answers

The steps that I took to make my example are as follows:

  1. Create MainRepo on BitBucket
  2. Create SubRepo on BitBucket
  3. Clone MainRepo
  4. Clone SubRepo as a sub-directory of MainRepo
  5. Manually create the .hgsub file with the contents SubRepo = ../SubRepo
  6. Add the .hgsub file to MainRepo, commit and push
  7. Create SubRepo2 on BitBucket
  8. Clone SubRepo2 as a sub-directory of MainRepo
  9. Manually edit .hgsub and add SubRepo2 = ../SubRepo2
  10. Commit and push MainRepo again

From then on, I could edit either of the two sub-repositories and see that they had changed when looking at MainRepo in the workbench. I could then commit the changes to the sub-repositories, commit the sub-repository states in MainRepo and push all three repositories with a single push from MainRepo

The way that you said that it was set up by TortoiseHg in your other question (subrepo = subrepo) won't work with BitBucket because of how their structure is. I think that you can only have repositories at the top level like this:

bitbucket.org/SteveKaye/MainRepo
bitbucket.org/SteveKaye/SubRepo

whereas having the line subrepo = subrepo is trying to set up a structure like this:

bitbucket.org/SteveKaye/MainRepo
bitbucket.org/SteveKaye/MainRepo/SubRepo

When you push this it looks like it is trying to push SubRepo into MainRepo which would explain the unrelated repository error message that you are getting.

The .hgsub syntax is such that the left of the equals defines the folder in the working copy where the repository will be and the right of the equals defines where to get it from. When the right of the equals is a relative path, it defines where the sub-repository is on the central server relative to the main repository. So in the example above, you go up one folder to bitbucket.org/SteveKaye and the SubRepo is contained in that folder.

The documentation says:

The source path of a Mercurial repository can either be a relative or absolute path or URL. It is generally recommended to use trivial relative paths where the source path is the same as the working dir path: This will ensure that the subrepositories always can be found 'in place'.

Other relative paths can be used if the subrepositories can't be hosted 'in place', for example because of limitations of a central repository or hosting service. A consequence of using such non-trivial relative paths is that clones can't be cloned.

This looks relevant to your situation when using BitBucket and I'd expect that your clones can't be cloned as it says in the last sentence.

like image 156
Steve Kaye Avatar answered Oct 23 '22 14:10

Steve Kaye