![](/img/trans.png)
[英]Is there a configurable pre-commit hook solution available for android?
[英]Git pre-commit hook to run lint check?
如何编写一个git pre-commit hook
来运行lint检查更改/新添加的文件,
当前,我在提交之前运行“ ./gradlew lint”命令,如果有一种方法可以在提交到git之前仅对添加/更改文件运行lint,则会容易得多。
# Get custom info
dirToLint=$(git config hooks.lintTargetDirectory)
lintArgs=$(git config hooks.lintArgs)
# If user has not defined a preferred directory to lint against, make it .
if [ -z "$dirToLint"]
then
dirToLint="."
fi
# Perform lint check
echo "Performing pre-commit lint check of ""$dirToLint"
lint $lintArgs "--exitcode" $dirToLint
lintStatus=$?
if [ $lintStatus -ne 0 ]
then
echo "Lint failure."
exit 1
fi
exit $lintStatus
将其作为pre-commit.sh
放在您的.git / hooks /文件夹中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.