Skip to content

Instantly share code, notes, and snippets.

@hiroki-uchida
Last active July 27, 2017 04:09
Show Gist options
  • Save hiroki-uchida/f8a4663ca049ae96fc1aef710bd0936e to your computer and use it in GitHub Desktop.
Save hiroki-uchida/f8a4663ca049ae96fc1aef710bd0936e to your computer and use it in GitHub Desktop.
RuboCop違反のファイルのコミットを阻止する
#!/bin/sh
# 参考記事
# Gitフックを使っておかしいRubyコードをコミットできないようにする - Qiita
# http://qiita.com/yuku_t/items/ad072418290a2b01a35a
# 使い方
# このコードを `~/.git_template/hooks/pre-commit` に保存して以下のコマンドを実行します。
# `$ git config --global init.templatedir '~/.git_template'`
# 新しく作られたリポジトリやcloneしたリポジトリに反映されます。
# 既存のリポジトリには反映されないので、 `$ git init` を実行する必要があります。
which bundle exec rubocop && git diff --cached --name-only --diff-filter=AM | grep '\.rb$' | xargs bundle exec rubocop --parallel
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment