# How does receive-pack and pre-receive hook works ?

2 messages from 2010-06-27 to 2010-06-27. Participants: Mahesh Vaidya, Shawn Pearce.
Thread: https://gitlist.dev/t/24209

## Mahesh Vaidya, 2010-06-27 02:24

Subject: How does receive-pack and pre-receive hook works ?
Message-ID: <AANLkTinYRF2m95MU2c817bK6mfehPt_OMBH45R6laNUe@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinYRF2m95MU2c817bK6mfehPt_OMBH45R6laNUe%40mail.gmail.com

```
How does receive-pack and pre-receive hook works ?

I have added following in pre-recieve hook; all works fine. git
rev-list --pretty d6d147f432869037a7ac8bdca3a2d5bc0cdc1e9f
^a3fe19833480023b72350d6e56e939cbd0ba2c8b

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.

Thx/ Mahesh.

```

## Shawn Pearce, 2010-06-27 07:00

Subject: Re: How does receive-pack and pre-receive hook works ?
Message-ID: <AANLkTikrSABpX8rFLIYwwQaN3zfnzEuqr6ugbPEOzo76@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikrSABpX8rFLIYwwQaN3zfnzEuqr6ugbPEOzo76%40mail.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:
> 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.

```
