Re: Git extra hook, pre-upload
- Date: Thu, 3 Jan 2019 02:29:40 -0500
- From: Jeff King <peff@xxxxxxxx>
- Subject: Re: Git extra hook, pre-upload
On Sun, Dec 30, 2018 at 10:34:26PM +0100, Ævar Arnfjörð Bjarmason wrote:
> On Sun, Dec 30 2018, Xheroz 128 wrote:
> > Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client.
> > Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook?
> We do not have such a pre-upload hook, but could have one. There's an
> old thread from 2011 detailing some potential downsides:
> FWIW I think most servers who find themselves needing such a hook use it
> to e.g. log how many fetches a given repository might serve, and end up
> instead wrapping git commands in some custom shell.
> It's also possible to imagine a much deeper integration for such a hook,
> e.g. something that would allow you to implement the functionality of
> the uploadpack.* variables and more in your own code, but I don't know
> if that's the sort of thing you're imagining.
Since that thread, we've added this config:
If this option is set, when upload-pack would run git
pack-objects to create a packfile for a client, it will run
this shell command instead. The pack-objects command and
arguments it would have run (including the git pack-objects
at the beginning) are appended to the shell command. The
stdin and stdout of the hook are treated as if pack-objects
itself was run. I.e., upload-pack will feed input intended
for pack-objects to the hook, and expects a completed
packfile on stdout.
Note that this configuration variable is ignored if it is
seen in the repository-level config (this is a safety
measure against fetching from untrusted repositories).
1. That's some prior art for how an upload-pack hook could behave
without introducing a security problem.
2. Depending on what you want to do, this hook may be enough already.
But it can't do everything (for instance, a fetch which results in
no objects being requested would not trigger the hook at all, so if
you were planning to keep stats about no-op fetches, it would not