Skip to content

Instantly share code, notes, and snippets.

@davidclin
Forked from mjackson/multiple-git-hooks.sh
Created October 31, 2018 05:28
Show Gist options
  • Select an option

  • Save davidclin/f2d064b0a46f00e26578032fbe6aeaf3 to your computer and use it in GitHub Desktop.

Select an option

Save davidclin/f2d064b0a46f00e26578032fbe6aeaf3 to your computer and use it in GitHub Desktop.

Revisions

  1. Michael Jackson created this gist Feb 6, 2018.
    27 changes: 27 additions & 0 deletions multiple-git-hooks.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/sh

    # This script should be saved in a git repo as a hook file, e.g. .git/hooks/pre-receive.
    # It looks for scripts in the .git/hooks/pre-receive.d directory and executes them in order,
    # passing along stdin. If any script exits with a non-zero status, this script exits.

    script_dir=$(dirname $0)
    hook_name=$(basename $0)

    hook_dir="$script_dir/$hook_name.d"

    if [[ -d $hook_dir ]]; then
    stdin=$(cat /dev/stdin)

    for hook in $hook_dir/*; do
    echo "Running $hook_name/$hook hook"
    echo "$stdin" | $hook "$@"

    exit_code=$?

    if [ $exit_code != 0 ]; then
    exit $exit_code
    fi
    done
    fi

    exit 0