Improve the git precommit hook to fix the includes
This commit is contained in:
parent
5ff52c277a
commit
2aacd0a0e5
|
@ -21,6 +21,21 @@ else
|
||||||
readonly n=
|
readonly n=
|
||||||
fi
|
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() {
|
function error_exit() {
|
||||||
for str in "$@"; do
|
for str in "$@"; do
|
||||||
echo -n "$b$str$n" >&2
|
echo -n "$b$str$n" >&2
|
||||||
|
@ -350,6 +365,9 @@ echo
|
||||||
|
|
||||||
readonly tty=${PRE_COMMIT_HOOK_TTY:-/dev/tty}
|
readonly tty=${PRE_COMMIT_HOOK_TTY:-/dev/tty}
|
||||||
|
|
||||||
|
|
||||||
|
fix_includes
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo -n "What would you like to do? [a/f/c/?] "
|
echo -n "What would you like to do? [a/f/c/?] "
|
||||||
read -r answer < "$tty"
|
read -r answer < "$tty"
|
||||||
|
|
Loading…
Reference in New Issue