简体   繁体   中英

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,

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.

# 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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