serene/scripts/pre-hook

33 lines
624 B
Plaintext
Raw Normal View History

#! /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:56:12 +01:00
function fix_includes(){
2021-09-16 18:00:24 +01:00
local files=$(get_changed_files)
2021-09-16 18:00:24 +01:00
if [[ "$files" ]];
then
sed - i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $(files)
fi
}
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
}
fix_includes
clang_format_staged
git add $(get_changed_files)