Improve the git precommit hook to fix the includes

This commit is contained in:
Sameer Rahmani 2021-09-16 17:30:16 +01:00
parent 5ff52c277a
commit 2aacd0a0e5
1 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,21 @@ else
readonly n=
fi
function get_changed_files() {
local files=$(git diff --cached --name-status | awk '$1 != "D" { print $2 }')
if [[ "$files" ]]; then
echo $files
else
echo "LICENSE"
fi
}
function fix_includes() {
sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $(get_changed_files)
git add $(get_changed_files)
}
function error_exit() {
for str in "$@"; do
echo -n "$b$str$n" >&2
@ -350,6 +365,9 @@ echo
readonly tty=${PRE_COMMIT_HOOK_TTY:-/dev/tty}
fix_includes
while true; do
echo -n "What would you like to do? [a/f/c/?] "
read -r answer < "$tty"