Compare commits
2
Commits
1361ee04f9
...
b5e55f13d3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5e55f13d3 | ||
|
|
054980e0f2 |
+25
-10
@@ -7,11 +7,30 @@
|
|||||||
|
|
||||||
b="$(tput bold)"
|
b="$(tput bold)"
|
||||||
red="$(tput setf 4)"
|
red="$(tput setf 4)"
|
||||||
|
yellow="$(tput setf 6)"
|
||||||
|
blue="$(tput setf 1)"
|
||||||
|
green="$(tput setf 2)"
|
||||||
n="$(tput sgr0)"
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
if [ ! -d ".git" ]; then
|
if [ ! -d ".git" ]; then
|
||||||
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Temporary clear unstaged files from the repository to pass the diff checker
|
||||||
|
unstaged="$(git --no-pager diff --name-only)"
|
||||||
|
if [ -n "$unstaged" ]; then
|
||||||
|
patch=".git/patch-$(date +%s)"
|
||||||
|
echo "[${yellow}WARNING${n}]: Stashing unstaged files to $patch"
|
||||||
|
git --no-pager diff > "$patch"
|
||||||
|
git restore .
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
git apply "$patch"
|
||||||
|
rm -rf "${patch:?}"
|
||||||
|
echo "[${blue}INFO${n}]: Restored changes from $patch"
|
||||||
|
}
|
||||||
|
trap remove EXIT HUP INT TERM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the path from the project root to the script
|
# Get the path from the project root to the script
|
||||||
@@ -20,10 +39,6 @@ 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)"
|
||||||
|
|
||||||
green="$(tput setf 2)"
|
|
||||||
red="$(tput setf 4)"
|
|
||||||
nc="$(tput sgr0)"
|
|
||||||
|
|
||||||
failures=0
|
failures=0
|
||||||
|
|
||||||
linters="
|
linters="
|
||||||
@@ -33,9 +48,9 @@ lint-shell-script.sh
|
|||||||
for linter in $linters; do
|
for linter in $linters; do
|
||||||
echo "Running $subDir/$linter"
|
echo "Running $subDir/$linter"
|
||||||
if "$subDir/$linter" "$files"; then
|
if "$subDir/$linter" "$files"; then
|
||||||
echo "[${green}PASS${nc}]: $subDir/$linter"
|
echo "[${green}PASS${n}]: $subDir/$linter"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: $subDir/$linter"
|
echo "[${red}FAIL${n}]: $subDir/$linter"
|
||||||
failures=$(( failures + 1 ))
|
failures=$(( failures + 1 ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -43,9 +58,9 @@ done
|
|||||||
echo "Running $subDir/lint-clang-format.sh"
|
echo "Running $subDir/lint-clang-format.sh"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if "$subDir/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}]: $subDir/lint-clang-format.sh"
|
echo "[${green}PASS${n}]: $subDir/lint-clang-format.sh"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: $subDir/lint-clang-format.sh"
|
echo "[${red}FAIL${n}]: $subDir/lint-clang-format.sh"
|
||||||
failures=$(( failures + 1 ))
|
failures=$(( failures + 1 ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -5,13 +5,17 @@
|
|||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
b="$(tput bold)"
|
error() {
|
||||||
red="$(tput setf 4)"
|
b="$(tput bold)"
|
||||||
n="$(tput sgr0)"
|
red="$(tput setf 4)"
|
||||||
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
echo "${b}${red}Error:${n} $1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if [ ! -d ".git" ]; then
|
if [ ! -d ".git" ]; then
|
||||||
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
error "please run this script from the project root"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
formatter=false
|
formatter=false
|
||||||
@@ -20,13 +24,11 @@ if command -v clang-format-11 >/dev/null 2>&1; then
|
|||||||
elif command -v clang-format >/dev/null 2>&1; then
|
elif command -v clang-format >/dev/null 2>&1; then
|
||||||
formatter="clang-format"
|
formatter="clang-format"
|
||||||
if ! "$formatter" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 11) exit 1; }'; then
|
if ! "$formatter" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 11) exit 1; }'; then
|
||||||
echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 11 or later."
|
error "you are using '$("${formatter}" --version)', which appears to not be clang-format 11 or later."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "clang-format-11 is not available, but C++ files need linting!"
|
error "clang-format-11 is not available, but C++ files need linting!
|
||||||
echo "Either skip this script, or install clang-format-11."
|
Either skip this script, or install clang-format-11."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
||||||
|
|||||||
@@ -5,19 +5,22 @@
|
|||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
|
|
||||||
b="$(tput bold)"
|
error() {
|
||||||
red="$(tput setf 4)"
|
b="$(tput bold)"
|
||||||
n="$(tput sgr0)"
|
red="$(tput setf 4)"
|
||||||
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
echo "${b}${red}Error:${n} $1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if [ ! -d ".git" ]; then
|
if [ ! -d ".git" ]; then
|
||||||
echo "${b}${red}Error:${n} please run this script from the project root" >&2
|
error "please run this script from the project root"
|
||||||
exit 1
|
|
||||||
fi
|
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!"
|
error "shellcheck is not available, but shell-script files need linting!
|
||||||
echo "Either skip this script, or install shellcheck."
|
Either skip this script, or install shellcheck."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
||||||
|
|||||||
Reference in New Issue
Block a user