jish / pre-commit

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

Better RVM integration. #190

Closed Saicheg closed 9 years ago

Saicheg commented 9 years ago

Hey guys!

First thing i wanna say - this gem is FREAKING AWESOME, i really like it! Thank for all job you are doing here.

So i tried to install your gem this morning and have some thoughts about integrating with rvm.

Right now on your template you have next code:

md=`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

Which basically tries to use "rvm default do ruby" until variable in config exists.

These days a lot of project have .ruby-version and .ruby-gemset under their project root. How your feel about checking if they exists and using them?

This way we can go really smart and instead fallback to "rvm default do ruby" we can do something like "rvm RUBY_VERSION>@<RUBY_GEMSET do ruby".

mpapis commented 9 years ago

the thing is that you would have to install the same gem in every ruby/gemset you want to use it, this would be inefficient and more problematic to detect.

@jish maybe we could update installation instructions in README.md to look like:

gem install pre-commit
# or if in RVM:
rvm default do gem install pre-commit
Saicheg commented 9 years ago

I thought it could become a good practice. you can checkout this gem within Gemfile under development group to repository. And keep it together with config/pre_commit.yml.

This way all you need to setup your environment is to run bundle install as you always do and run pre-commit install.

mpapis commented 9 years ago

you could try:

git config pre-commit.ruby rvm-auto-ruby

if this works you could set it with --global and this would solve it for all your projects

jish commented 9 years ago

"First thing i wanna say - this gem is FREAKING AWESOME, i really like it! Thank for all job you are doing here."

Thanks! It's great to hear positive feedback like this. :)


One of the hardest parts is getting this gem to play nicely with everyone's specific Git, Ruby, and environment configuration. The default hook you are talking about solves the most problems for the largest number of people. Most people get the "it just works" out of the box treatment :)

You do raise valid points that .ruby-version is near ubiquitous now, but like @mpapis said, some people may not be able to control the Gemfile of every project they are working on. So they just install the pre-commit gem globally.

I tend to use the manual hook, installed via pre-commit instal --manual. That gives you a simple pre-commit hook that looks like:

require 'pre-commit'
PreCommit.run

We could look into creating another template that uses the .ruby-version, or you could set the pre-commit.ruby setting like @mpapis said above.

Saicheg commented 9 years ago

@mpapis @jish yeah, all you proposals sound really good. Thank you guys for your help of understanding how i can run it easily on my project.

mpapis commented 9 years ago

@Saicheg let us know which way worked for you, if there is a new template we could add maybe we should add it.