Paul Nathan
Paul Nathan

Reputation: 40299

Sharing files in a managed approach between hg repos

Problem: One hg repository has a file I want to update & maintain in another hg repository, and I do not want to copy & paste. I do want to have the file available in both repos.

Scenario:

Working on Product 0001

Project A has an hg repository.

Down the road, a Project B is spun up. There is largely no coupling between Project A and B, but there are some files that could be shared.

Version controlling files in a managed approach is critical: copy & pasting is not a viable solution.

There are some solutions that may work -

Extending this issue is the concept of sharing certain files between Products. Somehow, a file needs to be shared and correctly tracked as being a singular file, but in two different Products.

The general problem might be stated as this -

Given a set of products, each with their own repository, under development which share and develop upon files living in each other's repositories (think utility routines and frameworks), what is the hg solution to maintaining file-version consistently between products.

What is a good solution here?

Upvotes: 4

Views: 668

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78330

Your second call is correct. You should extract the files that would be in both repositories and make that a third repo, which you in turn make a sub repo for each of project A and project B.

I don't know when you first looked at subrepos, but they've been around for a year now and are supported quite well.

Read a few of the subrepo related answers here on stack overflow, make sure to make your subrepo paths relative (not absolute w/ http:// etc.) in them and they'll treat you very well.

Update:

Today's 1.7 release of mercurial includes these enhancements for subrepos:

  • support remapping of subrepository source paths (see [subpaths] in hgrc(5))
  • make add, diff, incoming, outgoing and status commands recurse into subrepos with --subrepos/-S
  • subrepo: add support for 'hg archive'
  • subrepo: fix status check on SVN subrepos (issue2445)

Upvotes: 3

Related Questions