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

[PATCH] githooks.txt: clarify push hooks are always executed in $GIT_DIR

From
Simon Ruderich <simon@ruderich.org>
Date
Apr 29, 2017, 12:28 UTC
Message-ID
<20170429122829.lz56r7exh3ecynxb@ruderich.org>
In-Reply-To
<CACBZZX4uBL99y=ZaKZ7dqyP9Ne-cx=kYkh8p51p3VYOr3PQGSw@mail.gmail.com>

Listing the specific hooks might feel verbose but without it the reader is left to wonder which hooks are triggered during the push. Something which is not immediately obvious when only trying to find out where the hook is executed.

Signed-off-by: Simon Ruderich <simon@ruderich.org>
---
 Documentation/githooks.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
On Mon, Apr 10, 2017 at 01:13:15PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 10 quoted lines
> [snip]
>
> Can we say as we do now that:
>
> * All hooks regardless of type in bare repos execute in the bare repo
> * If you have a working tree hooks use that
>
> But add:
>
> * Working trees are ignored by any hooks invoked on your behalf during a push.
Hello,

Maybe like this? I reordered the cases as it felt more natural that the general case is first and followed by the one with the exception.

> Some ad-hoc testing reveals that this rule also goes for the
> push-to-checkout hook. Should it? Wouldn't it be more useful if it
> broke the pattern, since it's dealing with the working tree on the
> other side? Junio?

I added push-to-checkout to the patch. Changing the behavior will break backwards compatibility so I think that's a no-go.

Regards Simon

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 32343ae29..706091a56 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -22,8 +22,10 @@ changed via the `core.hooksPath` configuration variable (see
 linkgit:git-config[1]).
 
 Before Git invokes a hook, it changes its working directory to either
-the root of the working tree in a non-bare repository, or to the
-$GIT_DIR in a bare repository.
+$GIT_DIR in a bare repository or the root of the working tree in a non-bare
+repository. An exception are hooks triggered during a push ('pre-receive',
+'update', 'post-receive', 'post-update', 'push-to-checkout') which are always
+executed in $GIT_DIR.
 
 Hooks can get their arguments via the environment, command-line
 arguments, and stdin. See the documentation for each hook below for
-- 
2.11.0

-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 4 in “Unexpected working directory in post-receive hook in non-bare repository”
  1. Simon RuderichApr 9, 2017
  2. Ævar Arnfjörð BjarmasonApr 10, 2017
  3. githooks.txt: clarify push hooks are always executed in $GIT_DIRSimon Ruderich, Apr 29, 2017
  4. Ævar Arnfjörð BjarmasonApr 29, 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.