mercurial:包括precommit-changed文件

时间:2012-07-29 11:38:02

标签: mercurial mercurial-hook

在提交到存储库时,我在Mercurial中定义了一个钩子:

[hooks]
precommit.exportDB=exportDB.bat

这将从我的数据库创建/更新SQL转储,该转储应包含在提交中。 但是:虽然这有效,但Sql被标记为新的,但不是现在提交的变更集的一部分。 如何自动包含它以使其进入已更改的文件集?

希望这是有道理的......

THX 莱因哈德

1 个答案:

答案 0 :(得分:6)

这听起来很疯狂,但你可以分两步完成。首先将precommit挂钩更改为pre-commit挂钩 - 是的,两者都存在且它们不同。没有破折号,提交已经开始并且已经获得了一些锁定。使用破折号,它会在提交开始之前发生,您仍然可以hg add新文件。

在unix上,总改变是:

[hooks]
pre-commit.exportDB=exportDB.sh && hg add resulting.sql

可能在Windows上有类似的东西,或者你可以将hg add作为批处理文件的最后一行。

P.S。不要提交生成的文件。 :)

<强>更新

我刚试过这个,它按照我的建议运作:

ry4an@four:~$ hg init reinhard
ry4an@four:~$ cd reinhard/
ry4an@four:~/reinhard$ vi .hg/hgrc
ry4an@four:~/reinhard$ cat .hg/hgrc 
[hooks]
pre-commit = hg add otherfile
ry4an@four:~/reinhard$ echo text > afile
ry4an@four:~/reinhard$ echo more > otherfile
ry4an@four:~/reinhard$ hg add afile
ry4an@four:~/reinhard$ hg status
A afile
? otherfile
ry4an@four:~/reinhard$ hg commit -m 'message'
ry4an@four:~/reinhard$ hg status --all
C afile
C otherfile

请注意,在提交之前只添加'afile'并且'otherfile'是未知的,并且在提交之后两个文件都是'C'(意思是“清理” - 它们已被添加并提交)。

相关问题