简体   繁体   English

禁用特定回购源的Mercurial Hook

[英]Disabling Mercurial Hooks For Specific Repo Sources

On my computer I have some Mercurial commit hooks that run on every commit that make sure I branch correctly and do a few other things. 在我的计算机上,我有一些Mercurial提交挂钩,可以在每次提交时运行,确保我正确分支并执行其他一些操作。 But I only need these for work projects. 但我只需要这些用于工作项目。

Here are the hooks implemented in my ~/.hgrc file: 以下是我的〜/ .hgrc文件中实现的钩子:

[hooks]
# This hook will warn you if you make a commit directly to trunk.
pretxncommit.default_check=/virtualhosts/mercurial-hooks/default_check.sh

# This hook will warn you if you branch from something other than default.
pretxncommit.branch_check=/virtualhosts/mercurial-hooks/branch_check.sh

For my personal projects I don't want to use the same, annoying hooks (which are set to global). 对于我的个人项目,我不想使用相同的,恼人的钩子(设置为全局)。 I would like all of the repos I checkout from bitbucket to not use those hooks. 我想从bitbucket结帐的所有回购都不使用那些钩子。 How can I set it up to do this? 如何设置它呢?

Create a file called from_bitbucket.sh that contains the following: 创建一个名为from_bitbucket.sh的文件,其中包含以下内容:

#!/bin/sh
test -f $HG_PENDING/.hg/hgrc || exit 1
egrep -q 'default.*bitbucket\.org' $HG_PENDING/.hg/hgrc || exit 1
exit 0

Give the script execute permission (eg, chmod 755 from_bitbucket.sh ) and move it to whatever directory you want to keep it in permanently. 给脚本执行权限(例如, chmod 755 from_bitbucket.sh )并将其移动到您希望永久保留的任何目录。

Change your hooks to something like: 将你的钩子改为:

pretxncommit.default_check=/path/to/from_bitbucket.sh || /virtualhosts/mercurial-hooks/default_check.sh

This will first execute from_bitbucket.sh and abort early with success if the script succeeds. 如果脚本成功,这将首先执行from_bitbucket.sh并提前中止。 The script checks only if there's a line matching default.*bitbucket\\.org in your repository's .hg/hgrc file (which should generally exist in the [paths] section if you push to/pull from bitbucket). 该脚本仅检查存储库的.hg/hgrc文件中是否存在与default.*bitbucket\\.org匹配的行(如果您从bitbucket推送/拉取,则通常应存在于[paths]部分中)。 It will fail if there's no .hg/hgrc or if the file doesn't contain a matching line. 如果没有.hg/hgrc或者文件不包含匹配的行,它将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM