githooks

作者: 发条蛙 | 来源:发表于2018-02-26 11:12 被阅读0次

    最近代码提交的时候,总会遇到一些拷贝的代码中包含tab的情况,因此需要在提交代码前进行格式检查,发现了这个hooks挺好用的,可以在commit之前检查新增代码中是否包含tab,如果包含,则不予提交:

    https://github.com/martinjoiner/portable-code-pre-commit-hook

    但问题是,怎么样将这项工作同步到项目中,则参考如下文档:

    https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/

    以AOSP为例,最终的实现步骤为:

    1. 创建自定义hooks目录:
      mkdir .githooks
      
    2. 下载hooks:
      cd .githooks
      wget https://raw.githubusercontent.com/martinjoiner/portable-code-pre-commit-hook/master/pre-commit .
      chmod +x pre-commit
      
    3. 考虑到AOSP的编译需要执行source build/envsetup.sh,也因此添加如下行到该文件末尾:
      find .git/hooks -type l -exec rm {} \; && find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
      

    最终项目组的小伙伴们都能用到该功能了。

    相关文章

      网友评论

          本文标题:githooks

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