From 41459ae5cd4bc1821f371f34233b4a3b864c6b44 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 24 Jun 2018 17:22:14 +0200 Subject: [PATCH] Improve hooks --- Hooks/delegator.sh | 7 ++++--- Hooks/filename.sh | 15 +++++++++++++++ Hooks/logging.sh | 2 +- Hooks/syntax.sh | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Hooks/filename.sh diff --git a/Hooks/delegator.sh b/Hooks/delegator.sh index 66272da..644b458 100644 --- a/Hooks/delegator.sh +++ b/Hooks/delegator.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash -. logging.sh -. syntax.sh \ No newline at end of file +. Build/Hooks/logging.sh +. Build/Hooks/syntax.sh +. Build/Hooks/filename.sh \ No newline at end of file diff --git a/Hooks/filename.sh b/Hooks/filename.sh new file mode 100644 index 0000000..8d3ae5c --- /dev/null +++ b/Hooks/filename.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +allownonascii="false" + +git diff --cached --name-only | while read FILE; do + +if [ "$allownonascii" != "true" ] && + test $(git diff --cached --name-only --diff-filter=A -z $FILE | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + echo -e "\e[1;31m\tInvalid file name.\e[0m" >&2 + exit 1 +fi + +done || exit $? \ No newline at end of file diff --git a/Hooks/logging.sh b/Hooks/logging.sh index aeeef6c..43a700f 100644 --- a/Hooks/logging.sh +++ b/Hooks/logging.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash git diff --cached --name-only | while read FILE; do if [[ "$FILE" =~ ^.+(php)$ ]]; then diff --git a/Hooks/syntax.sh b/Hooks/syntax.sh index df3638f..3874940 100644 --- a/Hooks/syntax.sh +++ b/Hooks/syntax.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash git diff --cached --name-only | while read FILE; do