* git's directory is _prepended_ to PATH when called with an absolute path @ 2015-04-21 21:37 David Rodríguez 2015-04-21 21:48 ` Junio C Hamano 2015-04-22 5:47 ` Andreas Krey 0 siblings, 2 replies; 9+ messages in thread From: David Rodríguez @ 2015-04-21 21:37 UTC (permalink / raw) To: git For example, if I run git using: $ /usr/bin/git then /usr/bin is prepended to the path. Is this intentional? If it is, why? This causes issues with Ruby git hooks, because Ruby version managers rely on custom settings in PATH to select the Ruby executable, and there's usually a system Ruby living in /usr/bin. See https://github.com/github/hub/issues/855 for an example. Thanks a lot, David Rodríguez. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-21 21:37 git's directory is _prepended_ to PATH when called with an absolute path David Rodríguez @ 2015-04-21 21:48 ` Junio C Hamano 2015-04-21 21:59 ` David Rodríguez 2015-04-22 5:47 ` Andreas Krey 1 sibling, 1 reply; 9+ messages in thread From: Junio C Hamano @ 2015-04-21 21:48 UTC (permalink / raw) To: David Rodríguez; +Cc: git http://thread.gmane.org/gmane.comp.version-control.git/267143/focus=267251 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-21 21:48 ` Junio C Hamano @ 2015-04-21 21:59 ` David Rodríguez 2015-04-21 23:17 ` David Rodríguez 0 siblings, 1 reply; 9+ messages in thread From: David Rodríguez @ 2015-04-21 21:59 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Thanks Junio for the useful link, I'll comment there. On 21/04/15 18:48, Junio C Hamano wrote: > http://thread.gmane.org/gmane.comp.version-control.git/267143/focus=267251 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-21 21:59 ` David Rodríguez @ 2015-04-21 23:17 ` David Rodríguez 0 siblings, 0 replies; 9+ messages in thread From: David Rodríguez @ 2015-04-21 23:17 UTC (permalink / raw) To: Junio C Hamano; +Cc: git I'm actually not sure how to reply to an old thread... From the thread I gather that the intention is to prevent this behavior and stop prepending git's directory to the path. Is that right? On 21/04/15 18:59, David Rodríguez wrote: > Thanks Junio for the useful link, I'll comment there. > > On 21/04/15 18:48, Junio C Hamano wrote: >> http://thread.gmane.org/gmane.comp.versionlist-control.git/267143/focus=267251 >> > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-21 21:37 git's directory is _prepended_ to PATH when called with an absolute path David Rodríguez 2015-04-21 21:48 ` Junio C Hamano @ 2015-04-22 5:47 ` Andreas Krey 2015-04-22 11:36 ` David Rodríguez 1 sibling, 1 reply; 9+ messages in thread From: Andreas Krey @ 2015-04-22 5:47 UTC (permalink / raw) To: David Rodríguez; +Cc: git On Tue, 21 Apr 2015 18:37:29 +0000, David Rodríguez wrote: ... > This causes issues with Ruby git hooks, because Ruby version managers > rely on custom settings in PATH to select the Ruby executable, Even if git wouldn't modify PATH this is still a broken way to do that. What ruby to execute a hook with is a property of the hook, not of the user context invoking it. 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] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-22 5:47 ` Andreas Krey @ 2015-04-22 11:36 ` David Rodríguez 2015-04-22 15:31 ` Andreas Krey 0 siblings, 1 reply; 9+ messages in thread From: David Rodríguez @ 2015-04-22 11:36 UTC (permalink / raw) To: Andreas Krey; +Cc: git On 22/04/15 02:47, Andreas Krey wrote: > On Tue, 21 Apr 2015 18:37:29 +0000, David Rodríguez wrote: > ... >> This causes issues with Ruby git hooks, because Ruby version managers >> rely on custom settings in PATH to select the Ruby executable, > Even if git wouldn't modify PATH this is still a broken way to do that. > What ruby to execute a hook with is a property of the hook, not of the > user context invoking it. > > Andreas > I probably shouldn't have mentioned Ruby version managers since they are not directly related to this issue. I'll try to elaborate on the issue: * 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, but since the path has been changed by "/usr/bin/git", the selected ruby will be "/usr/bin/ruby" and not "~/.rubies/2.2.2/bin/ruby" as the user would expect. What's the proper way to do whatever you're saying is done in "a broken way"? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-22 11:36 ` David Rodríguez @ 2015-04-22 15:31 ` Andreas Krey 2015-04-22 17:02 ` brian m. carlson 0 siblings, 1 reply; 9+ messages in thread From: Andreas Krey @ 2015-04-22 15:31 UTC (permalink / raw) To: David Rodríguez; +Cc: git 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. 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] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-22 15:31 ` Andreas Krey @ 2015-04-22 17:02 ` brian m. carlson 2015-04-22 17:47 ` David Rodríguez 0 siblings, 1 reply; 9+ messages in thread From: brian m. carlson @ 2015-04-22 17:02 UTC (permalink / raw) To: Andreas Krey; +Cc: David Rodríguez, git [-- Attachment #1: Type: text/plain, Size: 1552 bytes --] On Wed, Apr 22, 2015 at 05:31:09PM +0200, Andreas Krey wrote: > 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 [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: git's directory is _prepended_ to PATH when called with an absolute path 2015-04-22 17:02 ` brian m. carlson @ 2015-04-22 17:47 ` David Rodríguez 0 siblings, 0 replies; 9+ messages in thread From: David Rodríguez @ 2015-04-22 17:47 UTC (permalink / raw) To: git On 22/04/15 14:02, brian m. carlson wrote: > "I want whatever ruby the > user chooses." This is exactly what I want. The problem is that git overrides the user's choice by prepending /usr/bin to the path and thus making /usr/bin/env choose system's ruby version. Which is almost always not the Ruby the user chose. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-04-22 17:48 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-04-21 21:37 git's directory is _prepended_ to PATH when called with an absolute path David Rodríguez 2015-04-21 21:48 ` Junio C Hamano 2015-04-21 21:59 ` David Rodríguez 2015-04-21 23:17 ` David Rodríguez 2015-04-22 5:47 ` Andreas Krey 2015-04-22 11:36 ` David Rodríguez 2015-04-22 15:31 ` Andreas Krey 2015-04-22 17:02 ` brian m. carlson 2015-04-22 17:47 ` David Rodríguez
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).