Re: post-checkout hook not run on clone
From: Jeff King <hidden>
Date: 2016-06-15 22:46:19
On Mon, Mar 02, 2009 at 02:43:37PM -0800, layer wrote:
I realize this might be a feature, but when I switch to the master branch with "git checkout master" it is, and I would think that a clone that gets the master branch would also does a sort of "checkout master" and would run the hook.
Right. Hooks are not cloned with the repo.
In any case, I'd be happy of there was a post-clone hook, instead, but there isn't.
The general wisdom on the list is that it's a bad idea to run remote code arbitrarily for security reasons (i.e., "git clone git://host/foo.git" should not automatically run code from "host"). Even if you are going to build and run the contents of "foo.git", you at least have a chance to inspect the changes via git. However, for situations where you are OK implicitly trusting the remote, it is obviously less convenient.
Any suggestions?
Most suggestions I have seen involve shipping the hooks in your repo, and then having users copy them to their .git/hooks directory (and you can even provide a script for that). Unfortunately, there is a chicken-and-egg problem there with the initial checkout. You could do something like (assuming the hooks are in "hooks" in the repo) to bootstrap: git clone -n <repo.git> cd repo git archive --format tar HEAD hooks | tar -C .git/hooks -xf - git checkout master -Peff