我正在使用RVM。我寫了一個Git pre-commit
掛鉤項目:
#!/usr/bin/env ruby
puts RUBY_VERSION
puts `echo $PATH`
exit(1)
當Git的運行,其輸出這樣的:
$ git ci -m 'foo'
1.8.7
/usr/libexec/git-core:/usr/bin:/usr/local/heroku/bin:/Users/mgoerlich/.rvm/gems/[email protected]/bin:/Users/mgoerlich/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/mgoerlich/.rvm/bin:/Users/mgoerlich/adt-bundle-mac-x86_64-20130219/sdk/platform-tools:/Users/mgoerlich/adt-bundle-mac-x86_64-20130219/sdk/tools:/usr/local/bin:/usr/local/sbin:/Users/mgoerlich/.dotfiles/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/core_perl:/Users/mgoerlich/bin:/usr/local/share/npm/bin:/usr/local/share/npm/bin
這似乎與錯版的Ruby運行,因爲$PATH
是不一樣的bash或zsh或sh。這似乎是git操縱$PATH
。當手動運行,我得到這個:
$ .git/hooks/pre-commit
2.0.0
/usr/local/heroku/bin:/Users/mgoerlich/.rvm/gems/[email protected]/bin:/Users/mgoerlich/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/mgoerlich/.rvm/bin:/Users/mgoerlich/adt-bundle-mac-x86_64-20130219/sdk/platform-tools:/Users/mgoerlich/adt-bundle-mac-x86_64-20130219/sdk/tools:/usr/local/bin:/usr/local/sbin:/Users/mgoerlich/.dotfiles/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin/core_perl:/Users/mgoerlich/bin:/usr/local/share/npm/bin:/usr/local/share/npm/bin
在提交鉤子的輸出,有兩條路前置,在系統Ruby的可執行文件放在他們/usr/bin
之一。
這是一個已知的行爲?我能操縱那個嗎?我知道我可以在shebang中指定正確的Ruby版本的完整路徑,但這不是我想要的。
[$ PATH擴展名爲.bashrc在git鉤子腳本中不可用]的可能重複(http://stackoverflow.com/questions/9405693/path-extended-at-bashrc-not-available-within-git-hook -script) –
相同的Python的virtualenv:http://stackoverflow.com/questions/9037284/how-can-i-run-a-virtualenv-python-script-as-a-git-pre-commit-hook –
相同對於rbenv:https://github.com/sstephenson/rbenv/issues/374 –