mercurial: including precommit-changed file

霸气de小男生 提交于 2019-12-08 03:37:59

问题


On commit to repository I have a hook defined in Mercurial:

[hooks]
precommit.exportDB=exportDB.bat

This creates/updates a SQL-dump from my database, which should be included in the commit. BUT: although this works, the Sql is marked as new, but not part of the now commiting changeset. How can I automatically include it so it gets into the set of changed files?

Hope this makes sense...

Thx Reinhard


回答1:


This'll sound crazy, but you can do it in two steps. First change your precommit hook to a pre-commit hook -- yup, both exist and they're different. Without the dash the commit has already started and some lock has been acquired. With the dash it happens before the commit starts and you can still hg add the new file.

On a unix like that total change would be:

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

presumably there's something similar on Windows, or you could make the hg add the last line of the batch file.

P.S. Don't commit generated files. :)

Update:

I just tested this and it works as I suggested:

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

Notice that before the commit only 'afile' is added and 'otherfile' is unknown, and after the commit both files are 'C' (meaning "Clean' -- they've been added and committed).



来源:https://stackoverflow.com/questions/11708929/mercurial-including-precommit-changed-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!