Re: PATH modifications for git-hook processes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 14, 2015, 17:17 UTC
- Message-ID
- <xmqqk2xe39zt.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <CAKuTQSGEmHHr-c+Tc2jM-JPkx6+_f3gp8Zjj8EuQy_e4=PvMzg@mail.gmail.com>
Matthew Rothenberg <mroth@khanacademy.org> writes:
> - what is the expected PATH modification behavior for subprocesses of > git-hooks? Is this documented anywhere? > - what would be causing /usr/local/bin to be prepended here, and can > it be adjusted via preference?
This is not limited to hooks and very much deliberate, I think. In order to make sure anything that is called from "git" wrapper gets picked up from GIT_EXEC_PATH so that the matching version of the git subprogram is used, "git <cmd>" does this before running "git-<cmd>" (in git.c):
/* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path();
And setup_path() is defined in exec_cmd.c to start the new PATH with git-exec-path, and then the path to the running "git" itself, and then finally the external PATH.