All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Eric Belhomme <rico-ml@ricozome.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: how-to get commit content with pre-receive hook ?
Date: Thu, 6 Apr 2017 20:38:19 +0200	[thread overview]
Message-ID: <CACBZZX7xA92e5n=E8fdGHiBHaqzRjP_MVWsaE2v=DcVmCO2r0w@mail.gmail.com> (raw)
In-Reply-To: <955c152a-b278-ecfd-8bc7-671c3aa81dc6@ricozome.net>

On Thu, Apr 6, 2017 at 4:03 PM, Eric Belhomme <rico-ml@ricozome.net> wrote:
> Until now I ever had a quite "basic" Git usage, but now I'm working on a
> project based on Git hooks feature.. and I'm a very beginner with Git hooks
> !
>
> My need consist doing a syntax check on submitted files before a 'git push'.
> So the right hook is 'pre-receive' and I'm already able to identify the
> files I want to check using 'git show'.
>
> But I don't know how to get the *content* of the file being submitted to run
> my syntax check rules against it !
>
> I googled but most examples using pre-receive I found are doing sanity check
> on enveloppe but never on actual content of the file !
>
> Could someone here put me on the rails ?
>
> Regards,

As documented in githooks(5), the hook gets a list of these on stdin:

    <old-value> SP <new-value> SP <ref-name> LF

That means that you can use any git command to inspect that ref range, e.g.:

    git log -p <old>..<new>
    git diff <old>..<new>

Or (pseudocode):

    git show <commit>:<some path> for $(git rev-list <old>..<new>)

This is no different than how you'd inspect the content in your git
repo, e.g. to get the README.md content of the master branch of
git.git:

    $ git ls-tree master|grep README
    100644 blob f17af66a97c8097ab91f074478c4a5cb90425725    README.md
    $ git cat-file blob f17af66a97c8097ab91f074478c4a5cb90425725|wc
         61     397    3001

  reply	other threads:[~2017-04-06 18:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06 14:03 how-to get commit content with pre-receive hook ? Eric Belhomme
2017-04-06 18:38 ` Ævar Arnfjörð Bjarmason [this message]
2017-04-06 18:48   ` Stefan Beller
2017-04-06 20:13 ` Igor Djordjevic

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

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

  git send-email \
    --in-reply-to='CACBZZX7xA92e5n=E8fdGHiBHaqzRjP_MVWsaE2v=DcVmCO2r0w@mail.gmail.com' \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=rico-ml@ricozome.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.