Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Mercurial subrepository to always point to a certain changeset or tag?

I am curious if this is possible with Mercurial. I'd like to have a subrepos in a project that are always fixed to the manually specified changeset, or better yet - tag.

Basically what I am trying to achieve is to have a core system in the main repo and then all the modules and components in subrepos, but I don't want those subrepos to point to tip, only to the major releases of those components/modules(hence tags).

like image 231
Alex N. Avatar asked Dec 17 '11 01:12

Alex N.


People also ask

What is a subrepository in mercurial?

When you create (or update) a subrepository, Mercurial takes a snapshot of the subrepo’s state and stores it in the parent repository’s .hgsubstate file. This means that multiple projects can point to a single shared subrepository, yet each one can independently decide which revision of the shared repository to rely on.

How to recurse through subrepositories?

hg commit and hg update go recursively through the subrepositories. If there is no change in a subrepository during a command, then there will of course not be committed to that subrepository. Other commands that can work on subrepositories need a --subrepos option to recurse through the subrepositories.

How are the subrepositories of a repository updated?

Therefore the repository is first updated and then the subrepositories are updated according to the updated version of the .hgsubstate file. This might also involve pulling from the subrepository path, if the revision in the .hgsubstate file has not yet been pulled. hg commit and hg update go recursively through the subrepositories.

How do I commit changes to a submodule in mercurial?

From this dialog you can click the ‘Commit’ button next to the submodule and commit those changes with a message of your choosing, separate to the parent repo commit message. In Git, the ‘Skip’ button at the bottom is enabled so you can just leave the changes uncommitted if you like, but Mercurial doesn’t allow this.


1 Answers

Subrepositories work exactly like you want.

Mercurial never automatically update the subrepo to the tip. It always stays at the changeset you choose. From the documentation:

Subrepos don't automatically track the latest changeset of their sources. Instead, they are updated to the changeset that corresponds with the changeset checked out in the top-level changeset. This is so developers always get a consistent set of compatible code and libraries when they update.

To achieve what you want, you can follow the following steps:

  1. echo subrepo = https://example.com/subrepo/repo/path > .hgsub
  2. hg add .hgsub
  3. hg clone https://example.com/subrepo/repo/path subrepo
  4. hg -R subrepo update mytag
  5. hg commit

This will create a subrepo directory with the content of the specified repository which will stay on the mytag tag as long as you don't update manually to something else!

Everyone who clones your repository will have the subrepo on the same changeset as you (ie mytag).

FYI, the changeset to which a subrepo is updated is stored in the .hgsubstate file at the root of the main repository.

like image 57
krtek Avatar answered Oct 18 '22 18:10

krtek