Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my Ruby Git script hook run with the wrong $PATH?
    primarykey
    data
    text
    <p>I'm using RVM. I wrote a Git <code>pre-commit</code> hook for a project:</p> <pre><code>#!/usr/bin/env ruby puts RUBY_VERSION puts `echo $PATH` exit(1) </code></pre> <p>which outputs this when run by Git:</p> <pre><code>$ git ci -m 'foo' 1.8.7 /usr/libexec/git-core:/usr/bin:/usr/local/heroku/bin:/Users/mgoerlich/.rvm/gems/ruby-2.0.0-p195@global/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 </code></pre> <p>It seems to run with the wrong version of Ruby because <code>$PATH</code> is not the same as in bash or zsh or sh. It seems like git is manipulating <code>$PATH</code>. When run manually, I get this:</p> <pre><code>$ .git/hooks/pre-commit 2.0.0 /usr/local/heroku/bin:/Users/mgoerlich/.rvm/gems/ruby-2.0.0-p195@global/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 </code></pre> <p>In the output of the commit hook, there are two paths prepended, one of them <code>/usr/bin</code> where the system Ruby's executable is placed.</p> <p>Is this a known behavior? Can I manipulate that somehow? I know I could specify the full path to the correct Ruby version in the shebang, but this is not what I want.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload