最近代碼提交的時(shí)候儡陨,總會(huì)遇到一些拷貝的代碼中包含tab的情況迷扇,因此需要在提交代碼前進(jìn)行格式檢查鸥昏,發(fā)現(xiàn)了這個(gè)hooks挺好用的瑟蜈,可以在commit之前檢查新增代碼中是否包含tab烟逊,如果包含,則不予提交:
https://github.com/martinjoiner/portable-code-pre-commit-hook
但問(wèn)題是铺根,怎么樣將這項(xiàng)工作同步到項(xiàng)目中宪躯,則參考如下文檔:
https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/
以AOSP為例,最終的實(shí)現(xiàn)步驟為:
- 創(chuàng)建自定義hooks目錄:
mkdir .githooks
- 下載hooks:
cd .githooks wget https://raw.githubusercontent.com/martinjoiner/portable-code-pre-commit-hook/master/pre-commit . chmod +x pre-commit
- 考慮到AOSP的編譯需要執(zhí)行
source build/envsetup.sh
位迂,也因此添加如下行到該文件末尾:find .git/hooks -type l -exec rm {} \; && find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
最終項(xiàng)目組的小伙伴們都能用到該功能了访雪。