jish/pre-commit

pre-commit doesn't appear to work

Closed this issue · 5 comments

Copy paste from email I got

I'm using Ruby 1.9.2-p290
rvm 1.16.11
simple Rails project, let's call it "RailsApp"

  1. installed pre-commit via gem install pre-commit
  2. in the folder RailsApp (root of git repo), ran pre-commit install
  3. for safe measure, ran git config "pre-commit.checks" "white_space, console_log, debugger"
  4. changed README to have "debugger" on the first line (tried many other files too)
  5. did git commit -am "test"

It does a slight pause as if it's running the Ruby script, but allows me to commit without any message.

Looking at .git/hooks/pre-commit I have:

!/usr/bin/env ruby

OPTIONS = "-r rubygems"

cmd = if system("which rvm > /dev/null")
"rvm default do ruby"
elsif system("which rbenv > /dev/null")
"rbenv exec ruby"
else
"ruby"
end

if !system(%Q{#{cmd} #{OPTIONS} -e "require 'pre-commit';" 2>&1})
$stderr.puts "pre-commit: WARNING: Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)"
exit(0)
end

And on .git/config I have:
... (other configs) ...
[pre-commit]
checks = white_space, console_log, debugger

Anything I'm missing? Did lots of searching, couldn't find a case where others were experiencing the same issue.

Thanks for the help!

debugger check only works on .rb files

@grosser I'm using Ruby 1.9.2-p290 and am having same issue as ^^ when it aborts with a warning "Skipping checks because the pre-commit gem is not installed. (Did you change your Ruby version?)". How did you fix it?

I think it has to be installed in your default ruby -> error message should be changed to "is not installed in ruby xxxx"
does installing in default ruby fix it ?

jish commented

@yadavsaroj yea, what @grosser said ;)

Depending on the Ruby version manager you're using you may or may not have a default Ruby. Also, are you in a folder with a .rvmrc or .ruby-version file that is switching your Ruby version unexpectedly?

closing as there was no feedback in over 2 months, please feel free to provide more details and we will reopen it