【发布时间】:2018-07-22 03:52:49
【问题描述】:
如何编写一个 git pre-commit hook 来运行 lint 检查更改/新添加的文件,
目前,我在提交之前运行“./gradlew lint”命令,如果有一种方法可以在提交到 git 之前只为添加/更改文件运行 lint。
【问题讨论】:
-
嘿,你知道了吗?
如何编写一个 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
把它放在你的 .git/hooks/ 文件夹中作为pre-commit.sh
【讨论】: