加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pre-commit 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
青立木木 提交于 2021-07-03 06:17 . update pre-commit.
#!/bin/sh
#
# Check for ruby style errors
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
# Change it to match your initial commit sha
against=123acdac4c698f24f2352cf34c3b12e246b48af1
fi
# Check if rubocop is installed for the current project
bin/bundle exec rubocop -v >/dev/null 2>&1 || { echo >&2 "[Ruby Style][Fatal]: Add rubocop to your Gemfile"; exit 1; }
# Get only the staged files
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')"
echo "[Ruby Style][Info]: Checking Ruby Style"
if [ -n "$FILES" ]
then
echo "[Ruby Style][Info]: ${FILES}"
if [ ! -f '.rubocop.yml' ]; then
echo "[Ruby Style][Warning]: No .rubocop.yml config file."
fi
# Run rubocop on the staged files
bin/bundle exec rubocop ${FILES}
if [ $? -ne 0 ]; then
echo "[Ruby Style][Error]: Fix the issues and commit again"
echo "[Ruby Style][Error]: 修复这些缺陷之后再尝试提交"
exit 1
fi
else
echo "[Ruby Style][Info]: No files to check"
fi
exit 0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化