Skip to content

Commit 08d8b2d

Browse files
Jérémy Lefauredanmar
authored andcommitted
git-pre-commit-cppcheck: check only added or modified source files
The regexp is written according to git-diff-index manual.
1 parent 4e9afac commit 08d8b2d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tools/git-pre-commit-cppcheck

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ else
3636
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
3737
fi
3838

39-
# We should not pass non-C/C++ files to cppcheck. Filter filenames with pattern.
40-
pattern='\.(c|cpp|cc|cxx|h|hpp)$'
41-
changed_files=$(git diff-index --cached --name-only $against | grep -E $pattern)
39+
# We should pass only added or modified C/C++ source files to cppcheck.
40+
changed_files=$(git diff-index --cached $against | \
41+
grep -E '[MA] .*\.(c|cpp|cc|cxx)$' | cut -d' ' -f 2)
4242

4343
if [ -n "$changed_files" ]; then
44-
cppcheck --error-exitcode=1 $changed_files
45-
exit $?
44+
cppcheck --error-exitcode=1 $changed_files
45+
exit $?
4646
fi

0 commit comments

Comments
 (0)