воскресенье, 14 апреля 2013 г.

pre-commit hooks for checking commits

there are examples for ruby code and puppet manifests(chef can validate automatically, but stupid puppet can't):
1. create file ./.git/hooks/pre-commit
2. add code

#!/bin/sh
echo 'working pre commit hook'
git diff --cached --name-only --diff-filter=ACM | while read file; do
  # check only puppet files
  if [ "${file##*.}" == 'pp' ]
  then
    echo "check $file"
    puppet parser validate $file
  fi
done

3. require set exec permissions. DO NOT FORGET !!!! (it is cause for not execution hook)
chmod +x ./.git/hooks/pre-commit
Complete.

Also example for ruby:

#!/bin/sh
echo 'working pre commit hook'
git diff --cached --name-only --diff-filter=ACM | while read file; do
  if [ "${file##*.}" == 'rb' ]
  then
    echo "check rubocop $file"
    rubocop $file
  fi
done

Комментариев нет: