【问题标题】:Git pre-commit hook to run lint check?Git 预提交钩子运行 lint 检查?
【发布时间】:2018-07-22 03:52:49
【问题描述】:

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

目前,我在提交之前运行“./gradlew lint”命令,如果有一种方法可以在提交到 git 之前只为添加/更改文件运行 lint。

【问题讨论】:

  • 嘿,你知道了吗?

标签: android git shell


【解决方案1】:
# 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

【讨论】:

    猜你喜欢
    • 2013-12-15
    • 2019-07-12
    • 2015-01-13
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    相关资源
    最近更新 更多