git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git's directory is _prepended_ to PATH when called with an absolute path

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 22, 2015, 17:02 UTC
Message-ID
<20150422170205.GA827497@vauxhall.crustytoothpaste.net>
In-Reply-To
<20150422153109.GO23476@inner.h.apk.li>
On Wed, Apr 22, 2015 at 05:31:09PM +0200, Andreas Krey wrote:
Show 13 quoted lines
> On Wed, 22 Apr 2015 08:36:00 +0000, David Rodríguez wrote:
> ...
> > * User is relying on a custom path to select their Ruby version. For
> > example, let's say the first folder in path is "~/.rubies/2.2.2/bin".
> > * User runs "/usr/bin/git commit" and a pre-commit hook is triggered.
> > * The pre-commit hook starts with "#!/us/bin/env ruby" to select the
> > Ruby to be used in the hook,
> 
> Yes...but shouldn't the hook itself know which ruby version it needs?
> 
> After all, if I go into that directory with another ruby setup in my
> PATH, the hook should still work, and presumably that requires that
> the hook itself selects its version, and not the user's context.

More generally, #!/usr/bin/env ruby is saying, "I want whatever ruby the user chooses." If you want a ruby that has certain gems, or certain features (e.g. Array#to_h), then that's not what you want. #!/usr/bin/env ruby is basically only safe if you're willing to accept any potential version that might show up.

You can use a multiline shebang[0] if you need to execute shell code to make the decision at runtime, such as if you need to use $HOME in the path to your ruby, or select from multiple different options.

[0] http://rosettacode.org/wiki/Multiline_shebang
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Previous: Andreas KreyNext: David Rodríguez
Message 8 of 9 in “git's directory is _prepended_ to PATH when called with an absolute path”
  1. David RodríguezApr 21, 2015
  2. Junio C HamanoApr 21, 2015
  3. David RodríguezApr 21, 2015
  4. David RodríguezApr 21, 2015
  5. Andreas KreyApr 22, 2015
  6. David RodríguezApr 22, 2015
  7. Andreas KreyApr 22, 2015
  8. brian m. carlsonApr 22, 2015
  9. David RodríguezApr 22, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.