git-pre-commit-cppcheck: check only added or modified source files
The regexp is written according to git-diff-index manual.
This commit is contained in:
parent
4e9afac92f
commit
08d8b2da38
|
@ -36,9 +36,9 @@ else
|
||||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We should not pass non-C/C++ files to cppcheck. Filter filenames with pattern.
|
# We should pass only added or modified C/C++ source files to cppcheck.
|
||||||
pattern='\.(c|cpp|cc|cxx|h|hpp)$'
|
changed_files=$(git diff-index --cached $against | \
|
||||||
changed_files=$(git diff-index --cached --name-only $against | grep -E $pattern)
|
grep -E '[MA] .*\.(c|cpp|cc|cxx)$' | cut -d' ' -f 2)
|
||||||
|
|
||||||
if [ -n "$changed_files" ]; then
|
if [ -n "$changed_files" ]; then
|
||||||
cppcheck --error-exitcode=1 $changed_files
|
cppcheck --error-exitcode=1 $changed_files
|
||||||
|
|
Loading…
Reference in New Issue