3

I am reading up on subrepos, and have been running some tests locally, seems to work OK so far, but I have one question.

How do I specify/control which changeset I want to use for a particular subrepo?

For instance, let's say I have the following two projects:

class library                    application
o    fourth commit               o   second commit, added a feature
|                                |
o    third commit                o   initial commit
| 
| o  second commit
|/
o    initial commit

Now, I want the class library as a subrepo of my application, but due to the immaturity of the longest branch (the one ending up as fourth commit), I want to temporarily use the "second commit" tip.

How do I go about configuring that, assuming it is even possible?

Here's a batch file that sets up the above two repos + adds the library as a subrepo.

If you run the batch file, it will output:

[C:\Temp] :test
...
v4

As you can see from that last line there, it verifies the contents of the file in the class library, which is "v4" from the fourth commit. I'd like it to be "v2", and persist as "v2" until I'm ready to pull down a newer version from the class library repository.

Can anyone tell me if it is possible to do what I want, and if so, what I need to do in order to lock my subrepo to the right changeset?

Batch-file:

@echo off
if exist app rd /s /q app
if exist lib rd /s /q lib
if exist app-clone rd /s /q app-clone


rem == app ==
hg init app
cd app
echo program>main.txt
hg add main.txt
hg commit -m "initial commit"
echo program+feature1>main.txt
hg commit -m "second commit, added a feature"
cd ..

rem == lib ==
hg init lib
cd lib
echo v1>lib.txt
hg add lib.txt
hg commit -m "initial commit"
echo v2>lib.txt
hg commit -m "second commit"
hg update 0
echo v3>lib.txt
hg commit -m "third commit"
echo v4>lib.txt
hg commit -m "fourth commit"
cd ..

rem == subrepos ==
cd app
hg clone ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

rem == clone ==
hg clone app app-clone

type app-clone\lib\lib.txt

Edit: Ok, I got my answer, thanks @VonC, I added the following section to my batch-file, above the rem == clone == line, and re-executed it, and now it locks the subrepo to the correct changeset.

rem == lock ==
cd app\lib
hg update 1
cd ..
hg commit -m "lock to second commit"
cd ..
4

2 回答 2

3

如果您没有明确选择这样做,您的子回购修订将不会被推进,所以您所要做的就是按照您最初的意愿进行设置。最初创建子存储库时,只需使用“-r”参数仅克隆到您想要的变更集:

rem == subrepos ==
cd app
hg clone -r CHANGESETYOUWANT ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

注意第三行的修改。

于 2010-05-19T16:56:20.827 回答
3

未经测试,但您应该能够进入您的子存储库,将其内容更新为正确的提交 ( hg update),返回上一级(在主项目中)并提交。
那应该.hgsubstate用正确的提交更新。

(极端的解决方法,自己更新.hgsubstate,但不建议这样做。)

hg subrepos (或 Git 子模块)的全部想法是通过引用给定子 repo 的固定id来允许依赖管理。如果在创建子存储库时没有给出 id,则选择最新的 id(在您的情况下为 v4),但您可以签出您需要的任何 id。

实际上,这个帖子甚至抱怨说:

现在,提交递归地尝试在提交当前存储库之前提交子存储库。

这使您可以:

  • 在 sub-repo 中记录一些变化。
  • 使用子存储库的新状态 (id)更新 .hgsubstate主项目的。
于 2010-05-19T16:49:49.407 回答