Why is my Ruby Git script hook run with the wrong $PATH?

前端 未结 3 1246
旧时难觅i
旧时难觅i 2021-01-06 07:00

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)

3条回答
  •  情歌与酒
    2021-01-06 07:26

    you need to set ruby to a wrapper:

    #!$rvm_path/wrappers/ruby-2.0.0-p195/ruby
    

    You can simplify it with an alias:

    rvm alias create git_hooks 2.0.0-p195
    

    And then the ne shebang will look like this:

    #!$rvm_path/wrappers/git_hooks/ruby
    

    In the file just make sure to replace $rvm_path with /Users/mgoerlich/.rvm so finally it looks like:

    #!/Users/mgoerlich/.rvm/wrappers/git_hooks/ruby
    

提交回复
热议问题