Mercurial (hg) Hook : PHP Syntax Check , hg 代码检测 钩子
用百度搜了一遍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 代码检测 钩子的更多相关文章
- Mercurial 的hook使用
1. Handling repository events with hooks可以通过Mercurial版本管理工具提供的hooks机制来处理repo的各种事件,从而实现对Mercurial的扩展, ...
- delphi Syntax check、 build、 run、 compile的区别
delphi Syntax check. build. run. compile的区别 Build是从新编译所有和生成exe有关的文件,无论.pas文件是否修改过,它都会重新生成新的.dcu,并从新 ...
- 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 ...
- 解决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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- [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 ...
随机推荐
- .net framework 4.6 asp.net mvc 使用NLog
NUGET添加NLog和NLog.Config的引用 配置NLog.config <?xml version="1.0" encoding="utf-8" ...
- C/C++中的常量指针与指针常量(转)
常量指针 常量指针是指向常量的指针,指针指向的内存地址的内容是不可修改的. 常量指针定义“const int *p=&a;”告诉编译器,*p是常量,不能将*p作为左值进行操作.但这里的指针p还 ...
- 树莓派3中安装JDK
一.简介 树莓派3(Raspbian系统,下载地址:https://www.raspberrypi.org/downloads/raspbian/),安装JDK8,直接运行:apt-get insta ...
- Windows 8系统默认开启的.Net Framework版本是4.0,而部分用户可能需要使用到3.5或以下版本,简单添加方法
从网络途径下载的.Net Framework3.5是无法直接在Windows 8系统上安装的,我们可以通过Windows 8的添加功能来实现 1.打开控制面板,点击”启用或关闭Windows 功能“ ...
- Linux内核剖析(一)Linux的历史
Unix操作系统 Unix的由来 汤普逊和里奇最早是在贝尔实验室开发Unix的,此后的10年,Unix在学术机构和大型企业中得到了广泛的应用,当时的UNIX拥有者AT&T公司以低廉甚至免费的许 ...
- SED单行脚本快速参考(Unix 流编辑器)(转)
sed.sourceforge.net被封杀,特在此处贴上官方的sed 使用说明文档 SED单行脚本快速参考(Unix 流编辑器) 2005年12月29日 英文标题:USEFUL ONE-LINE S ...
- SNF快速开发平台MVC-EasyUI3.9之-DataGrid表格控件如何增加右键菜单
如题,我们在项目开发当中会遇到需要,表格控件增加右键菜单的使用. 下面我们就以SNF框架增加右键菜单步骤如下: 1.在加载页面当中增加如下菜单定义 <div id="mm" ...
- xml解析、写入遇到的坑
前言 最近在看一个线上xml文件导出的问题,需求如下: 从我们平台导出一个后缀为tmx的术语语料数据(实际内容为xml文件),然后导入到其他第三方平台发现无法导入. 从其他平台导入的tmx文件无法导入 ...
- 2018年末--积极拥抱h5.转载 大前端时代来临,我们何去何从?
1.大前端时代是什么? 大前端时代是WEB统一的时代,利用html5或者6甚至7,不但可以开发传统的网站,做炫酷的网页动态效果,更可以采用BS架构应用程序.开发手机端web应用.移动端Native应用 ...
- [转](OS 10038)在一个非套接字上尝试了一个操作 的解决办法
原文: http://blog.csdn.net/zooop/article/details/47170885 可能是安装了某些程序修改了Winsock,使用netsh winsock reset 命 ...