Meta: Allow pre-commit hooks to be run from parent project
This commit is contained in:
+19
-11
@@ -5,9 +5,17 @@
|
|||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
# Get the full path to this script while handling spaces and symlinks correctly
|
b="$(tput bold)"
|
||||||
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
red="$(tput setf 4)"
|
||||||
cd "$scriptPath/.." || exit 1
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the path from the project root to the script
|
||||||
|
subDir="$(dirname -- "$0")"
|
||||||
|
|
||||||
# Get all files staged for commit
|
# Get all files staged for commit
|
||||||
files="$(git --no-pager diff --cached --name-only)"
|
files="$(git --no-pager diff --cached --name-only)"
|
||||||
@@ -23,21 +31,21 @@ lint-shell-script.sh
|
|||||||
"
|
"
|
||||||
|
|
||||||
for linter in $linters; do
|
for linter in $linters; do
|
||||||
echo "Running script/$linter"
|
echo "Running $subDir/$linter"
|
||||||
if "script/$linter" "$files"; then
|
if "$subDir/$linter" "$files"; then
|
||||||
echo "[${green}PASS${nc}]: script/$linter"
|
echo "[${green}PASS${nc}]: $subDir/$linter"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: script/$linter"
|
echo "[${red}FAIL${nc}]: $subDir/$linter"
|
||||||
failures=$(( failures + 1 ))
|
failures=$(( failures + 1 ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Running script/lint-clang-format.sh"
|
echo "Running $subDir/lint-clang-format.sh"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if script/lint-clang-format.sh "$files" && git diff --exit-code $files; then
|
if "$subDir/lint-clang-format.sh" "$files" && git diff --exit-code $files; then
|
||||||
echo "[${green}PASS${nc}]: script/lint-clang-format.sh"
|
echo "[${green}PASS${nc}]: $subDir/lint-clang-format.sh"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: script/lint-clang-format.sh"
|
echo "[${red}FAIL${nc}]: $subDir/lint-clang-format.sh"
|
||||||
failures=$(( failures + 1 ))
|
failures=$(( failures + 1 ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,14 @@
|
|||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
# Get the full path to this script while handling spaces and symlinks correctly
|
b="$(tput bold)"
|
||||||
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
red="$(tput setf 4)"
|
||||||
cd "$scriptPath/.." || exit 1
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
formatter=false
|
formatter=false
|
||||||
if command -v clang-format-11 >/dev/null 2>&1; then
|
if command -v clang-format-11 >/dev/null 2>&1; then
|
||||||
@@ -28,7 +33,6 @@ files="${1:-$(git --no-pager diff --cached --name-only)}"
|
|||||||
files="$(echo "$files" | grep -E '\.(cpp|h)$')"
|
files="$(echo "$files" | grep -E '\.(cpp|h)$')"
|
||||||
|
|
||||||
if [ -z "$files" ]; then
|
if [ -z "$files" ]; then
|
||||||
echo "No .cpp or .h files to check."
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,14 @@
|
|||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
# Get the full path to this script while handling spaces and symlinks correctly
|
b="$(tput bold)"
|
||||||
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
red="$(tput setf 4)"
|
||||||
cd "$scriptPath/.." || exit 1
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if ! command -v shellcheck > /dev/null 2>&1; then
|
if ! command -v shellcheck > /dev/null 2>&1; then
|
||||||
echo "shellcheck is not available, but shell script files need linting!"
|
echo "shellcheck is not available, but shell script files need linting!"
|
||||||
@@ -19,7 +24,6 @@ files="${1:-$(git --no-pager diff --cached --name-only)}"
|
|||||||
files="$(echo "$files" | grep -E '\.sh$')"
|
files="$(echo "$files" | grep -E '\.sh$')"
|
||||||
|
|
||||||
if [ -z "$files" ]; then
|
if [ -z "$files" ]; then
|
||||||
echo "No .sh files to check."
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -37,15 +37,9 @@ if [ ! -d ".git" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
currentDir="$(pwd -P)"
|
|
||||||
|
|
||||||
# Get the path from the project root to the script
|
# Get the path from the project root to the script
|
||||||
subDir="$(dirname -- "$0")"
|
subDir="$(dirname -- "$0")"
|
||||||
|
|
||||||
# Get the full path to this script while handling spaces and symlinks correctly
|
|
||||||
scriptPath="$(cd -P -- "$subDir" && pwd -P)"
|
|
||||||
cd "$scriptPath/.." || exit 1
|
|
||||||
|
|
||||||
hooks="
|
hooks="
|
||||||
lint-ci.sh
|
lint-ci.sh
|
||||||
"
|
"
|
||||||
@@ -53,7 +47,7 @@ lint-ci.sh
|
|||||||
install() {
|
install() {
|
||||||
echo "Installing pre-commit hooks"
|
echo "Installing pre-commit hooks"
|
||||||
|
|
||||||
preCommit="$currentDir/.git/hooks/pre-commit"
|
preCommit=".git/hooks/pre-commit"
|
||||||
if ! test -f "$preCommit"; then
|
if ! test -f "$preCommit"; then
|
||||||
touch "$preCommit"
|
touch "$preCommit"
|
||||||
chmod +x "$preCommit"
|
chmod +x "$preCommit"
|
||||||
|
|||||||
Reference in New Issue
Block a user