Mercurial (Hg) hook:php Syntax Check, HG code detection hooks

Source: Internet
Author: User
Tags closing tag mercurial

With Baidu searched the Hg Hook tutorial, found that really is too little. The company is going to use this, just I am responsible, so.

Baidu is a pit, a few articles, coupled with a good eye to find the Tortoisehg UI operation will be displayed in the console action command, combined with the following this hook!

Above, is not going to turn google?!

The following is a combination of this article [using Php_codesniffer to check if the code conforms to coding specification], edible should be more delicious!

1. Write the following SH script and execute chmod a+x to give Execute permission:

#!/bin/BashEcho-E"\n==========================starting PHP Syntax check==========================\n"#在/Create temp directory under TMP directory 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# Export Current to latest #hg archive-R $HG _node:tip-t files/tmp/test# Export current #hg archive-R $HG _node-t files/tmp/test# Full Volume export #hg archive-R tip-t files/tmp/test# Exporting the modified part of the CodeEcho$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# detection code, output hintsEcho "$CHECK _cmd"Test_syntax=' $CHECK _cmd 'Echo-E"$TEST _syntax"#删除目录Echo "RM-RF"$TEMP _dirRM-rf"$TEMP _dir"if["0"=="${test_syntax}"]; Then    Echo-E"Through code detection, allowed to push!"Exit0fiEcho-E"\n\nserver detected The code has a problem and check to submit the push again!"Echo-E"\n===============================================================================\n\n"Exit1

2. In the directory where the Code warehouse is located, edit the [code library/.HG/HGRC] File and add the following node:

=/home/hg/php_codesniffer/scripts/hg_pretxnchangegroup_hook. SH

3. Add the code version locally, push the code (HG push), the effect is as follows:

test%HG Push%The HG push is being pushed toSSH://[email protected]//Home/hg/myprojectsearching for modifications remote:adding changesetsremote:adding manifestsremote:addingfilechangesremote:added3Changesets with8Changes to3Filesremote:remote:==========================starting PHP Syntax check==========================remote:remote:tempdir:/tmp/Php_syntax_files. Oxlrcuremote:/USR/BIN/HG Archive-i"set:added () or modified ()"-R d0a1ccf22a26dfe62ae1db932dcc4972509b8f0b:tip-t files/tmp/Php_syntax_files. oxlrcuremote:php/home/hg/php_codesniffer/scripts/phpcs--standard=fenqile--tab-width=4/tmp/Php_syntax_files. OxLrCUremote:remote:FILE:/tmp/php_syntax_files. oxlrcu/Test30000.phpremote:-------------------------------------------------------------------------Remote:found1ERROR affecting1Lineremote:-------------------------------------------------------------------------Remote:7| ERROR | [x] A closing tag is not permitted at the end of a PHPfileRemote:-------------------------------------------------------------------------REMOTE:PHPCBF CAN FIX the1MARKED SNIFF violations automaticallyremote:-------------------------------------------------------------------------Remote:remote:remote:FILE:/tmp/php_syntax_files. oxlrcu/Test40000.phpremote:-------------------------------------------------------------------------Remote:found1ERROR affecting1Lineremote:-------------------------------------------------------------------------Remote:6| ERROR | [x] A closing tag is not permitted at the end of a PHPfileRemote:-------------------------------------------------------------------------REMOTE:PHPCBF CAN FIX the1MARKED SNIFF violations automaticallyremote:-------------------------------------------------------------------------remote:remote:time:7ms; Memory:2mbremote:RM-rf/tmp/Php_syntax_files. OxLrCUremote:remote:remote:Server detected the code has a problem and check to submit the push again!Remote:remote:===============================================================================remote:remote:remote:transaction Abort!remote:rollback Completedremote:abort:pretxnchangegroup Hook exited with status1[Command return code 1 Wed Apr -  A: -: A  .]test%

This configuration is complete!

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 code detection hooks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.