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

Re: Server-side hooks on non-bare repository

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2017, 21:42 UTC
Message-ID
<xmqq1suankus.fsf@junio-linux.mtv.corp.google.com>
In-Reply-To
<719CE082-14AB-4E18-AE7D-7D2A818CF499@mplew.is>
Mike Lewis <mike@mplew.is> writes:
Show 8 quoted lines
> I’m having some issues with using server-side hooks when pushing
> to a non-bare repository. In my git config, I have
> `receive.denyCurrentBranch` set to `updateInstead`, which behaves
> as expected, and updates the current working tree when the current
> branch is pushed to. However, attempting to process those changes
> with pre-receive and post-receive hooks results in some unexpected
> behavior regarding the current working directory of the scripts
> and using git commands.

The pre-receive hook is to inspect the objects and ref updates and say "yes, allow it" or "no, refuse it"---you are not supposed to do anything else, so even though what processing you are interested in doing in your "attempting to process" is unclear, this hook is not what you want to use anyway.

The post-receive hook is a more interesting case. It is called only after everything finishes, so it is like running a custom script after "git push" is processed.

> I’ve tested these issues using both git
> 2.11 and 2.12 on various systems (macOS and CentOS), and get the
> same behavior each time.

That is a very good news, as I do not think at least in the past few years we planned to change the established behaviour of the hook.

Show 5 quoted lines
> 1. When using a non-bare repository, I would expect the the
> working directory of the hook to be the root directory of the
> working tree,...
> 2. While running the hooks, git treats the repository as being
> bare, regardless of whether it actually is.

Yes, and it is unlikely that the behaviour wrt to where $cwd is during the hook's execution will ever change; otherwise existing scripts that know what the rule is (i.e. the rule you figured out in 2.) will be broken. denycurrent=updateinstead *is* an odd-man out, and its processing is purely internal---its addition does not mean hook authors are suddenly required to do things differently depending on bare/non-bare-ness of the repository.

Previous: Mike LewisNext: Mike Lewis
Message 2 of 3 in “Server-side hooks on non-bare repository”
  1. Mike LewisMar 4, 2017
  2. Junio C HamanoMar 6, 2017
  3. Mike LewisMar 6, 2017

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.