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

Re: How does receive-pack and pre-receive hook works ?

From
Shawn Pearce <spearce@spearce.org>
Date
Jun 27, 2010, 07:00 UTC
Message-ID
<AANLkTikrSABpX8rFLIYwwQaN3zfnzEuqr6ugbPEOzo76@mail.gmail.com>
In-Reply-To
<AANLkTinYRF2m95MU2c817bK6mfehPt_OMBH45R6laNUe@mail.gmail.com>
On Sat, Jun 26, 2010 at 7:24 PM, Mahesh Vaidya <forvaidya@gmail.com> wrote:
Show 6 quoted lines
> How does receive-pack and pre-receive hook works ?
>
> I Would like know where does Git saves whatever I am pushing before
> exit 0 of this hook; Specifically how does it understand about
> 'd6d147f432869037a7ac8bdca3a2d5bc0cdc1e9f' which is not part of
> destination depot / repo.

The objects that were sent are actually added to the destination repository, by creating one or more loose objects in the objects/ directory, or a single new pack file in the objects/pack/ directory if more than 100 objects were sent. These objects are in the repository, but they aren't actually reachable from any ref, so they are subject to garbage collection during a future `git gc`. Once the objects are safely stored, the hooks are invoked... which means the hooks can access the objects, as they are already part of the repository.

If pre-receive or update exits with a non-zero status, the objects stay around, but the references aren't updated. By not updating the references, the objects aren't reachable, and the objects will be automatically removed during a future `git gc`.

-- 
Shawn.
Previous: Mahesh Vaidya
Message 2 of 2 in “How does receive-pack and pre-receive hook works ?”
  1. Mahesh VaidyaJun 27, 2010
  2. Shawn PearceJun 27, 2010

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.