Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial `hg clone` but ignoring all subrepos?

Tags:

mercurial

Is there a way to clone a repo that comes with subrepos, but without having Mercurial pull all the subrepos?

It appears that while hg clone -U can be used to obtain an empty clone of a repo, there's nothing that would convince hg update to avoid starting off by pulling all of the subrepos.

I should point out that it is crucial to retain the ability to easily sync to the head revision after creating such a clone.

like image 221
Roman Starkov Avatar asked Aug 08 '10 23:08

Roman Starkov


4 Answers

This should do what you want:

REM Take a new clone, but do not update working directory
hg clone --noupdate %REPO_PATH% %DESTINATION%

REM Update working directory but exclude the certain subprojects
hg revert --all --rev %BRANCH% --exclude %SUBREPO_PATH_1% --exclude %SUBREPO_PATH_2%
like image 197
asdf Avatar answered Nov 18 '22 16:11

asdf


This answer may add more than the question required, but provides some valuable notes on working with Mercurial when you can't update do to a bad subrepository path or revision.

Step 1: Clone the repository without any updates

hg clone --noupdate source_repository destination_repository

Step 2: Use revert to get the right files

hg revert --all --rev revision_number --exclude subrepo_1 --exclude subrepo_2 ...

At this point, you have a new changeset; you may need to make sure the parent revision is correct. When I did this, my new changeset's parent was changeset 0. To fix this I had to set the parent changeset AND switch branches (since my changeset was on a different branch).

Step 3: Change the parent of the current changes

hg debugsetparents revision_number
hg branch branch_name

That should do it.

like image 40
Robert Altman Avatar answered Nov 18 '22 16:11

Robert Altman


Found a hacky way. It still requires all subrepos to be checked out once, but afterwards they can be deleted.

  1. Clone the whole lot, including subrepos. No way around this.
  2. Delete subrepos
  3. hg remove .hgsub

I tried to convince Mercurial to hg remove .hgsub before the subrepos are cloned, but the best I got is not removing .hgsub: file is untracked.

like image 5
Roman Starkov Avatar answered Nov 18 '22 15:11

Roman Starkov


If you have a subrepo, a working directory must include some version of that subrepo. That version may be a fixed older revision if specified, or the tip if not.

You cannot update your repo without getting the subrepos; if you had a complete working dir without them, you shouldn't be using subrepos - use truly external repos instead.

If your subrepos are pegged against a certain remote version, then updates after the first will not trigger a subrepo update - they're already up-to-date. But for the initial creation of the working directory, you will have to do a remote pull.

You can trick Mercurial by munging the hgsubstate file. But really, your model and the conceptual model differ, so you're probably not a good match for subrepos if this is a concern.

edit: If you find yourself cloning and then updating to the tip many times, try using local branches or mq instead. That way you only have to do the initial clone once.

like image 3
Borealid Avatar answered Nov 18 '22 14:11

Borealid