All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* Stop prepending /usr/bin to hooks PATH, or document it very clearly
@ 2014-10-17 11:25 Ciro Santilli
  2014-10-18 14:49 ` Andreas Krey
  0 siblings, 1 reply; 3+ messages in thread
From: Ciro Santilli @ 2014-10-17 11:25 UTC (permalink / raw
  To: git

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stop prepending /usr/bin to hooks PATH, or document it very clearly
  2014-10-17 11:25 Stop prepending /usr/bin to hooks PATH, or document it very clearly Ciro Santilli
@ 2014-10-18 14:49 ` Andreas Krey
  2014-10-18 16:45   ` Ciro Santilli
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Krey @ 2014-10-18 14:49 UTC (permalink / raw
  To: Ciro Santilli; +Cc: git

On Fri, 17 Oct 2014 13:25:42 +0000, Ciro Santilli wrote:
...
> 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

And that is the right thing to do. What ruby to execute with is
a property of the hook script, not of the virtualenv a user happens
to be in. If you want virtualenvs, you should set up the right one
within the hook script.

...
> - documenting this behavior *very* clearly on `man githooks`

That would still be a good thing to do.

Andreas

-- 
"Totally trivial. Famous last words."
From: Linus Torvalds <torvalds@*.org>
Date: Fri, 22 Jan 2010 07:29:21 -0800

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stop prepending /usr/bin to hooks PATH, or document it very clearly
  2014-10-18 14:49 ` Andreas Krey
@ 2014-10-18 16:45   ` Ciro Santilli
  0 siblings, 0 replies; 3+ messages in thread
From: Ciro Santilli @ 2014-10-18 16:45 UTC (permalink / raw
  To: git

On Sat, Oct 18, 2014 at 4:49 PM, Andreas Krey <a.krey@gmx.de> wrote:
> On Fri, 17 Oct 2014 13:25:42 +0000, Ciro Santilli wrote:
> ...
>> 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
>
> And that is the right thing to do. What ruby to execute with is
> a property of the hook script, not of the virtualenv a user happens
> to be in. If you want virtualenvs, you should set up the right one
> within the hook script.
>

I'm sure what you say has a good rationale, but can you give a more
concrete example where PATH prepending is desirable?

Use cases that I have seen where it is surprising and undesirable:

- I want binaries I manually installed under `/usr/local/bin` to have
precedence over the system defaults under `/usr/bin`, so I modify the
PATH on my `.profile`. But then I run a hook and things fail: so in
each hook I have to do export PATH="$THE_GOOD_PATH", which makes me
repeat the same thing many times.

- Locally I use RVM. But the CI uses rbenv. Next year, there will be
another version manager. If we follow the rule that when I invoke
`system('git something')` it runs in the same environment as current,
I don't need to do anything. But if environments change, I'd have to
either write extra code for each manager, or install dependencies on
multiple versions of the interpreter.

For now I'm going to go with `export PATH="$THE_GOOD_PATH && ruby
real_script.rb"`.

> ...
>> - documenting this behavior *very* clearly on `man githooks`
>
> That would still be a good thing to do.
>
> Andreas
>
> --
> "Totally trivial. Famous last words."
> From: Linus Torvalds <torvalds@*.org>
> Date: Fri, 22 Jan 2010 07:29:21 -0800

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-18 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-17 11:25 Stop prepending /usr/bin to hooks PATH, or document it very clearly Ciro Santilli
2014-10-18 14:49 ` Andreas Krey
2014-10-18 16:45   ` Ciro Santilli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.