jish / pre-commit

A slightly improved pre-commit hook for git
https://jish.github.io/pre-commit/
Other
796 stars 96 forks source link

Cannot get pre-commit hook to prevent commit creation #235

Open trystant opened 8 years ago

trystant commented 8 years ago

Hi,

I just found this gem, installed it in my repo, but with the following settings in place (taken from the home page), the pre-commit hook will not prevent bad ruby code from being run.

My only aim is to have the test suite run in order to guarantee that all tests pass before committing to the repo.

Here is the output of my pre-commit list

Available providers: default(0) git(10) git_old(11) yaml(20) env(30)
Available checks   : before_all ci closure coffeelint common console_log csslint debugger gemfile_path go jshint jslint json local merge_conflict migration nb_space pry rails rspec_focus rubocop ruby ruby_symbol_hashrockets scss_lint tabs whitespace yaml
Default   checks   : common rails
Enabled   checks   : common rails
Evaluated checks   : tabs nb_space whitespace merge_conflict debugger pry local jshint console_log migration
Default   warnings :
Enabled   warnings :
Evaluated warnings :

and the .git/hooks/pre-commit file:

#!/usr/bin/env sh

# This hook has a focus on portability.
# This hook will attempt to setup your environment before running checks.
#
# If you would like `pre-commit` to get out of your way and you are comfortable
# setting up your own environment, you can install the manual hook using:
#
#     pre-commit install --manual
#

# This is a work-around to get GitHub for Mac to be able to run `node` commands
# https://stackoverflow.com/questions/12881975/git-pre-commit-hook-failing-in-github-for-mac-works-on-command-line
PATH=$PATH:/usr/local/bin:/usr/local/sbin

cmd=`git config pre-commit.ruby 2>/dev/null`
if   test -n "${cmd}"
then true
elif which rvm   >/dev/null 2>/dev/null
then cmd="rvm default do ruby"
elif which rbenv >/dev/null 2>/dev/null
then cmd="rbenv exec ruby"
else cmd="ruby"
fi

export rvm_silence_path_mismatch_check_flag=1

${cmd} -rrubygems -e '
  begin
    require "pre-commit"
    true
  rescue LoadError => e
    $stderr.puts <<-MESSAGE
pre-commit: WARNING: Skipping checks because: #{e}
pre-commit: Did you set your Ruby version?
MESSAGE
    false
  end and PreCommit.run
'

If there's more info I need to add, please let me know. Also, any assistance would be appreciated. Thanks much

jish commented 8 years ago

Hello,

You should be able to run this command to disable the common checks and the rails checks:

$ pre-commit disable git checks common rails

Then you can enable the ci check using:

$ pre-commit enable git checks ci

FYI The ci check will not do anything unless you have a Rake task defined called pre_commit:ci. You can point the pre_commit:ci task at whatever Rake task you want like this:

https://jish.github.io/pre-commit/checks/ci/

namespace :pre_commit do
  task :ci => [:test]
end