git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ciro Santilli <ciro.santilli@gmail.com>
To: git@vger.kernel.org
Subject: Stop prepending /usr/bin to hooks PATH, or document it very clearly
Date: Fri, 17 Oct 2014 13:25:42 +0200	[thread overview]
Message-ID: <CAFXrp_c+dxafLOO6T=LDd6OxhfpamkJsUc8iBwB-B41z8Htc4A@mail.gmail.com> (raw)

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

             reply	other threads:[~2014-10-17 11:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-17 11:25 Ciro Santilli [this message]
2014-10-18 14:49 ` Stop prepending /usr/bin to hooks PATH, or document it very clearly Andreas Krey
2014-10-18 16:45   ` Ciro Santilli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFXrp_c+dxafLOO6T=LDd6OxhfpamkJsUc8iBwB-B41z8Htc4A@mail.gmail.com' \
    --to=ciro.santilli@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).