From: Jeff King <peff@peff.net>
To: Mark Plaksin <happy@usg.edu>
Cc: git@vger.kernel.org
Subject: Re: Syntax check via update hook?
Date: Sat, 9 May 2009 10:47:12 -0400 [thread overview]
Message-ID: <20090509144711.GA3926@sigill.intra.peff.net> (raw)
In-Reply-To: <wsprejtm71.fsf@usg.edu>
On Fri, May 08, 2009 at 03:43:30PM -0400, Mark Plaksin wrote:
> What's the best way to make the update hook do a syntax check?
>
> We want to switch our Puppet [1] config repository from SVN to Git. Our
> SVN repository has a pre-commit hook that does a syntax check. The hook
> runs Puppet to check the syntax of the file(s) being committed and if the
> check fails, the commit fails. With SVN that hook runs on the server so
> it's easy to have (the correct version of) the puppet binary there for
> the hook to use.
>
> Once Puppet config changes are committed to to our SVN repository they
> are automatically pushed into our production Puppet config. We want to
> do something similar with Git--once commits are successfully pushed to
> the master repository they are automatically pulled and become our
> production Puppet config.
That sounds like a reasonable goal. In the hook itself, you can do one
of:
1. Look at the diff to the original version to make sure you're not
introducing anything bogus. This is sufficient for syntax issues on
single lines, etc, and is obviously pretty efficient. But it won't
cover "does this whole thing build?" types of checks, which I think
is what you want.
2. Check out the whole tree to a temp directory and run your full
syntax check there. The simplest way would be by using "git
archive" to generate the tree. You can make this a bit more
efficient by keeping the temp directory between runs and using
git to just update the changed files. Off the top of my head, that
would look something like:
$ cat <<EOF >.git/hooks/update
#!/bin/sh
GIT_INDEX_FILE=/path/to/tempdir/index; export GIT_INDEX_FILE
cd /path/to/tempdir/tree &&
mkdir -p tree &&
git read-tree "$3" &&
git checkout-index &&
your_syntax_check
EOF
$ chmod +x .git/hooks/update
-Peff
next prev parent reply other threads:[~2009-05-09 14:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-08 19:43 Syntax check via update hook? Mark Plaksin
2009-05-09 14:47 ` Jeff King [this message]
2009-05-12 19:16 ` Mark Plaksin
2009-05-14 6:55 ` Jeff King
2009-05-14 19:52 ` Mark Plaksin
2009-05-20 15:13 ` Mark Plaksin
2009-05-20 15:22 ` Jeff King
2009-05-20 20:57 ` Mark Plaksin
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=20090509144711.GA3926@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=happy@usg.edu \
/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 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 NNTP newsgroup(s).