美文网首页
TortoiseGit hook scripts 本地项目配置

TortoiseGit hook scripts 本地项目配置

作者: 爱吃秋葵的莫冲 | 来源:发表于2018-07-27 12:07 被阅读49次

    环境要求

    • Tortoise git: 2.5 以上版本
    • git:1.9 以上版本

    系统变量

    C:\Users\your computer user name\AppData\Roaming\Composer\vendor\bin 添加到系统变量,在cmd中执行php-cs-fixer可见到输出PHP CS Fixer 2.7.1 Sandy Pool by Fabien Potencier and Dariusz Ruminski

    Tortoise git 可视化提交方式的代码格式化配置

    • 安装php-cs-fixer

    composer global require friendsofphp/php-cs-fixer

    • 在项目根目录下,右键打开Tortoise git->Hook scripts,点击add,打开配置面板
    • 勾选左上角的Enable(默认)
    • 右上角下拉框选择Start Commit hook
    • Run when working tree path is under中输入项目根目录地址,例如
      C:\wamp64\www\laravel5-common\picks
    • Commond line to execute的输入框中输入执行命令,例如:
      sh C:\wamp64\www\laravel5-common\picks\format.sh
    • 选中Wait for the script to finish
    • 选中Hide the script while running
    • 在项目根目录创建 format.sh,内容为
    php-cs-fixer fix --config=format.php_cs.dist --allow-risky yes
    
    • format.php_cs.dist 文件从git中pull,确保该配置文件内容一致
    • 右键提交代码,可见到代码已被格式化
    • 如果commit时提示系统找不到指定的文件,请将C:\Program Files (x86)\Git\bin;加入 系统环境变量PATH

    命令行提交方式的代码格式化配置

    • 在项目根目录下,进入./.git/hooks,复制pre-commit.sample,重命名为pre-commit
    • 在第一行输入php-cs-fixer fix --config=C:/wamp64/www/laravel5-common/picks/format.php_cs.dist --allow-risky yes 保存
    • command 进入项目根目录执行
    git add .
    git commit -m 'your comment'
    

    可见到代码已经被格式化

    相关文章

      网友评论

          本文标题:TortoiseGit hook scripts 本地项目配置

          本文链接:https://www.haomeiwen.com/subject/zygivxtx.html