Create a new and simpler pre-commit hook
This commit is contained in:
parent
2aacd0a0e5
commit
fe63407aed
9
builder
9
builder
|
@ -29,6 +29,7 @@ export LSAN_OPTIONS
|
|||
# root of the source tree
|
||||
ROOT_DIR=$(pwd)
|
||||
BUILD_DIR=$ROOT_DIR/build
|
||||
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
|
||||
|
||||
scanbuild=scan-build
|
||||
|
||||
|
@ -118,12 +119,8 @@ function tests() {
|
|||
|
||||
case "$command" in
|
||||
"setup")
|
||||
pushd ./scripts || return
|
||||
./git-pre-commit-format install
|
||||
popd || return
|
||||
echo "=== Manual action required ==="
|
||||
echo "Set this environment variable. (clang-format-diff.py is located inside llvm's source directory)."
|
||||
echo 'export CLANG_FORMAT_DIFF="python3 /path/to/llvm/saurce/llvm-project/clang/tools/clang-format/clang-format-diff.py"'
|
||||
rm -rv $ME/.git/hooks/pre-commit
|
||||
ln -s $ME/scripts/pre-hook $ME/.git/hooks/pre-commit
|
||||
;;
|
||||
"build")
|
||||
clean
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#! /bin/bash
|
||||
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
function clang_format_staged() {
|
||||
for file in $(get_changed_files)
|
||||
do
|
||||
clang-format -i $file
|
||||
done
|
||||
}
|
||||
|
||||
fix_includes
|
||||
clang_format_staged
|
||||
git add $(get_changed_files)
|
Loading…
Reference in New Issue