git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Xheroz 128 <kenneth.951218@gmail.com>, git@vger.kernel.org
Subject: Re: Git extra hook, pre-upload
Date: Thu, 3 Jan 2019 02:29:40 -0500	[thread overview]
Message-ID: <20190103072940.GA24925@sigill.intra.peff.net> (raw)
In-Reply-To: <87k1jqem1p.fsf@evledraar.gmail.com>

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:
> 
> https://public-inbox.org/git/CAMK1S_jaEWV=F6iHKZw_6u5ncDW0bPosNx-03W9bOLOfEEEY1Q@mail.gmail.com/
> 
> 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:

  uploadpack.packObjectsHook
	     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).

So:

  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
     work).

-Peff

  parent reply	other threads:[~2019-01-03  7:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-30 20:11 Git extra hook, pre-upload Xheroz 128
2018-12-30 21:34 ` Ævar Arnfjörð Bjarmason
2019-01-02 17:27   ` Junio C Hamano
2019-01-03  7:29   ` Jeff King [this message]
     [not found]     ` <A842150D-2A45-4ABB-9B0F-DF516F7A2737@gmail.com>
2019-01-06  6:07       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190103072940.GA24925@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kenneth.951218@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).