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

Re: [RFC/PATCH v2 2/3] run-command: make sure hooks have always GIT_DIR

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 23, 2014, 21:15 UTC
Message-ID
<53582d78e82e6_24448772ecf8@nysa.notmuch>
In-Reply-To
<xmqqoazrye6w.fsf@gitster.dls.corp.google.com>
Junio C Hamano wrote:
Show 5 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
> 
> > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> 
> Why is this a good change?

When a hook is called from a command without NEED_WORK_TREE, GIT_DIR is not set (e.g. git branch).

> How does it prevent existing hook scripts from suddenly start
> misbehaving, where they do *not* expect to see an explicit GIT_DIR
> pointing at the original repository hook gets run in exported into
> their environment?
Fine, I'll use "${GIT_DIR-.git}" in my hook tests.
Show 7 quoted lines
> For example, one of my post-receive hooks in a repository I push into records
> $cwd (which is the GIT_DIR of receiving repository), chdir's to another
> repository and then executes "git pull $cwd" from there, and that relies on
> the fact that being at the top-level of that other repository without GIT_DIR
> environment pointing at elsewhere but having .git directory in that top-level
> repository is sufficient to kick the auto-discovery of the repository that
> receives the "pull" in order to work correctly.
Let's hope post-receive is never called from a command that has NEED_WORK_TREE then.
-- 
Felipe Contreras
Previous: Junio C HamanoNext: Felipe Contreras
Message 7 of 12 in “New 'update-branch' hook”
  1. 0/3 New 'update-branch' hookFelipe Contreras, Apr 23, 2014
  2. 1/3 sh-setup: export GIT_DIRFelipe Contreras, Apr 23, 2014
  3. Jeff KingApr 23, 2014
  4. Junio C HamanoApr 23, 2014
  5. 2/3 run-command: make sure hooks have always GIT_DIRFelipe Contreras, Apr 23, 2014
  6. Junio C HamanoApr 23, 2014
  7. Felipe ContrerasApr 23, 2014
  8. 3/3 Add 'update-branch' hookFelipe Contreras, Apr 23, 2014
  9. Junio C HamanoApr 23, 2014
  10. Felipe ContrerasApr 23, 2014
  11. Junio C HamanoApr 23, 2014
  12. Felipe ContrerasApr 23, 2014

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.