문제

We have a Mercurial repository with many projects, each resides in its own directory:

- Main Repo
  - Project A
  - Project B
  - ...

Each of the projects is self contained and must reside in it's own directory, but there are some common files that should be similar between projects.

For example, some projects are websites, and they share a common javascript library we develop. When changing the library in one project, we would like it to change in other projects too, but the file must reside in each of the projects.

I read about sub-repos but they don't seem a good solution for this.

Is there a way to accomplish this in Mercurial?

도움이 되었습니까?

해결책

You are looking for a feature for keeping the same file version in multiple places, also known as file cloning or file sharing in other types of source control, like Sourcesafe or Vault. There is no mechanism like this in Mercurial. Every file is a single entity with a single location.

The first solution you have is to keep the common libraries in a separate place. You need a single copy that can be accessed by all your projects. It does not matter if you use sub-repos or not, they can all be in the same repo, as long as your folder structure includes everything, but sub-repos can be easier to manage if your projects are not related.

The other solutions you have could be to state an internal policy to always sync and commit the common libraries manually (which I do not suggest as it is error-prone and requires effort), or to create a script, either as hook or not, to sync your files, before a commit or after an update (which is more tedious to establish and maintain anyway)...

Conclusion, go for the separation of your common libraries. You'll be glad you spent the extra time to set everything up correctly from the start.

다른 팁

In my experience (local Linux repository) using symlinks to handle shared files works but it's usually better to create a library that contains the common files.

Even if you have one repository for all your projects, it is advised to have a separate library/tool/etc. repository(ies) for the common code(s).

The way you can "use" this code inside your project will then heavily depend on your technology and infrastructure: java/maven/ant world, linux distrib, ruby gems etc. You will generally have some kind of "dependencies specification" language where you can specify that you need such and such library. In a Gemfile for rails, using autoconf for C/C++ etc. Most of the time you can also specify a specific version (or greater than etc..) which allows taking care of API changes.

Basically it is not advised to solve this issue at SCM level but instead to use the right framework for decoupling your common code from the projects repositories.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top