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

Stop prepending /usr/bin to hooks PATH, or document it very clearly

From
Ciro Santilli <ciro.santilli@gmail.com>
Date
Oct 17, 2014, 11:25 UTC
Message-ID
<CAFXrp_c+dxafLOO6T=LDd6OxhfpamkJsUc8iBwB-B41z8Htc4A@mail.gmail.com>
On hooks Git automatically prepends to the `PATH` via the `setup_path` function:
- `git --exec-path` (`/usr/lib/git-core`)
- the directory of `$0` (`/usr/bin`) if you call it with the full path

The problem is that the `/usr/bin` breaks "interpreter version manager systems" like RVM, rbenv, virtualenv, etc. since people will write hooks like:

    #!/usr/bin/env ruby

and the `/usr/bin` ruby will get run instead of the managed one (`~/.rvm/some/path/bin).

I recommend either:
- not adding the `$0` if possible (ideal but backwards incompatible
unless a new config is added)
- documenting this behavior *very* clearly on `man githooks`
- proposing some other mechanism that neatly solves the problem

I will try to submit a patch for the desired solution if within my technical capability.

Samples of problems this has caused people:
- https://github.com/gitlabhq/gitlabhq/issues/8045
- http://stackoverflow.com/questions/9037284/how-can-i-run-a-virtualenv-python-script-as-a-git-pre-commit-hook
- http://stackoverflow.com/questions/17515769/why-is-my-ruby-git-script-hook-run-with-the-wrong-path
- https://github.com/sstephenson/rbenv/issues/374
- https://github.com/magit/magit/issues/498
Next: Andreas Krey
Message 1 of 3 in “Stop prepending /usr/bin to hooks PATH, or document it very clearly”
  1. Ciro SantilliOct 17, 2014
  2. Andreas KreyOct 18, 2014
  3. Ciro SantilliOct 18, 2014

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.