用百度搜了一遍hg的hook教程,发现真的是太少了。公司目前正要用到这个,正好本人负责,So。

百度是个坑,少有的几篇文章,再加上善于发现的眼睛,发现TortoiseHg的UI操作都会在控制台显示动作命令,结合之才有下面这个hook!

以上,是不是要转google?!

下面内容结合鄙人的这个篇文章[ 使用 PHP_CodeSniffer 检查 代码 是否 符合 编码规范 ],食用起来应该更美味!

1.编写如下sh脚本,并执行 chmod a+x 赋予执行权限:

#!/bin/bash

echo -e "\n==========================Starting PHP Syntax Check==========================\n"

#在/tmp目录下创建临时目录
TEMP_DIR=`mktemp -dt php_syntax_files.XXXXXX` #临时测试
#TEMP_DIR="/tmp/test/"
#HG_NODE="d0a1ccf22a26dfe62ae1db932dcc4972509b8f0b" HG_BIN="/usr/bin/hg"
CHECK_CMD="php /home/hg/php_codesniffer/scripts/phpcs --standard=Fenqile --tab-width=4 $TEMP_DIR"、 #输出临时目录
echo "temp dir : "$TEMP_DIR #导出当前至最新
#hg archive -r $HG_NODE:tip -t files /tmp/test
#导出当前
#hg archive -r $HG_NODE -t files /tmp/test
#全量导出
#hg archive -r tip -t files /tmp/test
#导出修改部分的代码
echo $HG_BIN" archive -I \"set:added() or modified()\" -r "$HG_NODE":tip -t files "$TEMP_DIR
$HG_BIN archive -I "set:added() or modified()" -r $HG_NODE:tip -t files $TEMP_DIR #检测代码,输出提示
echo "$CHECK_CMD"
TEST_SYNTAX=`$CHECK_CMD`
echo -e "$TEST_SYNTAX" #删除目录
echo "rm -rf "$TEMP_DIR
rm -rf "$TEMP_DIR" if [ "" == "${TEST_SYNTAX}" ] || [ "" == "${TEST_SYNTAX}" ];then
echo -e "Through code detection, allowed to push!"
exit
fi echo -e "\n\nServer detected the code has a problem, please check to submit the push again!"
echo -e "\n===============================================================================\n\n"
exit

2.在代码仓库所在目录下,编辑 [ 代码库/.hg/hgrc ] 文件,添加如下节点:

[hooks]
pretxnchangegroup = /home/hg/php_codesniffer/scripts/hg_pretxnchangegroup_hook.sh

3. 在本地添加代码版本,推送代码(hg push),效果如下:

test% hg push
% hg push
正在推到 ssh://hg@192.168.6.234//home/hg/myproject
正在搜索修改
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added changesets with changes to files
remote:
remote: ==========================Starting PHP Syntax Check==========================
remote:
remote: temp dir : /tmp/php_syntax_files.OxLrCU
remote: /usr/bin/hg archive -I "set:added() or modified()" -r d0a1ccf22a26dfe62ae1db932dcc4972509b8f0b:tip -t files /tmp/php_syntax_files.OxLrCU
remote: php /home/hg/php_codesniffer/scripts/phpcs --standard=Fenqile --tab-width= /tmp/php_syntax_files.OxLrCU
remote:
remote: FILE: /tmp/php_syntax_files.OxLrCU/test30000.php
remote: -------------------------------------------------------------------------
remote: FOUND ERROR AFFECTING LINE
remote: -------------------------------------------------------------------------
remote: | ERROR | [x] A closing tag is not permitted at the end of a PHP file
remote: -------------------------------------------------------------------------
remote: PHPCBF CAN FIX THE MARKED SNIFF VIOLATIONS AUTOMATICALLY
remote: -------------------------------------------------------------------------
remote:
remote:
remote: FILE: /tmp/php_syntax_files.OxLrCU/test40000.php
remote: -------------------------------------------------------------------------
remote: FOUND ERROR AFFECTING LINE
remote: -------------------------------------------------------------------------
remote: | ERROR | [x] A closing tag is not permitted at the end of a PHP file
remote: -------------------------------------------------------------------------
remote: PHPCBF CAN FIX THE MARKED SNIFF VIOLATIONS AUTOMATICALLY
remote: -------------------------------------------------------------------------
remote:
remote: Time: 7ms; Memory: 2Mb
remote: rm -rf /tmp/php_syntax_files.OxLrCU
remote:
remote:
remote: Server detected the code has a problem, please check to submit the push again!
remote:
remote: ===============================================================================
remote:
remote:
remote: transaction abort!
remote: rollback completed
remote: abort: pretxnchangegroup hook exited with status
[命令返回代码1 Wed Apr :: ]
test%

到此配置完毕!

ps:

https://www.mercurial-scm.org/wiki/Hook#Hook_return_values

https://selenic.com/hg/help/config

http://pear.php.net/manual/en/package.php.php-codesniffer.svn-pre-commit.php

http://stackoverflow.com/questions/4162384/mercurial-pre-commit-hook

http://www.softwareprojects.com/resources/programming/t-mercurial-hook-php-syntax-check-1976.html

https://www.mercurial-scm.org/wiki/Hook

Mercurial (hg) Hook : PHP Syntax Check , hg 代码检测 钩子的更多相关文章

  1. Mercurial 的hook使用

    1. Handling repository events with hooks可以通过Mercurial版本管理工具提供的hooks机制来处理repo的各种事件,从而实现对Mercurial的扩展, ...

  2. delphi Syntax check、 build、 run、 compile的区别

    delphi Syntax check. build.  run. compile的区别 Build是从新编译所有和生成exe有关的文件,无论.pas文件是否修改过,它都会重新生成新的.dcu,并从新 ...

  3. C# Mysql You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ????

    有几年没用过MySql数据了,今天在使用C#访问MySql数据库时出现了一个小插曲. 错误提示: You have an error in your SQL syntax; check the man ...

  4. 解决You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (order_name, customer)

    在学习hibernate一对多映射关系时,根据视频学习的时候,例子是顾客和订单的问题,一个顾客有多个订单.按照视频中的敲代码出现了You have an error in your SQL synta ...

  5. ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 7

    问题: 使用hibernate4.1.1,数据库使用mysql5.1.30,使用hibernate自动生成数据库表时,hibernate方言使用org.hibernate.dialect.MySQLI ...

  6. MySql 执行语句错误 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

    关于用Power Designer 生成sql文件出现 错误  [Err] 1064 - You have an error in your SQL syntax; check the manual ...

  7. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '

    mysql中如果字段使用了关键字,在插入和更新时会提示 You have an error in your SQL syntax; check the manual that corresponds ...

  8. mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': You have an error in your SQL syntax; check the manual t

    1.备份mysql数据库时候出错,导出数据: [root@localhost ~]# mysqldump -uroot -p mysql >/root/bck.sql Enter passwor ...

  9. [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds...

    INSERT INTO `ftms_active_dealer`(dealer_code,dealer_name,active_id,dealer_state)VALUES('415A1','贺磊'1 ...

随机推荐

  1. strip_tags、htmlentities、htmlspecialchars的区别

    一.strip_tags() 函数剥去字符串中的 HTML.XML 以及 PHP 的标签. strip_tags(string,allow) 注释:可通过allow设置允许的标签.这些标签不会被删除. ...

  2. 实战:mysql统计指定架构的全部表的数据和索引大小情况-v2

    PS:第一个版本号里未做输入的schema_name和table_name推断,改动了一下!再次share! #统计指定架构的全部表的数据和索引大小情况 #tablesize.sh #!/bin/sh ...

  3. Keras模型的导出和pb文件的转换

    Keras有两种类型的模型,序贯模型(Sequential)和函数式模型(Model),函数式模型应用更为广泛,序贯模型是函数式模型的一种特殊情况. 两类模型有一些方法是相同的: model.summ ...

  4. oracle-用户和表空间创建

    windows下 创建临时表空间 create temporary tablespace user_temp tempfile 'D:\oracle\oradata\Oracle11i\user_te ...

  5. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(三十):使用flatMapGroupsWithState替换agg

    flatMapGroupsWithState的出现解决了什么问题: flatMapGroupsWithState的出现在spark structured streaming原因(从spark.2.2. ...

  6. 了解 JavaScript (2)- 需要了解的一些概念

    Ajax 是什么 Ajax 是一种创建交互式 Web 应用程序的方式. Ajax 是 Asynchronous JavaScript and XML 缩写(异步的 JavaScript 和 XML), ...

  7. Python:提取网页中的电子邮箱

    import requests, re #regex = r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"#这个正则表达式过滤 ...

  8. IE10、IE11使用 __doPostBack 出现未定义问题

    在公司的老项目中分页控件使用了 __doPostBack 方式,在IE兼容模式下正常,在IE10.IE11中 __doPostBack 出现未定义问题. 百度查阅资料得知,这是微软NET环境下的一个B ...

  9. SpringCloud服务如何在Eureka安全优雅的下线

    如果直接KILL SpringCloud的服务,因为Eureka采用心跳的机制来上下线服务,会导致服务消费者调用此已经kill的服务提供者然后出错,处理这种情况有2中方案. 如需平滑的发布服务请参考: ...

  10. 【Linux】ps命令

    Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...