Git pre-commit hook运行lint检查?

时间:2018-02-12 02:10:40

标签: android git shell

如何编写git pre-commit hook来运行lint检查更改/新添加的文件,

目前,我正在跑步" ./ gradlew lint"在提交之前执行命令,如果在提交git之前有一种方法只为添加/更改文件运行lint会更容易。

1 个答案:

答案 0 :(得分:0)

# 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 /文件夹中