简体   繁体   English

git pre-commit钩子可以运行lint检查?

[英]Git pre-commit hook to run lint check?

how to Write a git pre-commit hook to run lint check for change/newly added file, 如何编写一个git pre-commit hook来运行lint检查更改/新添加的文件,

currently, I'm running "./gradlew lint" command before commit, It would be much easier if there is a way to run the lint only for add/change files before committing to git. 当前,我在提交之前运行“ ./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

put this in your .git/hooks/ folder as pre-commit.sh 将其作为pre-commit.sh放在您的.git / hooks /文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM