LoginSignup
1
1

More than 5 years have passed since last update.

Git で複数のスクリプトをフックに設定する

Posted at

はじめに

簡単な手順

スクリプト作成

.git/hooks/hook-chain
#!/bin/bash
#
# author: orefalo

hookname=`basename $0`


FILE=`mktemp`
trap 'rm -f $FILE' EXIT
cat - > $FILE

for hook in $GIT_DIR/hooks/$hookname.*
do
    if test -x "$hook"; then
#       echo $hook
        cat $FILE | $hook "$@"
        status=$?

        if test $status -ne 0; then
            echo Hook $hook failed with error code $status
            exit $status
        fi
    fi
done

フックに設定(pre-commit に設定する場合)

$ cd .git/hooks
$ chmod +x hook-chain
$ mv pre-commit pre-commit.rename_if_already_exist
$ ln -s hook-chain pre-commit
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1