From 08d8b2da3877f87765bca69c9c27cd864ac507c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lefaure?= Date: Sun, 1 May 2016 14:52:03 +0200 Subject: [PATCH] git-pre-commit-cppcheck: check only added or modified source files The regexp is written according to git-diff-index manual. --- tools/git-pre-commit-cppcheck | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/git-pre-commit-cppcheck b/tools/git-pre-commit-cppcheck index f944f072f..4a542d207 100644 --- a/tools/git-pre-commit-cppcheck +++ b/tools/git-pre-commit-cppcheck @@ -36,11 +36,11 @@ else against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi -# We should not pass non-C/C++ files to cppcheck. Filter filenames with pattern. -pattern='\.(c|cpp|cc|cxx|h|hpp)$' -changed_files=$(git diff-index --cached --name-only $against | grep -E $pattern) +# We should pass only added or modified C/C++ source files to cppcheck. +changed_files=$(git diff-index --cached $against | \ + grep -E '[MA] .*\.(c|cpp|cc|cxx)$' | cut -d' ' -f 2) if [ -n "$changed_files" ]; then - cppcheck --error-exitcode=1 $changed_files - exit $? + cppcheck --error-exitcode=1 $changed_files + exit $? fi