Mercurial `hg clone` but ignoring all subrepos?

后端 未结 4 1648
無奈伤痛
無奈伤痛 2021-02-04 00:37

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 t

相关标签:
4条回答
  • 2021-02-04 00:57

    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.

    0 讨论(0)
  • 2021-02-04 01:02

    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.

    0 讨论(0)
  • 2021-02-04 01:14

    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%
    
    0 讨论(0)
  • 2021-02-04 01:24

    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.

    0 讨论(0)
提交回复
热议问题