├── .gitignore ├── LICENSE ├── README.md ├── bin └── clone └── hooks └── post-checkout /.gitignore: -------------------------------------------------------------------------------- 1 | *~undo-tree~.gz 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Eric S Crosson 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 | DAMAGE.GNU GENERAL PUBLIC LICENSE 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | As git does not provide a `post-clone` hook, some repositories come with manual instructions for post-clone configuration. 4 | This project effectively provides a `post-clone` hook, allowing project maintainers to specify a project's post-clone behavior and install other various hooks. 5 | 6 | # Use 7 | 8 | To clone a repository with post-clone hooks: 9 | 10 | ```sh 11 | curl -fsSL https://raw.githubusercontent.com/git-hook/post-clone/master/bin/clone \ 12 | | bash -s -- 13 | ``` 14 | 15 | All arguments will be passed directly to `git clone`. 16 | 17 | > [!TIP] 18 | > If you'd rather not pipe `curl` to `bash`, use this approach instead: 19 | > 20 | > ```sh 21 | > git clone https://github.com/git-hook/post-clone /tmp/post-clone 22 | > git clone --template=/tmp/post-clone git@github.com:username/repo-of-interest 23 | > ``` 24 | 25 | In addition to cloning the repository, this will: 26 | 27 | - ensure `/hooks/` is symlinked to `/.git/hooks/`, if present in the cloned repo 28 | - ensure `/.git/hooks/post-clone` is invoked, if present in the cloned repo 29 | 30 | > [!NOTE] 31 | > This hook will not be automatically invoked again. 32 | 33 | # Benefits 34 | 35 | Using this `post-clone` template allows repo maintainers to: 36 | 37 | - automate installation of client-side git hooks 38 | - version-control this automation inside the relevant repository 39 | 40 | # Acknowledgements 41 | 42 | This git hook was inspired by [this StackOverflow post]. 43 | 44 | [this stackoverflow post]: http://stackoverflow.com/questions/2141492/git-clone-and-post-checkout-hook/2141577#2141577 45 | -------------------------------------------------------------------------------- /bin/clone: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Written by Eric Crosson 3 | # 2017-01-28 4 | # 5 | # This script clones the post-clone template and applies it to the 6 | # target repository. 7 | 8 | readonly template=$(mktemp -d /tmp/post-clone.XXXXX) 9 | 10 | teardown() { 11 | rm -rf "${template}" 12 | } 13 | trap teardown EXIT 14 | 15 | init() { 16 | cd "${template}" 17 | git init 18 | git remote add origin https://github.com/git-hook/post-clone.git 19 | git fetch origin 20 | git checkout --track origin/master 21 | cd - 22 | } 23 | 24 | main() { 25 | git clone --template="${template}" "$@" 26 | } 27 | 28 | init &>/dev/null 29 | main "$@" 30 | -------------------------------------------------------------------------------- /hooks/post-checkout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Written by Eric Crosson 3 | # 2016-10-12 4 | # 5 | # This hook can be used to save metadata about where a git repository 6 | # is cloned locally. The intent is to use this information in other 7 | # scripts that operate on the cloned git repository. 8 | # path to the newly cloned repo on disk 9 | 10 | readonly repo=$(git rev-parse --show-toplevel) 11 | 12 | main() { 13 | rm -rf -- "${repo}/.git/hooks" 14 | initializeSubmodules 15 | installClonedReposHooks 16 | invokeClonedReposPostCloneHook 17 | } 18 | 19 | initializeSubmodules() { 20 | git submodule update --init --recursive 21 | } 22 | 23 | installClonedReposHooks() { 24 | cd "${repo}/.git" 25 | rm -rf hooks 26 | ln -sf ../hooks 27 | cd - >/dev/null 28 | } 29 | 30 | invokeClonedReposPostCloneHook() { 31 | local -r post_clone_hook="${repo}/.git/hooks/post-clone" 32 | test ! -e "${post_clone_hook}" && return 33 | chmod u+x "${post_clone_hook}" 34 | ${post_clone_hook} 35 | } 36 | 37 | main "$@" 38 | --------------------------------------------------------------------------------