Everywhere: Update work in progress

This commit is contained in:
Riyyi
2022-09-16 20:22:08 +02:00
parent 6b0095dadf
commit edc0ef7203
19 changed files with 285 additions and 135 deletions
+8 -8
View File
@@ -9,9 +9,12 @@
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
cd "$scriptPath/.." || exit 1
green=$(tput setf 2)
red=$(tput setf 4)
nc=$(tput sgr0)
# Get all files staged for commit
files="$(git --no-pager diff --cached --name-only)"
green="$(tput setf 2)"
red="$(tput setf 4)"
nc="$(tput sgr0)"
failures=0
@@ -21,7 +24,7 @@ lint-shell-script.sh
for linter in $linters; do
echo "Running script/$linter"
if "script/$linter"; then
if "script/$linter" "$files"; then
echo "[${green}PASS${nc}]: script/$linter"
else
echo "[${red}FAIL${nc}]: script/$linter"
@@ -29,12 +32,9 @@ for linter in $linters; do
fi
done
# Get all files staged for commit
files="$(git diff --cached --name-only)"
echo "Running script/lint-clang-format.sh"
# shellcheck disable=SC2086
if script/lint-clang-format.sh && git diff --exit-code $files; then
if script/lint-clang-format.sh "$files" && git diff --exit-code $files; then
echo "[${green}PASS${nc}]: script/lint-clang-format.sh"
else
echo "[${red}FAIL${nc}]: script/lint-clang-format.sh"
+2 -1
View File
@@ -24,7 +24,8 @@ else
exit 1
fi
files=$(git ls-files -- '*.cpp' '*.h' ':!:inferno/vendor')
files="${1:-$(git --no-pager diff --cached --name-only)}"
files="$(echo "$files" | grep -E '\.(cpp|h)$')"
if [ -z "$files" ]; then
echo "No .cpp or .h files to check."
+2 -1
View File
@@ -15,7 +15,8 @@ if ! command -v shellcheck > /dev/null 2>&1; then
exit 1
fi
files=$(git ls-files -- '*.sh' ':!:inferno/vendor')
files="${1:-$(git --no-pager diff --cached --name-only)}"
files="$(echo "$files" | grep -E '\.sh$')"
if [ -z "$files" ]; then
echo "No .sh files to check."
+24 -13
View File
@@ -7,23 +7,24 @@
scriptName="$(basename "$0")"
help() {
b=$(tput bold)
u=$(tput smul)
nc=$(tput sgr0)
b="$(tput bold)"
u="$(tput smul)"
red="$(tput setf 4)"
n="$(tput sgr0)"
help() {
cat << EOF
${b}NAME${nc}
${b}NAME${n}
${scriptName} - manage pre-commit hooks
${b}SYNOPSIS${nc}
${b}${scriptName}${nc} ${u}COMMAND${nc}
${b}SYNOPSIS${n}
${b}${scriptName}${n} ${u}COMMAND${n}
${b}COMMANDS${nc}
${b}install${nc}
${b}COMMANDS${n}
${b}install${n}
Install all pre-commit hooks.
${b}remove${nc}
${b}remove${n}
Remove all pre-commit hooks.
EOF
}
@@ -31,8 +32,18 @@ EOF
# Exit if no option is provided
[ "$#" -eq 0 ] && help && exit 1
if [ ! -d ".git" ]; then
echo "${b}${red}Error:${n} please run this script from the project root." >&2
exit 1
fi
currentDir="$(pwd -P)"
# Get the path from the project root to the script
subDir="$(dirname -- "$0")"
# Get the full path to this script while handling spaces and symlinks correctly
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
scriptPath="$(cd -P -- "$subDir" && pwd -P)"
cd "$scriptPath/.." || exit 1
hooks="
@@ -42,7 +53,7 @@ lint-ci.sh
install() {
echo "Installing pre-commit hooks"
preCommit=".git/hooks/pre-commit"
preCommit="$currentDir/.git/hooks/pre-commit"
if ! test -f "$preCommit"; then
touch "$preCommit"
chmod +x "$preCommit"
@@ -51,7 +62,7 @@ install() {
for hook in $hooks; do
sed -Ei "/$hook/d" "$preCommit"
sed -Ei "\$ a script/$hook" "$preCommit"
sed -Ei "\$ a $subDir/$hook" "$preCommit"
done
}