git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: post-checkout hook not run on clone

From
Jeff King <peff@peff.net>
Date
Mar 3, 2009, 04:28 UTC
Message-ID
<20090303042848.GC18136@coredump.intra.peff.net>
In-Reply-To
<20273.1236033817@relay.known.net>
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
Previous: layerNext: layer
Message 2 of 11 in “post-checkout hook not run on clone”
  1. layerMar 2, 2009
  2. Jeff KingMar 3, 2009
  3. layerMar 3, 2009
  4. Jeff KingMar 3, 2009
  5. clone: run post-checkout hook when checking outJeff King, Mar 3, 2009
  6. Junio C HamanoMar 3, 2009
  7. Jay SoffianMar 3, 2009
  8. Nanako ShiraishiMar 3, 2009
  9. Jeff KingMar 3, 2009
  10. layerMar 4, 2009
  11. Shawn O. PearceMar 3, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.