mirror of
https://github.com/TrustTunnel/TrustTunnel.git
synced 2026-04-26 20:36:02 +00:00
Pull request 94: Added auto-formatting and pre-commit hook
Squashed commit of the following: commit 0dc9600ff3bd8573d805e4de4d85290b1052a222 Author: Andrey Meshkov <am@adguard.com> Date: Sun Dec 21 20:53:02 2025 +0300 Rollback to the old changelog commit fb56f619d5f703d712dbfdb95ab093a211dc0c58 Author: Andrey Meshkov <am@adguard.com> Date: Sun Dec 21 20:36:24 2025 +0300 Improve the dev doc commit afd44a5e2bebd51b07dcb587cf39ada925a42db9 Author: Andrey Meshkov <am@adguard.com> Date: Sun Dec 21 20:32:49 2025 +0300 Added auto-formatting and pre-commit hook
This commit is contained in:
91
scripts/hooks/pre-commit
Executable file
91
scripts/hooks/pre-commit
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e -f -u
|
||||
|
||||
# This comment is used to simplify checking local copies of the script. Bump
|
||||
# this number every time a significant change is made to this script.
|
||||
#
|
||||
# AdGuard-Project-Version: 1
|
||||
|
||||
# Only show interactive prompts if there a terminal is attached to stdout.
|
||||
# While this technically doesn't guarantee that reading from /dev/tty works,
|
||||
# this should work reasonably well on all of our supported development systems
|
||||
# and in most terminal emulators.
|
||||
is_tty='0'
|
||||
if [ -t '1' ]; then
|
||||
is_tty='1'
|
||||
fi
|
||||
readonly is_tty
|
||||
|
||||
# prompt is a helper that prompts the user for interactive input if that can be
|
||||
# done. If there is no terminal attached, it sleeps for two seconds, giving the
|
||||
# programmer some time to react, and returns with a zero exit code.
|
||||
prompt() {
|
||||
if [ "$is_tty" -eq '0' ]; then
|
||||
sleep 2
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
while true; do
|
||||
printf 'commit anyway? y/[n]: '
|
||||
read -r ans </dev/tty
|
||||
|
||||
case "$ans" in
|
||||
'y' | 'Y')
|
||||
break
|
||||
;;
|
||||
'' | 'n' | 'N')
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Warn the programmer about unstaged changes and untracked files, but do not
|
||||
# fail the commit, because those changes might be temporary or for a different
|
||||
# branch.
|
||||
#
|
||||
# shellcheck disable=SC2016
|
||||
awk_prog='substr($2, 2, 1) != "." { print $9; } $1 == "?" { print $2; }'
|
||||
readonly awk_prog
|
||||
|
||||
unstaged="$(git status --porcelain=2 | awk "$awk_prog")"
|
||||
readonly unstaged
|
||||
|
||||
if [ "$unstaged" != '' ]; then
|
||||
printf 'WARNING: you have unstaged changes:\n\n%s\n\n' "$unstaged"
|
||||
prompt
|
||||
fi
|
||||
|
||||
# Warn the programmer about temporary todos and skel FIXMEs, but do not fail the
|
||||
# commit, because the commit could be in a temporary branch.
|
||||
temp_todos="$(
|
||||
git grep -e 'FIXME' -e 'TODO.*!!' -- \
|
||||
':!./scripts/hooks/pre-commit' \
|
||||
|| :
|
||||
)"
|
||||
readonly temp_todos
|
||||
|
||||
if [ "$temp_todos" != '' ]; then
|
||||
printf 'WARNING: you have temporary todos:\n\n%s\n\n' "$temp_todos"
|
||||
prompt
|
||||
fi
|
||||
|
||||
verbose="${VERBOSE:-0}"
|
||||
readonly verbose
|
||||
|
||||
if [ "$(git diff --cached --name-only -- '*.md' || :)" != '' ]; then
|
||||
make VERBOSE="$verbose" lint-md
|
||||
fi
|
||||
|
||||
if [ "$(git diff --cached --name-only -- '*.rs' 'Cargo.toml' 'Cargo.lock' || :)" != '' ]; then
|
||||
make VERBOSE="$verbose" lint-rust
|
||||
fi
|
||||
|
||||
if [ "$(git diff --cached --name-only -- '*.rs' '*.toml' '*.lock' 'Makefile' || :)" != '' ]; then
|
||||
make VERBOSE="$verbose" lint-rust test
|
||||
fi
|
||||
Reference in New Issue
Block a user