{"thread":{"id":"39126","subject":"git's directory is _prepended_ to PATH when called with an absolute path","startedAt":"2015-04-21T21:37:29Z","lastAt":"2015-04-22T17:47:51Z","messageCount":9,"participants":["David Rodríguez","Junio C Hamano","Andreas Krey","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"259764","messageId":"5536C319.4000402@gmail.com","threadId":"39126","inReplyTo":null,"subject":"git's directory is _prepended_ to PATH when called with an absolute path","fromName":"David Rodríguez","fromEmail":"deivid.rodriguez@gmail.com","sentAt":"2015-04-21T21:37:29Z","receivedAt":"2015-04-21T21:37:29Z","isPatch":false,"sender":{"key":"deivid.rodriguez@gmail.com","avatar":"https://gravatar.com/avatar/a1cc6e0d09fa7ad750142933abbcc225b647baa36e04fedda00fad1eb2e7a0e1?d=mp&s=160"},"body":"For example, if I run git using:\n\n$ /usr/bin/git\n\nthen /usr/bin is prepended to the path. Is this intentional? If it is, why?\n\nThis causes issues with Ruby git hooks, because Ruby version managers \nrely on custom settings in PATH to select the Ruby executable, and \nthere's usually a system Ruby living in /usr/bin. See \nhttps://github.com/github/hub/issues/855 for an example.\n\nThanks a lot,\n\nDavid Rodríguez.\n"},{"id":"259766","messageId":"xmqqzj61f90k.fsf@gitster.dls.corp.google.com","threadId":"39126","inReplyTo":"5536C319.4000402@gmail.com","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-04-21T21:48:11Z","receivedAt":"2015-04-21T21:48:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"http://thread.gmane.org/gmane.comp.version-control.git/267143/focus=267251\n"},{"id":"259768","messageId":"5536C84E.8060702@gmail.com","threadId":"39126","inReplyTo":"xmqqzj61f90k.fsf@gitster.dls.corp.google.com","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"David Rodríguez","fromEmail":"deivid.rodriguez@gmail.com","sentAt":"2015-04-21T21:59:42Z","receivedAt":"2015-04-21T21:59:42Z","isPatch":false,"sender":{"key":"deivid.rodriguez@gmail.com","avatar":"https://gravatar.com/avatar/a1cc6e0d09fa7ad750142933abbcc225b647baa36e04fedda00fad1eb2e7a0e1?d=mp&s=160"},"body":"Thanks Junio for the useful link, I'll comment there.\n\nOn 21/04/15 18:48, Junio C Hamano wrote:\n> http://thread.gmane.org/gmane.comp.version-control.git/267143/focus=267251\n"},{"id":"259778","messageId":"5536DA9B.1010801@gmail.com","threadId":"39126","inReplyTo":"5536C84E.8060702@gmail.com","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"David Rodríguez","fromEmail":"deivid.rodriguez@gmail.com","sentAt":"2015-04-21T23:17:47Z","receivedAt":"2015-04-21T23:17:47Z","isPatch":false,"sender":{"key":"deivid.rodriguez@gmail.com","avatar":"https://gravatar.com/avatar/a1cc6e0d09fa7ad750142933abbcc225b647baa36e04fedda00fad1eb2e7a0e1?d=mp&s=160"},"body":"I'm actually not sure how to reply to an old thread...\n\n From the thread I gather that the intention is to prevent this behavior \nand stop prepending git's directory to the path. Is that right?\n\nOn 21/04/15 18:59, David Rodríguez wrote:\n> Thanks Junio for the useful link, I'll comment there.\n>\n> On 21/04/15 18:48, Junio C Hamano wrote:\n>> http://thread.gmane.org/gmane.comp.versionlist-control.git/267143/focus=267251 \n>>\n>\n"},{"id":"259786","messageId":"20150422054737.GA11889@inner.h.apk.li","threadId":"39126","inReplyTo":"5536C319.4000402@gmail.com","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"Andreas Krey","fromEmail":"a.krey@gmx.de","sentAt":"2015-04-22T05:47:37Z","receivedAt":"2015-04-22T05:47:37Z","isPatch":false,"sender":{"key":"a.krey@gmx.de","avatar":"https://avatars.githubusercontent.com/u/37810?v=4"},"body":"On Tue, 21 Apr 2015 18:37:29 +0000, David Rodríguez wrote:\n...\n> This causes issues with Ruby git hooks, because Ruby version managers \n> rely on custom settings in PATH to select the Ruby executable,\n\nEven if git wouldn't modify PATH this is still a broken way to do that.\nWhat ruby to execute a hook with is a property of the hook, not of the\nuser context invoking it.\n\nAndreas\n\n-- \n\"Totally trivial. Famous last words.\"\nFrom: Linus Torvalds <torvalds@*.org>\nDate: Fri, 22 Jan 2010 07:29:21 -0800\n"},{"id":"259794","messageId":"553787A0.40707@gmail.com","threadId":"39126","inReplyTo":"20150422054737.GA11889@inner.h.apk.li","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"David Rodríguez","fromEmail":"deivid.rodriguez@gmail.com","sentAt":"2015-04-22T11:36:00Z","receivedAt":"2015-04-22T11:36:00Z","isPatch":false,"sender":{"key":"deivid.rodriguez@gmail.com","avatar":"https://gravatar.com/avatar/a1cc6e0d09fa7ad750142933abbcc225b647baa36e04fedda00fad1eb2e7a0e1?d=mp&s=160"},"body":"On 22/04/15 02:47, Andreas Krey wrote:\n> On Tue, 21 Apr 2015 18:37:29 +0000, David Rodríguez wrote:\n> ...\n>> This causes issues with Ruby git hooks, because Ruby version managers\n>> rely on custom settings in PATH to select the Ruby executable,\n> Even if git wouldn't modify PATH this is still a broken way to do that.\n> What ruby to execute a hook with is a property of the hook, not of the\n> user context invoking it.\n>\n> Andreas\n>\nI probably shouldn't have mentioned Ruby version managers since they are \nnot directly related to this issue. I'll try to elaborate on the issue:\n\n* User is relying on a custom path to select their Ruby version. For \nexample, let's say the first folder in path is \"~/.rubies/2.2.2/bin\".\n* User runs \"/usr/bin/git commit\" and a pre-commit hook is triggered.\n* The pre-commit hook starts with \"#!/us/bin/env ruby\" to select the \nRuby to be used in the hook, but since the path has been changed by \n\"/usr/bin/git\", the selected ruby will be \"/usr/bin/ruby\" and not \n\"~/.rubies/2.2.2/bin/ruby\" as the user would expect.\n\nWhat's the proper way to do whatever you're saying is done in \"a broken \nway\"?\n"},{"id":"259802","messageId":"20150422153109.GO23476@inner.h.apk.li","threadId":"39126","inReplyTo":"553787A0.40707@gmail.com","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"Andreas Krey","fromEmail":"a.krey@gmx.de","sentAt":"2015-04-22T15:31:09Z","receivedAt":"2015-04-22T15:31:09Z","isPatch":false,"sender":{"key":"a.krey@gmx.de","avatar":"https://avatars.githubusercontent.com/u/37810?v=4"},"body":"On Wed, 22 Apr 2015 08:36:00 +0000, David Rodríguez wrote:\n...\n> * User is relying on a custom path to select their Ruby version. For \n> example, let's say the first folder in path is \"~/.rubies/2.2.2/bin\".\n> * User runs \"/usr/bin/git commit\" and a pre-commit hook is triggered.\n> * The pre-commit hook starts with \"#!/us/bin/env ruby\" to select the \n> Ruby to be used in the hook,\n\nYes...but shouldn't the hook itself know which ruby version it needs?\n\nAfter all, if I go into that directory with another ruby setup in my\nPATH, the hook should still work, and presumably that requires that\nthe hook itself selects its version, and not the user's context.\n\nAndreas\n\n-- \n\"Totally trivial. Famous last words.\"\nFrom: Linus Torvalds <torvalds@*.org>\nDate: Fri, 22 Jan 2010 07:29:21 -0800\n"},{"id":"259803","messageId":"20150422170205.GA827497@vauxhall.crustytoothpaste.net","threadId":"39126","inReplyTo":"20150422153109.GO23476@inner.h.apk.li","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T17:02:06Z","receivedAt":"2015-04-22T17:02:06Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Apr 22, 2015 at 05:31:09PM +0200, Andreas Krey wrote:\n> On Wed, 22 Apr 2015 08:36:00 +0000, David Rodríguez wrote:\n> ...\n> > * User is relying on a custom path to select their Ruby version. For\n> > example, let's say the first folder in path is \"~/.rubies/2.2.2/bin\".\n> > * User runs \"/usr/bin/git commit\" and a pre-commit hook is triggered.\n> > * The pre-commit hook starts with \"#!/us/bin/env ruby\" to select the\n> > Ruby to be used in the hook,\n> \n> Yes...but shouldn't the hook itself know which ruby version it needs?\n> \n> After all, if I go into that directory with another ruby setup in my\n> PATH, the hook should still work, and presumably that requires that\n> the hook itself selects its version, and not the user's context.\n\nMore generally, #!/usr/bin/env ruby is saying, \"I want whatever ruby the\nuser chooses.\"  If you want a ruby that has certain gems, or certain\nfeatures (e.g. Array#to_h), then that's not what you want.\n#!/usr/bin/env ruby is basically only safe if you're willing to accept\nany potential version that might show up.\n\nYou can use a multiline shebang[0] if you need to execute shell code to\nmake the decision at runtime, such as if you need to use $HOME in the\npath to your ruby, or select from multiple different options.\n\n[0] http://rosettacode.org/wiki/Multiline_shebang\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"259809","messageId":"5537DEC7.2020303@gmail.com","threadId":"39126","inReplyTo":"20150422170205.GA827497@vauxhall.crustytoothpaste.net","subject":"Re: git's directory is _prepended_ to PATH when called with an absolute path","fromName":"David Rodríguez","fromEmail":"deivid.rodriguez@gmail.com","sentAt":"2015-04-22T17:47:51Z","receivedAt":"2015-04-22T17:47:51Z","isPatch":false,"sender":{"key":"deivid.rodriguez@gmail.com","avatar":"https://gravatar.com/avatar/a1cc6e0d09fa7ad750142933abbcc225b647baa36e04fedda00fad1eb2e7a0e1?d=mp&s=160"},"body":"On 22/04/15 14:02, brian m. carlson wrote:\n> \"I want whatever ruby the\n> user chooses.\"\nThis is exactly what I want. The problem is that git overrides the \nuser's choice by prepending /usr/bin to the path and thus making \n/usr/bin/env choose system's ruby version. Which is almost always not \nthe Ruby the user chose.\n"}]}