45 lines
826 B
Bash
Executable File
45 lines
826 B
Bash
Executable File
#! /bin/bash
|
|
|
|
function get_changed_files() {
|
|
git diff --cached --name-status |egrep '*\.(cpp|h|hpp|cpp.inc|h.inc)'|awk '$1 != "D" { print $2 }'
|
|
}
|
|
|
|
function fix_includes(){
|
|
local files=$(get_changed_files)
|
|
|
|
if [[ "$files" ]];
|
|
then
|
|
echo "Fixing '#include' syntax...."
|
|
sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $files
|
|
fi
|
|
}
|
|
|
|
function clang_format_staged() {
|
|
local files=$(get_changed_files)
|
|
|
|
if [[ "$files" ]];
|
|
then
|
|
for file in $(get_changed_files)
|
|
do
|
|
echo "Reformatting $file..."
|
|
clang-format -i $file
|
|
done
|
|
fi
|
|
|
|
}
|
|
|
|
function git_add_changes() {
|
|
local files=$(get_changed_files)
|
|
|
|
if [[ "$files" ]];
|
|
then
|
|
git add $files
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
fix_includes
|
|
clang_format_staged
|
|
git_add_changes
|