2021-09-16 17:46:30 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
function get_changed_files() {
|
2021-09-16 18:00:24 +01:00
|
|
|
git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 != "D" { print $2 }'
|
|
|
|
|
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
|
|
|
|
sed - i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $(files)
|
|
|
|
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
|
|
|
|
clang-format -i $file
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2021-09-16 17:46:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fix_includes
|
|
|
|
clang_format_staged
|
|
|
|
git add $(get_changed_files)
|