From 0a5354b749413d39bfd1d395e42d7388b3ce771c Mon Sep 17 00:00:00 2001 From: Pawel Szczepaniak Date: Fri, 23 Sep 2016 10:22:10 +0200 Subject: [PATCH 1/2] Added dependencies in Gemfile; Option to test all files with pre-commit hook --- Gemfile | 5 ++++- pre-commit | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1afcab2..9e13b34 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,8 @@ source "https://rubygems.org" -gem 'puppet', '3.8.6' +gem 'r10k' gem 'rspec-puppet' +gem 'json_pure' +gem 'psych' +gem 'puppet', '3.8.6' gem 'puppet-lint', '2.0.0' diff --git a/pre-commit b/pre-commit index 646940a..2489b24 100755 --- a/pre-commit +++ b/pre-commit @@ -9,6 +9,14 @@ RC=0 hook_dir="$(dirname "$0")" hook_symlink="$(readlink "$0")" +# Manage arguments passed to script +while getopts ":a" o; do + case "${o}" in + a) + CHECK_ALL=true + esac +done + # Figure out where commit hooks are if [[ ! -z "$hook_symlink" ]] && ! [[ "$hook_symlink" == ../* ]]; then #pre-commit is setup as a symlink @@ -41,7 +49,13 @@ fi SAVEIFS=$IFS IFS=$(echo -en "\n\b") -for changedfile in $(git diff --cached --name-only --diff-filter=ACM); do +if [ $CHECK_ALL ]; then + files_to_check=$(find $git_root) +else + files_to_check=$(git diff --cached --name-only --diff-filter=ACM) +fi + +for changedfile in files_to_check; do [[ -f "$changedfile" ]] || continue #check puppet manifest syntax if type puppet >/dev/null 2>&1; then From fdd5541ec794b854193f47e332d1f123fc1d2aec Mon Sep 17 00:00:00 2001 From: Pawel Szczepaniak Date: Fri, 23 Sep 2016 10:50:35 +0200 Subject: [PATCH 2/2] Adapted error message --- pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre-commit b/pre-commit index 2489b24..7a1e13b 100755 --- a/pre-commit +++ b/pre-commit @@ -55,7 +55,7 @@ else files_to_check=$(git diff --cached --name-only --diff-filter=ACM) fi -for changedfile in files_to_check; do +for changedfile in $files_to_check; do [[ -f "$changedfile" ]] || continue #check puppet manifest syntax if type puppet >/dev/null 2>&1; then @@ -156,7 +156,7 @@ fi #summary if [[ "$failures" -ne 0 ]]; then - echo -e "$(tput setaf 1)Error: $failures subhooks failed. Aborting commit.$(tput sgr0)" + echo -e "$(tput setaf 1)Error: $failures subhooks failed. Please fix above errors.$(tput sgr0)" exit 1 fi