diff --git a/commit_hooks/config.cfg b/commit_hooks/config.cfg index 233d418..47fd56d 100644 --- a/commit_hooks/config.cfg +++ b/commit_hooks/config.cfg @@ -1,3 +1,4 @@ CHECK_PUPPET_LINT="enabled" # enabled, permissive or disabled (permissive runs but return code is ignored) USE_PUPPET_FUTURE_PARSER="enabled" # enabled or disabled +CHECK_INITIAL_COMMIT="disabled" # enabled or disabled export PUPPET_LINT_OPTIONS="" # puppet-lint options to use if no rc file is present. Defaults to "--no-80chars-check" diff --git a/pre-receive b/pre-receive index 7079097..1cf687a 100755 --- a/pre-receive +++ b/pre-receive @@ -32,6 +32,7 @@ export TERM # Decide if we want the puppet future parser (already on puppet 4?) CHECK_PUPPET_LINT="enabled" USE_PUPPET_FUTURE_PARSER="enabled" +CHECK_INITIAL_COMMIT="disabled" if [[ -e ${subhook_root}/config.cfg ]] ; then source "${subhook_root}/config.cfg" fi @@ -49,7 +50,18 @@ while read -r oldrev newrev refname; do oldrev=$(git show-branch | grep '\*' | grep -v "$newrev" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//') fi - for changedfile in $(git diff --name-only "$oldrev" "$newrev" --diff-filter=ACM); do + files_list='' + if [[ "x$oldrev" == 'x' ]]; then + if [[ $CHECK_INITIAL_COMMIT != "disabled" ]] ; then + files_list=$(git ls-tree --full-tree -r HEAD --name-only) + else + echo "Skipping file checks this is the initial commit..." + fi + else + files_list=$(git diff --name-only "$oldrev" "$newrev" --diff-filter=ACM) + fi + + for changedfile in $files_list; do tmpmodule="$tmptree/$changedfile" [[ -f "$tmpmodule" ]] || continue #check puppet manifest syntax