Skip to content

Instantly share code, notes, and snippets.

@polunzh
Forked from arnobroekhof/pre-commit
Last active September 4, 2017 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save polunzh/77cbb66876c965bf3161 to your computer and use it in GitHub Desktop.
Save polunzh/77cbb66876c965bf3161 to your computer and use it in GitHub Desktop.
Maven pre commit hook
#!/bin/bash
# 放在 <git_directory>/.git/hooks/pre-commit
echo "执行 Maven clean test 检查单元测试是否通过..."
# retrieving current working directory
CWD=`pwd`
MAIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# 返回项目主目录
cd $MAIN_DIR/../../
# 执行 maven clean test
mvn clean test
if [ $? -ne 0 ]; then
echo "[Failed] 单元测试未通过!"
# 返回当前工作目录
cd $CWD
exit 1
fi
# 返回当前工作目录
cd $CWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment