当在Mercurial存储库中的特定分支(测试分支)中进行推送时,我想向所有同事发送更改日志消息。
下面的代码。
1。挂接Merurial服务器(/var/hg/repository/.hg/hgrc)
[hook]
incoming=/home/user/incomming
Bash脚本1(/ home / user / incomming)
nohup /usr/bin/sudo -i -u user /home/user/bin/changelog.sh $HG_NODE &>/dev/null &
Bash脚本2(/home/user/bin/changelog.sh)
#we go to the sandbox repository directory
cd /home/user/hg/repository
L_BRANCH_SANDBOX=$($HG branches | $GREP testbranch | $SORT -Vr |$AWK '{print $1}')
P_BRANCH=$($HG log -r $HG_NODE | $HEAD -n 4 | $GREP branch: | $AWK '{print $2}')
if [[ "$L_BRANCH_SANDBOX" == "$P_BRANCH" ]] ; then
Some commands and send mail
fi
我看到,如果我在顶部和底部放置一些回声,则挂钩会被触发,因为我的BASH-SCRIPT1提供了输出,但是我的BASH-SCRIPT2甚至没有启动,因为它甚至在一开始都没有回声。但是,如果我以已知的$ HG_NODE手动运行它,我的BASH_SCRIPT2就会运行。
感谢您的支持
答案 0 :(得分:0)
您面临的问题是,在传入挂钩中,交易尚未完成,因此$HG_NODE
尚未成为存储库中的有效变更集-您的script2需要在其中正常工作(传输仍在进行中,因此仅在挂钩脚本script1中可用)。
由于您不希望根据变更集的易读性来判断变更集,因此您可能想在事务已完成时在挂钩中执行操作,例如 txnclose 钩子:
"hooks.txnclose" Run after any repository transaction has been committed. At this point, the transaction can no longer be rolled back. The hook will run after the lock is released. See 'hg help config.hooks.pretxnclose' for details about available variables. "hooks.pretxnclose" Run right before the transaction is actually finalized. Any repository change will be visible to the hook program. This lets you validate the transaction content or change it. Exit status 0 allows the commit to proceed. A non-zero status will cause the transaction to be rolled back. The reason for the transaction opening will be in "$HG_TXNNAME", and a unique identifier for the transaction will be in "HG_TXNID". The rest of the available data will vary according the transaction type. New changesets will add "$HG_NODE" (the ID of the first added changeset), "$HG_NODE_LAST" (the ID of the last added changeset), "$HG_URL" and "$HG_SOURCE" variables. Bookmark and phase changes will set "HG_BOOKMARK_MOVED" and "HG_PHASES_MOVED" to "1" respectively, etc.
无论如何,我建议:只有挂钩才能访问存储库。并将要邮寄或进一步处理的所有数据作为直接输入移交给脚本 script2 ,这样就无需再次查询存储库。