Skip to content

Commit

Permalink
git-pre-commit-cppcheck: check only added or modified source files
Browse files Browse the repository at this point in the history
The regexp is written according to git-diff-index manual.
  • Loading branch information
Jérémy Lefaure authored and danmar committed May 7, 2016
1 parent 4e9afac commit 08d8b2d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/git-pre-commit-cppcheck
Expand Up @@ -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

0 comments on commit 08d8b2d

Please sign in to comment.