├── README.mkd ├── bin ├── git-hook ├── git-hook-help ├── git-hook-install ├── git-hook-list ├── git-hook-test └── git-hook-uninstall └── hook /README.mkd: -------------------------------------------------------------------------------- 1 | # Lightweight Git Hook Management Tool: git-hook 2 | 3 | git-hook is very eazy git's hook management tool. 4 | 5 | ## Installation 6 | 7 | $ cd 8 | $ git clone git://github.com/rosylilly/git-hook.git .git-hook 9 | $ echo 'export PATH="$HOME/.git-hook/bin:$PATH"' >> ~/.bash_profile 10 | 11 | if you're using zsh: `~/.bash_profile` replace `~/.zshenv` 12 | 13 | ### Upgrading 14 | 15 | $ cd ~/.git-hook 16 | $ git pull 17 | 18 | ## Usage 19 | 20 | install `pre-commit` hook: 21 | 22 | $ git hook install pre-commit gist:0000 23 | 24 | uninstall `pre-commit` hook: 25 | 26 | $ git hook ls pre-commit 27 | gist-0000 28 | $ git hook uninstall pre-commit gist-0000 29 | 30 | more usage: 31 | 32 | $ git hook install pre-commit http://raw.github.com/gist/0000 33 | $ git hook install post-commit ~/my-git-hooks/post-commit 34 | 35 | ## Development 36 | 37 | git-hook source code is hosted on [Github](https://github.com/rosylilly/git-hook). 38 | 39 | Please feel free to submit pull requests and file bugs on the [issue tracker](https://github.com/rosylilly/git-hook/issues). 40 | 41 | ### History 42 | 43 | #### 1.0.1 (2012-11-12) 44 | - fix bug 45 | 46 | #### 1.0.0 (2012-08-01) 47 | - implemented ``git hook test`` 48 | - implemented ``git hook install`` with name option 49 | 50 | #### 0.0.1 (2012-07-30) 51 | - first release 52 | 53 | ### License 54 | 55 | Copyright (c) 2012 Sho Kusano 56 | 57 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 58 | 59 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 62 | -------------------------------------------------------------------------------- /bin/git-hook: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | command="$1" 6 | case "$command" in 7 | "" | "-v" | "--version" ) 8 | echo "git-hook 1.0.1" 9 | ;; 10 | * ) 11 | # alias 12 | case "$command" in 13 | ls ) 14 | command="list" 15 | ;; 16 | rm ) 17 | command="uninstall" 18 | ;; 19 | --help | -h ) 20 | command="help" 21 | ;; 22 | esac 23 | command_path="$(command -v "git-hook-$command" || true)" 24 | if [ -z "$command_path" ]; then 25 | echo "git-hook no such command \`$command'" >&2 26 | exit 1 27 | fi 28 | 29 | shift 1 30 | exec "$command_path" "$@" 31 | ;; 32 | esac 33 | -------------------------------------------------------------------------------- /bin/git-hook-help: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | case "$1" in 4 | "") 5 | echo "usage: git hook [args] 6 | 7 | Some useful git-hook commands are: 8 | install install git-hook 9 | uninstall uninstall git-hook 10 | list list git-hooks 11 | test test git-hook 12 | 13 | See 'git hook help ' for information for a specific command. 14 | For details, see https://github.com/rosylilly/git-hook#readme" 15 | ;; 16 | "install" ) 17 | echo "usage: git hook install [--force] [--link] [] 18 | 19 | Define to kick when happened. See 'man githooks' for all s defined. 20 | When defined to intall ' name is . 21 | 22 | You can specify as the following: 23 | URL example: https://raw.github.com/gist/1387542 24 | Gist example: gist:1387542 25 | File example: ~/gist/1387542 26 | 27 | --force Override an existing destination file. 28 | --link Create a symbolic link instead of copy. This option 29 | make sense only if a file is specified as hook." 30 | ;; 31 | "uninstall" ) 32 | echo "usage: git hook uninstall 33 | 34 | Uninstall one installed hook. 35 | 36 | You can know what to specify for by seeing 'git hook list ' 37 | 38 | See 'man githooks' for all s defined." 39 | ;; 40 | "list" ) 41 | echo "usage: git hook list [ [ ... ]] 42 | 43 | List up all hooks installed for . 44 | 45 | See 'man githooks' for all s defined." 46 | ;; 47 | "test" ) 48 | echo "usage: git hook test [ [ ...]] 49 | 50 | Kick 's hooks with s. See 'man githooks' for all s defined." 51 | ;; 52 | esac 53 | -------------------------------------------------------------------------------- /bin/git-hook-install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ARGS=() 4 | while [ -n "$1" ]; 5 | do 6 | case $1 in 7 | --force ) 8 | force=true 9 | shift 10 | ;; 11 | --link ) 12 | link=true 13 | shift 14 | ;; 15 | * ) 16 | ARGS=("${ARGS[@]}" "$1") 17 | shift 18 | ;; 19 | esac 20 | done 21 | 22 | timing="${ARGS[0]}" 23 | shift 24 | hook="${ARGS[1]}" 25 | shift 26 | preset_hook_name="${ARGS[2]}" 27 | shift 28 | 29 | ALLOWED_TIMING=`cat <&2 51 | exit 1 52 | fi 53 | 54 | template="$(dirname "$0")/../hook" 55 | 56 | cwd="$(pwd)" 57 | 58 | if [ -f "$hook" ]; then 59 | hook="$(cd $(dirname "$hook") && pwd)/$(basename $hook)" 60 | fi 61 | 62 | cd "./$(git rev-parse --show-cdup)" 63 | cd "$(git rev-parse --git-dir)/hooks" 64 | 65 | hookdiff="$(diff "$template" "$timing" 2>&1)" 66 | mkdir -p "installed/$timing" 67 | if [ -n "$hookdiff" ]; then 68 | if [ -x "$timing" ]; then 69 | mv "$timing" "installed/$timing/origin" 70 | fi 71 | ln -s "$template" "$timing" 72 | chmod +x "$timing" 73 | fi 74 | 75 | case "$hook" in 76 | http://* | https://* ) # via URL 77 | type="url" 78 | hook_name="$(basename "$hook")" 79 | url="$hook" 80 | ;; 81 | gist:* ) # via gist 82 | type="gist" 83 | gist=${hook:5} 84 | hook_name="gist-$gist" 85 | url="https://gist.github.com/raw/$gist" 86 | ;; 87 | * ) # other 88 | if [ -f "$hook" ]; then # via file 89 | type="file" 90 | hook_name="$(basename "$hook")" 91 | fi 92 | ;; 93 | esac 94 | 95 | if [ -n "$preset_hook_name" ]; then 96 | hook_name="$preset_hook_name" 97 | fi 98 | 99 | install_path="installed/$timing/$hook_name" 100 | 101 | if [ -f "$install_path" ] && [ -z "$force" ]; then 102 | echo "\`$hook_name' is installed. force install with --force option" >&2 103 | exit 1 104 | fi 105 | 106 | case "$type" in 107 | url | gist ) 108 | curl -L -o "$install_path" "$url" 109 | ;; 110 | file ) 111 | if [[ -n "$link" ]]; then 112 | ln -s "$hook" "$install_path" 113 | else 114 | cp "$hook" "$install_path" 115 | fi 116 | ;; 117 | esac 118 | 119 | chmod +x "$install_path" 120 | 121 | echo "\`$hook_name' installed" 122 | 123 | cd "$cwd" 124 | -------------------------------------------------------------------------------- /bin/git-hook-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | timings="$*" 4 | 5 | ALLOWED_TIMING=`cat <&2 28 | exit 1 29 | fi 30 | 31 | cwd="$(pwd)" 32 | 33 | cd "./$(git rev-parse --show-cdup)" 34 | cd "$(git rev-parse --git-dir)/hooks/installed/$timing" 35 | 36 | if [ -x "$hook" ]; then 37 | rm "$hook" 38 | echo "\`$hook' uninstalled" 39 | else 40 | echo "\`$hook' is not found" >&2 41 | exit 1 42 | fi 43 | -------------------------------------------------------------------------------- /hook: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | timing="$(basename "$0")" 4 | hooks="$(git rev-parse --git-dir)/hooks/installed/$timing" 5 | cwd="$(pwd)" 6 | 7 | if [ -z "$hooks" ]; then 8 | exit 0 9 | fi 10 | 11 | for hook in `ls $hooks` 12 | do 13 | cd "$cwd" 14 | ./$hooks/$hook "$@" 15 | [ "$?" -ne 0 ] && exit 1 16 | done 17 | 18 | exit 0 19 | --------------------------------------------------------------------------------