I\'m using RVM. I wrote a Git pre-commit hook for a project:
#!/usr/bin/env ruby
puts RUBY_VERSION
puts `echo $PATH`
exit(1)
What I ended up doing is: the .git file structure:
.git/hooks/pre-commit.git/hooks/pre-commit-main.rb.git/hooks/pre-commit:
#!/usr/bin/env bash
export PATH="$THE_GOOD_PATH"
ruby "$GIT_DIR/hooks/pre-commit-main.rb"
.git/hooks/pre-commit-main.rb:
#!/usr/bin/env ruby
puts RUBY_VERSION
Then, when you call git commit, make sure that THE_GOOD_PATH, is defined:
export THE_GOOD_PATH="$PATH"
git commit
You could also export THE_GOOD_PATH="$PATH" from your .profile or the toplevel of your application and symlink all hooks to a single file.
This method has the advantage of being rbenv agnostic: it also works with RVM or Python virtualenv.
I wrote to the Git developers at: http://permalink.gmane.org/gmane.comp.version-control.git/258454 asking them to leave our PATH alone, but the initial reply was WONTFIX.