Skip to content

Commit

Permalink
kram - try new pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Oct 13, 2024
1 parent 839aa51 commit 3c3808f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/bin/bash

# derived from here
# https://github.com/andrewseidl/githook-clang-format/blob/master/clang-format.hook
# Uses the _clang-format file for rules
# Uses the _clang-format_ignore file to skip dirs
# Check if there are any staged changes
if ! git diff --cached --name-only | grep -q '\.cpp\|\.c\|\.h\|\.hpp'; then
exit 0
fi

format_file() {
file="${1}"
# Run clang-format on staged changes
git clang-format --style=file

if [ -f $file ]; then
clang-format -style=file -i ${file}
git add ${file}
fi
}

for file in `git diff-index --cached --name-only HEAD | grep -iE '\*.(cpp|h|m|mm)$' ` ; do
format_file "${file}"
done
# Check if clang-format made any changes
if ! git diff --cached --name-only | grep -q '\.cpp\|\.c\|\.h\|\.hpp'; then
echo "No changes made by clang-format."
exit 0
fi

# Add the formatted changes
echo "Code formatted with clang-format."
git add .

0 comments on commit 3c3808f

Please sign in to comment.