According to the manual, the post-checkout
hook is run after a git checkout
(just as expected) but also after a git clone
(unless you pass --no-checkout
).
Very well, now, considering the following:
git clone
--template
are copied non-executable and therefore not executed after git clone
It seems impossible that a post-checkout
hook ever gets executed after a git clone
. Still, the githooks
man page at http://git-scm.com/docs/githooks explicitely states a way to avoid it being executed, and also parameters passed in case it is executed, which would indicate it is possible to execute a custom hook after a git-clone
.
So, how is it possible? I am obviously missing something here.
Turns out
No, there isn't any clone hook.
The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.
In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'...
Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle.
I suppose you could make a custom installation - rename the hooks in .../share/git-core/templates/hooks
to remove the .sample
suffix.
You could also make a template directory full of symlinks to a hooks directory inside the repository, (e.g. post-checkout -> ../../hooks/post-checkout
). Then if the cloned repo contained that particular hook, it'd get executed.
You're right, though, in most cases it will not happen.
Edit: I just tested it, and the --template
option does appear to preserve permissions, so that's a much more straight-forward way to make it happen. What'd you see to indicate that it stripped that bit?
The final say on versions: You're looking at documentation online for a newer version of git than you're using. This feature was added in dfa7a6c (clone: run post-checkout hook when checking out); git describe says this wasn't included until v1.6.2-rc2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With