git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Matthew RothenbergNext: Matthew Rothenberg
Message 2 of 12 in “PATH modifications for git-hook processes”
  1. Matthew RothenbergApr 14, 2015
  2. Junio C HamanoApr 14, 2015
  3. Matthew RothenbergApr 15, 2015
  4. Jeff KingApr 16, 2015
  5. Jeff KingApr 16, 2015
  6. David RodríguezApr 22, 2015
  7. Junio C HamanoApr 22, 2015
  8. stop putting argv[0] dirname at front of PATHJeff King, Apr 22, 2015
  9. Eric SunshineApr 22, 2015
  10. Jeff KingApr 22, 2015
  11. Jonathan NiederApr 22, 2015
  12. Jeff KingApr 22, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.