2021-09-16 17:46:30 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-10-17 22:22:49 +01:00
|
|
|
set -e
|
|
|
|
|
2021-09-16 17:46:30 +01:00
|
|
|
function get_changed_files() {
|
2021-09-28 17:11:50 +01:00
|
|
|
local add_modified
|
|
|
|
local renamed
|
|
|
|
add_modified=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '($1 != "D" && $1 !~ /R.+/) { print $2 }')
|
|
|
|
renamed=$(git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 ~ /^R.+/ { print $3 }')
|
|
|
|
|
|
|
|
echo $add_modified | sed '/^[[:space:]]*$/d'
|
|
|
|
echo $renamed | sed '/^[[:space:]]*$/d'
|
2021-09-16 17:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-09-16 17:56:12 +01:00
|
|
|
function fix_includes(){
|
2021-09-16 18:00:24 +01:00
|
|
|
local files=$(get_changed_files)
|
2021-09-16 17:46:30 +01:00
|
|
|
|
2021-09-16 18:00:24 +01:00
|
|
|
if [[ "$files" ]];
|
|
|
|
then
|
2021-09-17 13:51:30 +01:00
|
|
|
echo "Fixing '#include' syntax...."
|
2021-09-17 13:49:55 +01:00
|
|
|
sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $files
|
2021-09-16 18:00:24 +01:00
|
|
|
fi
|
2021-09-16 17:46:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function clang_format_staged() {
|
2021-09-16 18:00:24 +01:00
|
|
|
local files=$(get_changed_files)
|
|
|
|
|
|
|
|
if [[ "$files" ]];
|
|
|
|
then
|
|
|
|
for file in $(get_changed_files)
|
|
|
|
do
|
2021-09-17 13:51:30 +01:00
|
|
|
echo "Reformatting $file..."
|
2021-09-16 18:00:24 +01:00
|
|
|
clang-format -i $file
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2021-09-16 17:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-09-16 18:02:00 +01:00
|
|
|
function git_add_changes() {
|
|
|
|
local files=$(get_changed_files)
|
|
|
|
|
|
|
|
if [[ "$files" ]];
|
|
|
|
then
|
2021-09-17 13:49:55 +01:00
|
|
|
git add $files
|
2021-09-16 18:02:00 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-16 17:46:30 +01:00
|
|
|
fix_includes
|
|
|
|
clang_format_staged
|
2021-09-16 18:02:00 +01:00
|
|
|
git_add_changes
|