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

Re: how to use two bare repositories?

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 12, 2008, 00:55 UTC
Message-ID
<7vbq4fnb71.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<200804120042.m3C0gmWR004445@mi0.bluebottle.com>
しらいしななこ  <nanako3@bluebottle.com> writes:
Show 12 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Typically, you would update a bare repository used for publishing by
>> pushing into it, and trigger update-server-info from the post-update hook.
>>
>> But it is perfectly fine if you initiate a mirror-fetch from that
>> publishing repository (in your case, "B"), and the caller to "git fetch"
>> can run update-server-info after fetching.
>>
>> And no, there is not a "post-fetch" hook, nor is there a need for one.
>
> Can you please explain why?

There are five valid reasons you might want to have a hook to a git command/operation:

 (1) A hook that countermands the normal decision made by the underlying
     command.  Examples of this class are the update hook and the
     pre-commit hook.
 (2) A hook that operates on data generated after the command starts to
     run.  The ability to munge the commit log message by the commit-msg
     hook is an example.
 (3) A hook that operates on the remote end of the connection that you may
     not otherwise have access to, other than over the git protocol.  An
     example is the post-update hook that runs update-server-info.
 (4) A hook that runs under a lock that is acquired by the command for
     mutual exclusion.  Currently there is no example, but if we allowed
     the update hook to modify the commit that was pushed through
     send-pack => receive-pack pair, which was discussed on the list a
     while ago, it would be a good example of this.
 (5) A hook that is run differently depending on the outcome of the
     command.  The post-merge hook conditionally run by git-pull is an
     example of this (it is not even run if no merge takes place).
     Another example is the post-checkout hook that gets information that
     is otherwise harder to get (namely, if it was a branch checkout or
     file checkout -- you can figure it out by examining the command line
     but that already is part of the processing git-checkout does anyway,
     so no need to force duplicating that code in the userland).

You cannot do an equivalent operation from outside the git command for the above classes of operations. You need hooks for them.

On the other hand, if you want to always cause an action before or after running a git opeation locally, you do not have to have a hook. This is true even if the action you would do after running a git operation depends on what happened (class (5) above) if the result is easily observable after the fact.

Of course there can be a very valid exception to the above policy. If it is common enough so that the policy means effectively everybody has to reinvent the same wrapper. But for this particular case I do not think that is the case.

Previous: しらいしななこ
Message 4 of 4 in “Re: how to use two bare repositories?”
  1. Oliver KullmannApr 11, 2008
  2. Junio C HamanoApr 12, 2008
  3. しらいしななこApr 12, 2008
  4. Junio C HamanoApr 12, 2008

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.